diff --git a/VERSION b/VERSION index b9a05a6d..10d3e72a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.17.3 +1.17.3-develop1 diff --git a/modules/builder.py b/modules/builder.py index 55229965..731bca7a 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -257,7 +257,7 @@ class CollectionBuilder: logger.warning(f"Collection Warning: {level_attr} attribute will run as builder_level") break - if level and not self.library.is_movie and not self.playlist: + if level and not self.playlist and not self.library.is_movie: logger.debug("") logger.debug("Validating Method: builder_level") if level is None: @@ -1788,6 +1788,7 @@ class CollectionBuilder: def build_url_arg(arg, mod=None, arg_s=None, mod_s=None): arg_key = plex.search_translation[attr] if attr in plex.search_translation else attr + arg_key = f"{sort_type}.label" if arg_key == "label" and sort_type in ["season", "episode", "album", "track"] else arg_key arg_key = plex.show_translation[arg_key] if self.library.is_show and arg_key in plex.show_translation else arg_key if mod is None: mod = plex.modifier_translation[modifier] if modifier in plex.modifier_translation else modifier diff --git a/modules/mdblist.py b/modules/mdblist.py index 0a80df90..510b1511 100644 --- a/modules/mdblist.py +++ b/modules/mdblist.py @@ -104,7 +104,10 @@ class Mdblist: if self.config.trace_mode: logger.debug(f"ID: {key}") logger.debug(f"Params: {params}") - response = self.config.get_json(api_url, params=params) + try: + response = self.config.get_json(api_url, params=params) + except JSONDecodeError: + raise Failed("Mdblist Error: JSON Decoding Failed") if "response" in response and response["response"] is False: if response["error"] == "API Limit Reached!": self.limit = True diff --git a/modules/meta.py b/modules/meta.py index f8bed576..c907bae1 100644 --- a/modules/meta.py +++ b/modules/meta.py @@ -165,43 +165,33 @@ class DataFile: for key, value in variables.copy().items(): variables[f"{key}_encoded"] = requests.utils.quote(str(value)) - default = {} - def add_default(d_key, d_value): - for v_key, v_value in variables.items(): - if f"<<{v_key}>>" in str(d_value): - d_value = str(d_value).replace(f"<<{v_key}>>", str(v_value)) - default[d_key] = d_value - default[f"{d_key}_encoded"] = requests.utils.quote(str(d_value)) - - def small_var_check(var_check): - for var_k, var_v in variables.items(): - if f"<<{var_k}>>" in str(var_check): - var_check = str(var_check).replace(f"<<{var_k}>>", str(var_v)) - for var_k, var_v in default.items(): - if f"<<{var_k}>>" in str(var_check): - var_check = str(var_check).replace(f"<<{var_k}>>", str(var_v)) - return var_check + def replace_var(input_item, search_dict): + return_item = input_item + for rk, rv in search_dict.items(): + if f"<<{rk}>>" in return_item: + return_item = return_item.replace(f"<<{rk}>>", str(rv)) + return return_item + ini_default = {} + default = {} if "default" in template: if not template["default"]: raise Failed(f"{self.data_type} Error: template sub-attribute default is blank") if not isinstance(template["default"], dict): raise Failed(f"{self.data_type} Error: template sub-attribute default is not a dictionary") for dv in template["default"]: - final_key = dv - for k, v in variables.items(): - if f"<<{k}>>" in final_key: - final_key = final_key.replace(f"<<{k}>>", str(v)) - if final_key not in optional: - final_value = template["default"][dv] - add_default(final_key, final_value) + ini_default[replace_var(dv, variables)] = replace_var(template["default"][dv], variables) + for dkey, dvalue in ini_default.items(): + final_key = replace_var(dkey, ini_default) + final_value = replace_var(dvalue, ini_default) + if final_key not in optional: + default[final_key] = final_value + default[f"{final_key}_encoded"] = requests.utils.quote(str(final_value)) if "optional" in template: if template["optional"]: for op in util.get_list(template["optional"]): - for k, v in variables.items(): - if f"<<{k}>>" in op: - op = op.replace(f"<<{k}>>", str(v)) + op = replace_var(op, variables) if op not in default: optional.append(str(op)) optional.append(f"{op}_encoded") @@ -221,7 +211,7 @@ class DataFile: logger.debug(f"Conditional: {con_key}") if not isinstance(con_value, dict): raise Failed(f"{self.data_type} Error: template sub-attribute conditionals is not a dictionary") - final_key = small_var_check(con_key) + final_key = replace_var(replace_var(con_key, variables), default) if final_key != con_key: logger.debug(f"Variable: {final_key}") if final_key in variables: @@ -243,11 +233,11 @@ class DataFile: for var_key, var_value in condition.items(): if var_key == "value": continue - var_key = small_var_check(var_key) - var_value = small_var_check(var_value) + var_key = replace_var(replace_var(var_key, variables), default) + var_value = replace_var(replace_var(var_value, variables), default) if var_key in variables: if (isinstance(var_value, list) and variables[var_key] not in var_value) or \ - (not isinstance(var_value, list) and variables[var_key] != var_value): + (not isinstance(var_value, list) and variables[var_key] != var_value): if isinstance(var_value, list): logger.debug(f'Condition {i} Failed: {var_key} "{variables[var_key]}" not in {var_value}') else: @@ -256,7 +246,7 @@ class DataFile: break elif var_key in default: if (isinstance(var_value, list) and default[var_key] not in var_value) or \ - (not isinstance(var_value, list) and default[var_key] != var_value): + (not isinstance(var_value, list) and default[var_key] != var_value): if isinstance(var_value, list): logger.debug(f'Condition {i} Failed: {var_key} "{default[var_key]}" not in {var_value}') else: diff --git a/modules/trakt.py b/modules/trakt.py index d845fb6c..8293c1e8 100644 --- a/modules/trakt.py +++ b/modules/trakt.py @@ -151,6 +151,10 @@ class Trakt: response = self.config.get(f"{base_url}/users/settings", headers=headers) if response.status_code == 423: raise Failed("Trakt Error: Account is Locked please Contact Trakt Support") + if self.config.trace_mode: + logger.debug(f"Trakt Error Code: {response.status_code}") + logger.debug(f"Trakt Error Reason: {response.reason}") + logger.debug(f"Trakt Error JSON: {response.json()}") return response.status_code == 200 def _refresh(self): diff --git a/modules/util.py b/modules/util.py index 7f2b3bf3..52cbd9c9 100644 --- a/modules/util.py +++ b/modules/util.py @@ -324,11 +324,11 @@ def item_title(item): else: return f"{item.parentTitle} Season {item.index}: {item.title}" elif isinstance(item, Episode): - text = f"{item.grandparentTitle} S{item.parentIndex:02}E{item.index:02}" - if f"Season {item.parentIndex}" == item.parentTitle: - return f"{text}: {item.title}" - else: - return f"{text}: {item.parentTitle}: {item.title}" + season = item.parentIndex if item.parentIndex else 0 + episode = item.index if item.index else 0 + show_title = item.grandparentTitle if item.grandparentTitle else "" + season_title = f"{item.parentTitle}: " if item.parentTitle and f"Season {season}" == item.parentTitle else "" + return f"{show_title} S{season:02}E{episode:02}: {season_title}{item.title if item.title else ''}" elif isinstance(item, Movie) and item.year: return f"{item.title} ({item.year})" elif isinstance(item, Album):