[87] update metadata editions

pull/1324/head
meisnate12 2 years ago
parent c2d6aab2ca
commit da018ec90f

@ -1 +1 @@
1.18.3-develop86 1.18.3-develop87

@ -1103,39 +1103,10 @@ class MetadataFile(DataFile):
methods = {mm.lower(): mm for mm in meta} methods = {mm.lower(): mm for mm in meta}
logger.info("") logger.info("")
logger.separator(f"{mapping_name} Metadata", space=False, border=False) logger.separator(f"{mapping_name} Metadata")
logger.info("")
item = None
if (isinstance(mapping_name, int) or mapping_name.startswith("tt")) and not self.library.is_music:
if isinstance(mapping_name, int):
id_type = "TMDb" if self.library.is_movie else "TVDb"
else:
id_type = "IMDb"
logger.separator(f"{id_type} ID: {mapping_name} Metadata", space=False, border=False)
logger.info("")
item = []
if self.library.is_movie and mapping_name in self.library.movie_map:
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:
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:
for item_id in self.library.imdb_map[mapping_name]:
item.append(self.library.fetchItem(item_id))
else:
logger.error(f"Metadata Error: {id_type} ID not mapped")
continue
title = None
else:
logger.separator(f"{mapping_name} Metadata", space=False, border=False)
logger.info("")
title = mapping_name
if "template" in methods: if "template" in methods:
logger.debug("")
logger.separator(f"Building Definition From Templates", space=False, border=False) logger.separator(f"Building Definition From Templates", space=False, border=False)
logger.debug("") logger.debug("")
named_templates = [] named_templates = []
@ -1148,7 +1119,6 @@ class MetadataFile(DataFile):
raise Failed(f"Metadata Error: template sub-attribute name cannot be blank") raise Failed(f"Metadata Error: template sub-attribute name cannot be blank")
named_templates.append(original_variables["name"]) named_templates.append(original_variables["name"])
logger.debug(f"Templates Called: {', '.join(named_templates)}") logger.debug(f"Templates Called: {', '.join(named_templates)}")
logger.debug("")
new_variables = {} new_variables = {}
if "variables" in methods: if "variables" in methods:
logger.debug("") logger.debug("")
@ -1191,6 +1161,7 @@ class MetadataFile(DataFile):
if not mapping_id and (isinstance(mapping_name, int) or mapping_name.startswith("tt")) and not self.library.is_music: if not mapping_id and (isinstance(mapping_name, int) or mapping_name.startswith("tt")) and not self.library.is_music:
mapping_id = mapping_name mapping_id = mapping_name
item = []
if not mapping_id: if not mapping_id:
title = mapping_name title = mapping_name
else: else:
@ -1198,8 +1169,8 @@ class MetadataFile(DataFile):
id_type = "IMDb" id_type = "IMDb"
else: else:
id_type = "TMDb" if self.library.is_movie else "TVDb" id_type = "TMDb" if self.library.is_movie else "TVDb"
logger.info("")
logger.info(f"{id_type} ID Mapping: {mapping_id}") logger.info(f"{id_type} ID Mapping: {mapping_id}")
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:
for item_id in self.library.movie_map[mapping_name]: for item_id in self.library.movie_map[mapping_name]:
item.append(self.library.fetchItem(item_id)) item.append(self.library.fetchItem(item_id))
@ -1220,19 +1191,16 @@ class MetadataFile(DataFile):
else: else:
title = meta[methods["title"]] title = meta[methods["title"]]
edition_titles = []
blank_edition = False blank_edition = False
if "edition_filter" in methods and self.library.is_movie: edition_titles = []
if not meta[methods["edition_filter"]]: edition_contains = []
blank_edition = True if self.library.is_movie:
else: if "blank_edition" in methods:
edition_titles = util.get_list(meta[methods["edition_filter"]]) blank_edition = util.parse("Metadata", "blank_edition", meta, datatype="bool", methods=methods, default=False)
if "edition_filter" in methods:
edition_contains = None edition_titles = util.parse("Metadata", "edition_filter", meta, datatype="strlist", methods=methods)
if "edition_contains" in methods and self.library.is_movie: if "edition_contains" in methods:
edition_contains = util.get_list(meta[methods["edition_contains"]]) edition_contains = util.parse("Metadata", "edition_contains", meta, datatype="strlist", methods=methods)
if not edition_contains:
edition_contains = []
if not item: if not item:
year = None year = None
@ -1247,22 +1215,16 @@ class MetadataFile(DataFile):
pass pass
if year is None: if year is None:
raise Failed(f"Metadata Error: year attribute must be an integer between 1800 and {next_year}") raise Failed(f"Metadata Error: year attribute must be an integer between 1800 and {next_year}")
if blank_edition and not edition_contains: item = self.library.search_item(title, year=year)
edition_title = ""
elif len(edition_titles) == 1 and not edition_contains:
edition_title = edition_titles[0]
else:
edition_title = None
item = self.library.search_item(title, year=year, edition=edition_title)
if not item and "alt_title" in methods: if not item and "alt_title" in methods:
if meta[methods["alt_title"]] is None: if meta[methods["alt_title"]] is None:
logger.error("Metadata Error: alt_title attribute is blank") logger.error("Metadata Error: alt_title attribute is blank")
else: else:
alt_title = meta[methods["alt_title"]] alt_title = meta[methods["alt_title"]]
item = self.library.search_item(alt_title, year=year, edition=edition_title) item = self.library.search_item(alt_title, year=year)
if not item: if not item:
item = self.library.search_item(alt_title, edition=edition_title) item = self.library.search_item(alt_title)
if not item: if not item:
logger.error(f"Skipping {mapping_name}: Item {title} not found") logger.error(f"Skipping {mapping_name}: Item {title} not found")
@ -1271,15 +1233,36 @@ class MetadataFile(DataFile):
item = [item] item = [item]
if blank_edition or edition_titles or edition_contains: if blank_edition or edition_titles or edition_contains:
new_item = [] new_item = []
logger.trace("")
logger.trace("Edition Filtering: ")
for i in item: for i in item:
if (blank_edition and not i.editionTitle) \ check = i.editionTitle if i.editionTitle else ""
or (edition_titles and i.editionTitle in edition_titles) \ if blank_edition and not check:
or (edition_contains and any([r in i.editionTitle for r in edition_contains])): logger.trace(f" Found {i.title} with no Edition")
new_item.append(i) new_item.append(i)
elif edition_titles and check in edition_titles:
logger.trace(f" Found {i.title} with Edition: {check}")
new_item.append(i)
else:
found = False
if edition_contains:
for ec in edition_contains:
if ec in check:
found = True
logger.trace(f" Found {i.title} with Edition: {check} containing {ec}")
new_item.append(i)
break
if not found:
if check:
logger.trace(f" {i.title} with Edition: {check} ignored")
else:
logger.trace(f" {i.title} with no Edition ignored")
item = new_item
for i in item: for i in item:
try: try:
logger.info("")
logger.separator(f"Updating {i.title}", space=False, border=False) logger.separator(f"Updating {i.title}", space=False, border=False)
logger.info("")
self.update_metadata_item(i, title, mapping_name, meta, methods) self.update_metadata_item(i, title, mapping_name, meta, methods)
except Failed as e: except Failed as e:
logger.error(e) logger.error(e)

@ -804,9 +804,9 @@ def parse(error, attribute, data, datatype=None, methods=None, parent=None, defa
return value return value
elif isinstance(value, (int, float)): elif isinstance(value, (int, float)):
return value > 0 return value > 0
elif str(value).lower() in ["t", "true"]: elif str(value).lower() in ["t", "true", "y", "yes"]:
return True return True
elif str(value).lower() in ["f", "false"]: elif str(value).lower() in ["f", "false", "n", "no"]:
return False return False
else: else:
message = f"{display} must be either true or false" message = f"{display} must be either true or false"

Loading…
Cancel
Save