[5] more small fixes

pull/847/head
meisnate12 3 years ago
parent 01354b8345
commit cdc6245c35

@ -1 +1 @@
1.16.3-develop4 1.16.3-develop5

@ -59,6 +59,7 @@ def get_dict(attribute, attr_data, check_list=None):
class DataFile: class DataFile:
def __init__(self, config, file_type, path): def __init__(self, config, file_type, path):
self.config = config self.config = config
self.library = None
self.type = file_type self.type = file_type
self.path = path self.path = path
self.data_type = "" self.data_type = ""
@ -102,6 +103,7 @@ class DataFile:
raise Failed(f"{self.data_type} Error: template attribute is blank") raise Failed(f"{self.data_type} Error: template attribute is blank")
else: else:
logger.debug(f"Value: {template_call}") logger.debug(f"Value: {template_call}")
new_attributes = {}
for variables in util.get_list(template_call, split=False): for variables in util.get_list(template_call, split=False):
if not isinstance(variables, dict): if not isinstance(variables, dict):
raise Failed(f"{self.data_type} Error: template attribute is not a dictionary") raise Failed(f"{self.data_type} Error: template attribute is not a dictionary")
@ -127,6 +129,7 @@ class DataFile:
variables["collection_name"] = str(name) variables["collection_name"] = str(name)
if self.data_type == "Playlist" and "playlist_name" not in variables: if self.data_type == "Playlist" and "playlist_name" not in variables:
variables["playlist_name"] = str(name) variables["playlist_name"] = str(name)
variables["library_type"] = self.library.type.lower()
template_name = variables["name"] template_name = variables["name"]
template = self.templates[template_name] template = self.templates[template_name]
@ -215,17 +218,19 @@ class DataFile:
final_data = scan_text(final_data, dm, dd) final_data = scan_text(final_data, dm, dd)
return final_data return final_data
new_attributes = {}
for method_name, attr_data in template.items(): 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 method_name not in data and method_name not in ["default", "optional", "move_collection_prefix", "move_prefix"]:
if attr_data is None: if attr_data is None:
logger.error(f"Template Error: template attribute {method_name} is blank") logger.error(f"Template Error: template attribute {method_name} is blank")
continue continue
try: if method_name in new_attributes:
new_attributes[method_name] = check_data(method_name, attr_data) logger.warning(f"Template Warning: template attribute: {method_name} from {variables['name']} skipped")
except Failed: else:
continue try:
return new_attributes new_attributes[method_name] = check_data(method_name, attr_data)
except Failed:
continue
return new_attributes
class MetadataFile(DataFile): class MetadataFile(DataFile):
@ -270,8 +275,6 @@ class MetadataFile(DataFile):
auto_type = dynamic[methods["type"]].lower() 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 [] 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 [] 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 {} 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] exclude = [str(e) for e in og_exclude]
for k, v in addons.items(): for k, v in addons.items():
@ -312,7 +315,7 @@ class MetadataFile(DataFile):
tags = library.get_tags(f"episode.{search_tag}") tags = library.get_tags(f"episode.{search_tag}")
else: else:
tags = library.get_tags(search_tag) 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] 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} 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: 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") 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: if tmdb_item and tmdb_item.countries:
for country in tmdb_item.countries: for country in tmdb_item.countries:
all_keys.append(country.iso_3166_1) all_keys.append(country.iso_3166_1.lower())
if country.iso_3166_1 not in exclude and country.name not in exclude: if country.iso_3166_1.lower() not in exclude and country.name not in exclude:
auto_list[country.iso_3166_1] = country.name auto_list[country.iso_3166_1.lower()] = country.name
logger.exorcise() logger.exorcise()
default_title_format = "<<key_name>> <<library_type>>s" default_title_format = "<<key_name>> <<library_type>>s"
elif auto_type in ["actor", "director", "writer", "producer"]: elif auto_type in ["actor", "director", "writer", "producer"]:
@ -493,6 +496,7 @@ class MetadataFile(DataFile):
for key, value in auto_list.items(): for key, value in auto_list.items():
logger.debug(f" - {key}{'' if key == value else f' ({value})'}") logger.debug(f" - {key}{'' if key == value else f' ({value})'}")
used_keys = []
for key, value in auto_list.items(): for key, value in auto_list.items():
if include and key not in include: if include and key not in include:
if key not in exclude: if key not in exclude:
@ -511,15 +515,16 @@ class MetadataFile(DataFile):
key_value = [key] if key in all_keys else [] key_value = [key] if key in all_keys else []
if key in addons: if key in addons:
key_value.extend([a for a in addons[key] if a in all_keys and a != key]) key_value.extend([a for a in addons[key] if a in all_keys and a != key])
template_call = { used_keys.extend(key_value)
"name": template_names, og_call = {"value": key_value, auto_type: key_value, "key_name": key_name, "key": key}
"value": key_value,
auto_type: key_value,
"key_name": key_name, "key": key
}
for k, v in template_variables.items(): for k, v in template_variables.items():
if key in v: 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: if key in title_override:
collection_title = title_override[key] collection_title = title_override[key]
else: else:
@ -534,17 +539,19 @@ class MetadataFile(DataFile):
sync.pop(collection_title) sync.pop(collection_title)
self.collections[collection_title] = col self.collections[collection_title] = col
if other_name: if other_name:
template_call = { og_other = {
"name": other_templates, "value": other_keys, "included_keys": include, "used_keys": used_keys,
"value": other_keys, auto_type: other_keys, "key_name": other_name, "key": "other"
"included_keys": include,
auto_type: other_keys,
"key_name": other_name, "key": "other"
} }
for k, v in template_variables.items(): for k, v in template_variables.items():
if "other" in v: if "other" in v:
template_call[k] = v["other"] og_other[k] = v["other"]
col = {"template": template_call, "label": str(map_name)} 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: if test:
col["test"] = True col["test"] = True
if other_name in sync: if other_name in sync:

@ -360,17 +360,17 @@ class Trakt:
if "ratings" in dict_methods: 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="-") 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: 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: 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: 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: 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: 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: 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) valid_dicts.append(final_dict)
else: else:
userlist = util.parse(err_type, "userlist", trakt_dict, methods=dict_methods, parent=method_name, options=["recommended", "watched", "collected", "watchlist"]) userlist = util.parse(err_type, "userlist", trakt_dict, methods=dict_methods, parent=method_name, options=["recommended", "watched", "collected", "watchlist"])

@ -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))): 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) final_list.append(str(v) if datatype == "strlist" else v)
elif options: 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 return final_list
elif datatype == "intlist": elif datatype == "intlist":
if value: if value:

Loading…
Cancel
Save