|
|
@ -684,59 +684,6 @@ class MetadataFile(DataFile):
|
|
|
|
for mapping_name, meta in self.metadata.items():
|
|
|
|
for mapping_name, meta in self.metadata.items():
|
|
|
|
methods = {mm.lower(): mm for mm in meta}
|
|
|
|
methods = {mm.lower(): mm for mm in meta}
|
|
|
|
|
|
|
|
|
|
|
|
updated = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_edit(name, current_item, group=None, alias=None, key=None, value=None, var_type="str"):
|
|
|
|
|
|
|
|
nonlocal updated
|
|
|
|
|
|
|
|
if value or name in alias:
|
|
|
|
|
|
|
|
if value or group[alias[name]]:
|
|
|
|
|
|
|
|
if key is None: key = name
|
|
|
|
|
|
|
|
if value is None: value = group[alias[name]]
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
current = str(getattr(current_item, key, ""))
|
|
|
|
|
|
|
|
final_value = None
|
|
|
|
|
|
|
|
if var_type == "date":
|
|
|
|
|
|
|
|
final_value = util.validate_date(value, name, return_as="%Y-%m-%d")
|
|
|
|
|
|
|
|
current = current[:-9]
|
|
|
|
|
|
|
|
elif var_type == "float":
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
value = float(str(value))
|
|
|
|
|
|
|
|
if 0 <= value <= 10:
|
|
|
|
|
|
|
|
final_value = value
|
|
|
|
|
|
|
|
except ValueError:
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
if final_value is None:
|
|
|
|
|
|
|
|
raise Failed(f"Metadata Error: {name} attribute must be a number between 0 and 10")
|
|
|
|
|
|
|
|
elif var_type == "int":
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
final_value = int(str(value))
|
|
|
|
|
|
|
|
except ValueError:
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
if final_value is None:
|
|
|
|
|
|
|
|
raise Failed(f"Metadata Error: {name} attribute must be an integer")
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
final_value = value
|
|
|
|
|
|
|
|
if current != str(final_value):
|
|
|
|
|
|
|
|
if key == "title":
|
|
|
|
|
|
|
|
current_item.editTitle(final_value)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
current_item.editField(key, final_value)
|
|
|
|
|
|
|
|
logger.info(f"Detail: {name} updated to {final_value}")
|
|
|
|
|
|
|
|
updated = True
|
|
|
|
|
|
|
|
except Failed as ee:
|
|
|
|
|
|
|
|
logger.error(ee)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
logger.error(f"Metadata Error: {name} attribute is blank")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def finish_edit(current_item, description):
|
|
|
|
|
|
|
|
nonlocal updated
|
|
|
|
|
|
|
|
if updated:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
current_item.saveEdits()
|
|
|
|
|
|
|
|
logger.info(f"{description} Details Update Successful")
|
|
|
|
|
|
|
|
except BadRequest:
|
|
|
|
|
|
|
|
logger.error(f"{description} Details Update Failed")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger.info("")
|
|
|
|
logger.info("")
|
|
|
|
if (isinstance(mapping_name, int) or mapping_name.startswith("tt")) and not self.library.is_music:
|
|
|
|
if (isinstance(mapping_name, int) or mapping_name.startswith("tt")) and not self.library.is_music:
|
|
|
|
if isinstance(mapping_name, int):
|
|
|
|
if isinstance(mapping_name, int):
|
|
|
@ -745,16 +692,20 @@ class MetadataFile(DataFile):
|
|
|
|
id_type = "IMDb"
|
|
|
|
id_type = "IMDb"
|
|
|
|
logger.separator(f"{id_type} ID: {mapping_name} Metadata", space=False, border=False)
|
|
|
|
logger.separator(f"{id_type} ID: {mapping_name} Metadata", space=False, border=False)
|
|
|
|
logger.info("")
|
|
|
|
logger.info("")
|
|
|
|
|
|
|
|
item = []
|
|
|
|
if self.library.is_movie and mapping_name in self.library.movie_map:
|
|
|
|
if self.library.is_movie and mapping_name in self.library.movie_map:
|
|
|
|
item = self.library.fetchItem(self.library.movie_map[mapping_name][0])
|
|
|
|
for item_id in self.library.movie_map[mapping_name]:
|
|
|
|
|
|
|
|
item.append(self.library.fetchItem(item_id))
|
|
|
|
elif self.library.is_show and mapping_name in self.library.show_map:
|
|
|
|
elif self.library.is_show and mapping_name in self.library.show_map:
|
|
|
|
item = self.library.fetchItem(self.library.show_map[mapping_name][0])
|
|
|
|
for item_id in self.library.show_map[mapping_name]:
|
|
|
|
|
|
|
|
item.append(self.library.fetchItem(item_id))
|
|
|
|
elif mapping_name in self.library.imdb_map:
|
|
|
|
elif mapping_name in self.library.imdb_map:
|
|
|
|
item = self.library.fetchItem(self.library.imdb_map[mapping_name][0])
|
|
|
|
for item_id in self.library.imdb_map[mapping_name]:
|
|
|
|
|
|
|
|
item.append(self.library.fetchItem(item_id))
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
logger.error(f"Metadata Error: {id_type} ID not mapped")
|
|
|
|
logger.error(f"Metadata Error: {id_type} ID not mapped")
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
title = item.title
|
|
|
|
title = None
|
|
|
|
if "title" in methods:
|
|
|
|
if "title" in methods:
|
|
|
|
if meta[methods["title"]] is None:
|
|
|
|
if meta[methods["title"]] is None:
|
|
|
|
logger.error("Metadata Error: title attribute is blank")
|
|
|
|
logger.error("Metadata Error: title attribute is blank")
|
|
|
@ -795,11 +746,67 @@ class MetadataFile(DataFile):
|
|
|
|
item = self.library.search_item(alt_title)
|
|
|
|
item = self.library.search_item(alt_title)
|
|
|
|
|
|
|
|
|
|
|
|
if item is None:
|
|
|
|
if item is None:
|
|
|
|
logger.error(f"Plex Error: Item {mapping_name} not found")
|
|
|
|
logger.error(f"Skipping {mapping_name}: Item {mapping_name} not found")
|
|
|
|
logger.error(f"Skipping {mapping_name}")
|
|
|
|
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
|
|
|
|
if not isinstance(item, list):
|
|
|
|
|
|
|
|
item = [item]
|
|
|
|
|
|
|
|
for i in item:
|
|
|
|
|
|
|
|
self.update_metadata_item(i, title, mapping_name, meta, methods)
|
|
|
|
|
|
|
|
|
|
|
|
logger.separator(f"{title} Metadata", space=False, border=False)
|
|
|
|
def update_metadata_item(self, item, title, mapping_name, meta, methods):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updated = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_edit(name, current_item, group=None, alias=None, key=None, value=None, var_type="str"):
|
|
|
|
|
|
|
|
nonlocal updated
|
|
|
|
|
|
|
|
if value or name in alias:
|
|
|
|
|
|
|
|
if value or group[alias[name]]:
|
|
|
|
|
|
|
|
if key is None: key = name
|
|
|
|
|
|
|
|
if value is None: value = group[alias[name]]
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
current = str(getattr(current_item, key, ""))
|
|
|
|
|
|
|
|
final_value = None
|
|
|
|
|
|
|
|
if var_type == "date":
|
|
|
|
|
|
|
|
final_value = util.validate_date(value, name, return_as="%Y-%m-%d")
|
|
|
|
|
|
|
|
current = current[:-9]
|
|
|
|
|
|
|
|
elif var_type == "float":
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
value = float(str(value))
|
|
|
|
|
|
|
|
if 0 <= value <= 10:
|
|
|
|
|
|
|
|
final_value = value
|
|
|
|
|
|
|
|
except ValueError:
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
if final_value is None:
|
|
|
|
|
|
|
|
raise Failed(f"Metadata Error: {name} attribute must be a number between 0 and 10")
|
|
|
|
|
|
|
|
elif var_type == "int":
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
final_value = int(str(value))
|
|
|
|
|
|
|
|
except ValueError:
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
if final_value is None:
|
|
|
|
|
|
|
|
raise Failed(f"Metadata Error: {name} attribute must be an integer")
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
final_value = value
|
|
|
|
|
|
|
|
if current != str(final_value):
|
|
|
|
|
|
|
|
if key == "title":
|
|
|
|
|
|
|
|
current_item.editTitle(final_value)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
current_item.editField(key, final_value)
|
|
|
|
|
|
|
|
logger.info(f"Detail: {name} updated to {final_value}")
|
|
|
|
|
|
|
|
updated = True
|
|
|
|
|
|
|
|
except Failed as ee:
|
|
|
|
|
|
|
|
logger.error(ee)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
logger.error(f"Metadata Error: {name} attribute is blank")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def finish_edit(current_item, description):
|
|
|
|
|
|
|
|
nonlocal updated
|
|
|
|
|
|
|
|
if updated:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
current_item.saveEdits()
|
|
|
|
|
|
|
|
logger.info(f"{description} Details Update Successful")
|
|
|
|
|
|
|
|
except BadRequest:
|
|
|
|
|
|
|
|
logger.error(f"{description} Details Update Failed")
|
|
|
|
|
|
|
|
|
|
|
|
tmdb_item = None
|
|
|
|
tmdb_item = None
|
|
|
|
tmdb_is_movie = None
|
|
|
|
tmdb_is_movie = None
|
|
|
@ -843,6 +850,7 @@ class MetadataFile(DataFile):
|
|
|
|
genres = tmdb_item.genres
|
|
|
|
genres = tmdb_item.genres
|
|
|
|
|
|
|
|
|
|
|
|
item.batchEdits()
|
|
|
|
item.batchEdits()
|
|
|
|
|
|
|
|
if title:
|
|
|
|
add_edit("title", item, meta, methods, value=title)
|
|
|
|
add_edit("title", item, meta, methods, value=title)
|
|
|
|
add_edit("sort_title", item, meta, methods, key="titleSort")
|
|
|
|
add_edit("sort_title", item, meta, methods, key="titleSort")
|
|
|
|
add_edit("user_rating", item, meta, methods, key="userRating", var_type="float")
|
|
|
|
add_edit("user_rating", item, meta, methods, key="userRating", var_type="float")
|
|
|
@ -1144,6 +1152,7 @@ class PlaylistFile(DataFile):
|
|
|
|
raise Failed("YAML Error: playlists attribute is required")
|
|
|
|
raise Failed("YAML Error: playlists attribute is required")
|
|
|
|
logger.info(f"Playlist File Loaded Successfully")
|
|
|
|
logger.info(f"Playlist File Loaded Successfully")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class OverlayFile(DataFile):
|
|
|
|
class OverlayFile(DataFile):
|
|
|
|
def __init__(self, config, library, file_type, path, temp_vars, asset_directory):
|
|
|
|
def __init__(self, config, library, file_type, path, temp_vars, asset_directory):
|
|
|
|
super().__init__(config, file_type, path, temp_vars, asset_directory)
|
|
|
|
super().__init__(config, file_type, path, temp_vars, asset_directory)
|
|
|
|