From cdc6245c35d655b7f33a5e28e5fff8b900408df7 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Sun, 3 Apr 2022 17:22:58 -0400 Subject: [PATCH] [5] more small fixes --- VERSION | 2 +- modules/meta.py | 61 +++++++++++++++++++++++++++--------------------- modules/trakt.py | 12 +++++----- modules/util.py | 2 +- 4 files changed, 42 insertions(+), 35 deletions(-) diff --git a/VERSION b/VERSION index f880c52c..d923b25c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.16.3-develop4 +1.16.3-develop5 diff --git a/modules/meta.py b/modules/meta.py index 551c7cb8..565eb48c 100644 --- a/modules/meta.py +++ b/modules/meta.py @@ -59,6 +59,7 @@ def get_dict(attribute, attr_data, check_list=None): class DataFile: def __init__(self, config, file_type, path): self.config = config + self.library = None self.type = file_type self.path = path self.data_type = "" @@ -102,6 +103,7 @@ class DataFile: raise Failed(f"{self.data_type} Error: template attribute is blank") else: logger.debug(f"Value: {template_call}") + new_attributes = {} for variables in util.get_list(template_call, split=False): if not isinstance(variables, dict): raise Failed(f"{self.data_type} Error: template attribute is not a dictionary") @@ -127,6 +129,7 @@ class DataFile: variables["collection_name"] = str(name) if self.data_type == "Playlist" and "playlist_name" not in variables: variables["playlist_name"] = str(name) + variables["library_type"] = self.library.type.lower() template_name = variables["name"] template = self.templates[template_name] @@ -215,17 +218,19 @@ class DataFile: final_data = scan_text(final_data, dm, dd) return final_data - new_attributes = {} for method_name, attr_data in template.items(): if method_name not in data and method_name not in ["default", "optional", "move_collection_prefix", "move_prefix"]: if attr_data is None: logger.error(f"Template Error: template attribute {method_name} is blank") continue - try: - new_attributes[method_name] = check_data(method_name, attr_data) - except Failed: - continue - return new_attributes + if method_name in new_attributes: + logger.warning(f"Template Warning: template attribute: {method_name} from {variables['name']} skipped") + else: + try: + new_attributes[method_name] = check_data(method_name, attr_data) + except Failed: + continue + return new_attributes class MetadataFile(DataFile): @@ -270,8 +275,6 @@ class MetadataFile(DataFile): auto_type = dynamic[methods["type"]].lower() og_exclude = util.parse("Config", "exclude", dynamic, parent=map_name, methods=methods, datatype="strlist") if "exclude" in methods else [] include = util.parse("Config", "include", dynamic, parent=map_name, methods=methods, datatype="strlist") if "include" in methods else [] - if og_exclude and include: - raise Failed(f"Config Error: {map_name} cannot have both include and exclude attributes") addons = util.parse("Config", "addons", dynamic, parent=map_name, methods=methods, datatype="dictliststr") if "addons" in methods else {} exclude = [str(e) for e in og_exclude] for k, v in addons.items(): @@ -312,7 +315,7 @@ class MetadataFile(DataFile): tags = library.get_tags(f"episode.{search_tag}") else: tags = library.get_tags(search_tag) - if auto_type in ["decade", "subtitle_language", "audio_language"]: + if auto_type in ["resolution", "decade", "subtitle_language", "audio_language"]: all_keys = [str(i.key) for i in tags] auto_list = {str(i.key): i.title for i in tags if str(i.title) not in exclude and str(i.key) not in exclude} else: @@ -358,9 +361,9 @@ class MetadataFile(DataFile): tmdb_item = config.TMDb.get_item(item, tmdb_id, tvdb_id, imdb_id, is_movie=library.type == "Movie") if tmdb_item and tmdb_item.countries: for country in tmdb_item.countries: - all_keys.append(country.iso_3166_1) - if country.iso_3166_1 not in exclude and country.name not in exclude: - auto_list[country.iso_3166_1] = country.name + all_keys.append(country.iso_3166_1.lower()) + if country.iso_3166_1.lower() not in exclude and country.name not in exclude: + auto_list[country.iso_3166_1.lower()] = country.name logger.exorcise() default_title_format = "<> <>s" elif auto_type in ["actor", "director", "writer", "producer"]: @@ -493,6 +496,7 @@ class MetadataFile(DataFile): for key, value in auto_list.items(): logger.debug(f" - {key}{'' if key == value else f' ({value})'}") + used_keys = [] for key, value in auto_list.items(): if include and key not in include: if key not in exclude: @@ -511,15 +515,16 @@ class MetadataFile(DataFile): key_value = [key] if key in all_keys else [] if key in addons: key_value.extend([a for a in addons[key] if a in all_keys and a != key]) - template_call = { - "name": template_names, - "value": key_value, - auto_type: key_value, - "key_name": key_name, "key": key - } + used_keys.extend(key_value) + og_call = {"value": key_value, auto_type: key_value, "key_name": key_name, "key": key} for k, v in template_variables.items(): if key in v: - template_call[k] = v[key] + og_call[k] = v[key] + template_call = [] + for template_name in template_names: + new_call = og_call.copy() + new_call["name"] = template_name + template_call.append(new_call) if key in title_override: collection_title = title_override[key] else: @@ -534,17 +539,19 @@ class MetadataFile(DataFile): sync.pop(collection_title) self.collections[collection_title] = col if other_name: - template_call = { - "name": other_templates, - "value": other_keys, - "included_keys": include, - auto_type: other_keys, - "key_name": other_name, "key": "other" + og_other = { + "value": other_keys, "included_keys": include, "used_keys": used_keys, + auto_type: other_keys, "key_name": other_name, "key": "other" } for k, v in template_variables.items(): if "other" in v: - template_call[k] = v["other"] - col = {"template": template_call, "label": str(map_name)} + og_other[k] = v["other"] + other_call = [] + for other_template in other_templates: + new_call = og_other.copy() + new_call["name"] = other_template + other_call.append(new_call) + col = {"template": other_call, "label": str(map_name)} if test: col["test"] = True if other_name in sync: diff --git a/modules/trakt.py b/modules/trakt.py index 604a63fc..c985b59d 100644 --- a/modules/trakt.py +++ b/modules/trakt.py @@ -360,17 +360,17 @@ class Trakt: if "ratings" in dict_methods: final_dict["ratings"] = util.parse(err_type, "ratings", trakt_dict, methods=dict_methods, parent=method_name, datatype="int", minimum=0, maximum=100, range_split="-") if "genres" in dict_methods: - final_dict["genres"] = util.parse(err_type, "genres", trakt_dict, methods=dict_methods, parent=method_name, datatype="list", options=self.movie_genres if is_movie else self.show_genres) + final_dict["genres"] = util.parse(err_type, "genres", trakt_dict, methods=dict_methods, parent=method_name, datatype="commalist", options=self.movie_genres if is_movie else self.show_genres) if "languages" in dict_methods: - final_dict["languages"] = util.parse(err_type, "languages", trakt_dict, methods=dict_methods, parent=method_name, datatype="list", options=self.movie_languages if is_movie else self.show_languages) + final_dict["languages"] = util.parse(err_type, "languages", trakt_dict, methods=dict_methods, parent=method_name, datatype="commalist", options=self.movie_languages if is_movie else self.show_languages) if "countries" in dict_methods: - final_dict["countries"] = util.parse(err_type, "countries", trakt_dict, methods=dict_methods, parent=method_name, datatype="list", options=self.movie_countries if is_movie else self.show_countries) + final_dict["countries"] = util.parse(err_type, "countries", trakt_dict, methods=dict_methods, parent=method_name, datatype="commalist", options=self.movie_countries if is_movie else self.show_countries) if "certifications" in dict_methods: - final_dict["certifications"] = util.parse(err_type, "certifications", trakt_dict, methods=dict_methods, parent=method_name, datatype="list", options=self.movie_certifications if is_movie else self.show_certifications) + final_dict["certifications"] = util.parse(err_type, "certifications", trakt_dict, methods=dict_methods, parent=method_name, datatype="commalist", options=self.movie_certifications if is_movie else self.show_certifications) if "networks" in dict_methods and not is_movie: - final_dict["networks"] = util.parse(err_type, "networks", trakt_dict, methods=dict_methods, parent=method_name, datatype="list") + final_dict["networks"] = util.parse(err_type, "networks", trakt_dict, methods=dict_methods, parent=method_name, datatype="commalist") if "status" in dict_methods and not is_movie: - final_dict["status"] = util.parse(err_type, "status", trakt_dict, methods=dict_methods, parent=method_name, datatype="list", options=status) + final_dict["status"] = util.parse(err_type, "status", trakt_dict, methods=dict_methods, parent=method_name, datatype="commalist", options=status) valid_dicts.append(final_dict) else: userlist = util.parse(err_type, "userlist", trakt_dict, methods=dict_methods, parent=method_name, options=["recommended", "watched", "collected", "watchlist"]) diff --git a/modules/util.py b/modules/util.py index 9a733b64..fecea18c 100644 --- a/modules/util.py +++ b/modules/util.py @@ -446,7 +446,7 @@ def parse(error, attribute, data, datatype=None, methods=None, parent=None, defa if options is None or (options and (v in options or (datatype == "strlist" and str(v) in options))): final_list.append(str(v) if datatype == "strlist" else v) elif options: - raise Failed(f"{error} Error: {v} is invalid options are: {options}") + raise Failed(f"{error} Error: {v} is invalid; Options include: {options}") return final_list elif datatype == "intlist": if value: