diff --git a/modules/builder.py b/modules/builder.py index 679146ca..c2a923d8 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -434,8 +434,10 @@ class CollectionBuilder: self.details["collection_order"] = self.data[methods["collection_order"]].lower() if self.data[methods["collection_order"]].lower() == "custom" and self.build_collection: self.custom_sort = True + elif (self.library.is_movie and self.data[methods["collection_order"]].lower() in plex.movie_sorts) or (self.library.is_show and self.data[methods["collection_order"]].lower() in plex.show_sorts): + self.custom_sort = self.data[methods["collection_order"]].lower() else: - raise Failed(f"{self.Type} Error: {self.data[methods['collection_order']]} collection_order invalid\n\trelease (Order Collection by release dates)\n\talpha (Order Collection Alphabetically)\n\tcustom (Custom Order Collection)") + raise Failed(f"{self.Type} Error: {self.data[methods['collection_order']]} collection_order invalid\n\trelease (Order Collection by release dates)\n\talpha (Order Collection Alphabetically)\n\tcustom (Custom Order Collection)\n\tOther sorting options can be found at https://github.com/meisnate12/Plex-Meta-Manager/wiki/Smart-Builders#sort-options") self.sort_by = None if "sort_by" in methods and not self.playlist: @@ -596,7 +598,7 @@ class CollectionBuilder: else: logger.error(e) - if self.custom_sort and (len(self.builders) > 1 or self.builders[0][0] not in custom_sort_builders): + if self.custom_sort is True and (len(self.builders) > 1 or self.builders[0][0] not in custom_sort_builders): raise Failed(f"{self.Type} Error: " + ('Playlists' if playlist else 'collection_order: custom') + (f" can only be used with a single builder per {self.type}" if len(self.builders) > 1 else f" cannot be used with {self.builders[0][0]}")) @@ -2245,11 +2247,11 @@ class CollectionBuilder: logger.info("") util.separator(f"Sorting {self.name} {self.Type}", space=False, border=False) logger.info("") - if self.sort_by: - search_data = self.build_filter("plex_search", {"sort_by": self.sort_by, "any": {"collection": self.name}}) - items = self.library.get_filter_items(search_data[2]) - else: + if self.custom_sort is True: items = self.added_items + else: + search_data = self.build_filter("plex_search", {"sort_by": self.custom_sort, "any": {"collection": self.name}}) + items = self.library.get_filter_items(search_data[2]) previous = None for item in items: text = f"after {util.item_title(previous)}" if previous else "to the beginning" diff --git a/modules/config.py b/modules/config.py index 98c6e7b4..2a925223 100644 --- a/modules/config.py +++ b/modules/config.py @@ -267,6 +267,7 @@ class ConfigFile: "test": check_for_attribute(self.data, "test", parent="notifiarr", var_type="bool", default=False, do_print=False, save=False) }) except Failed as e: + util.print_stacktrace() logger.error(e) logger.info(f"Notifiarr Connection {'Failed' if self.NotifiarrFactory is None else 'Successful'}") else: @@ -567,14 +568,14 @@ class ConfigFile: if "tmdb_collections" in lib["operations"]: params["tmdb_collections"] = { "exclude_ids": [], - "remove_suffix": None, + "remove_suffix": [], "dictionary_variables": {}, "template": {"tmdb_collection_details": "<>"} } if lib["operations"]["tmdb_collections"] and isinstance(lib["operations"]["tmdb_collections"], dict): params["tmdb_collections"]["exclude_ids"] = check_for_attribute(lib["operations"]["tmdb_collections"], "exclude_ids", var_type="int_list", default_is_none=True, save=False) - params["tmdb_collections"]["remove_suffix"] = check_for_attribute(lib["operations"]["tmdb_collections"], "remove_suffix", default_is_none=True, save=False) + params["tmdb_collections"]["remove_suffix"] = check_for_attribute(lib["operations"]["tmdb_collections"], "remove_suffix", var_type="comma_list", default_is_none=True, save=False) if "dictionary_variables" in lib["operations"]["tmdb_collections"] and lib["operations"]["tmdb_collections"]["dictionary_variables"] and isinstance(lib["operations"]["tmdb_collections"]["dictionary_variables"], dict): for key, value in lib["operations"]["tmdb_collections"]["dictionary_variables"].items(): if isinstance(value, dict): @@ -587,8 +588,6 @@ class ConfigFile: logger.warning("Config Warning: Using default template for tmdb_collections") else: logger.error("Config Error: tmdb_collections blank using default settings") - if params["tmdb_collections"]["remove_suffix"]: - params["tmdb_collections"]["remove_suffix"] = params["tmdb_collections"]["remove_suffix"].strip() if "genre_mapper" in lib["operations"]: if lib["operations"]["genre_mapper"] and isinstance(lib["operations"]["genre_mapper"], dict): params["genre_mapper"] = {} diff --git a/modules/notifiarr.py b/modules/notifiarr.py index d4262b39..01eef137 100644 --- a/modules/notifiarr.py +++ b/modules/notifiarr.py @@ -15,12 +15,14 @@ class Notifiarr: self.apikey = params["apikey"] self.develop = params["develop"] self.test = params["test"] + logger.debug(f"Environment: {'Test' if self.test else 'Develop' if self.develop else 'Production'}") url, _ = self.get_url("user/validate/") response = self.config.get(url) try: response_json = response.json() except JSONDecodeError as e: - raise Failed(e) + logger.debug(e) + raise Failed("Notifiarr Error: Invalid response") if response.status_code >= 400 or ("result" in response_json and response_json["result"] == "error"): logger.debug(f"Response: {response_json}") raise Failed(f"({response.status_code} [{response.reason}]) {response_json}") diff --git a/modules/playlist.py b/modules/playlist.py index 620d8152..352bb1d6 100644 --- a/modules/playlist.py +++ b/modules/playlist.py @@ -63,4 +63,4 @@ class PlaylistFile: raise Failed(f"YAML Error: {util.tab_new_lines(ye)}") except Exception as e: util.print_stacktrace() - raise Failed(f"YAML Error: {e}") \ No newline at end of file + raise Failed(f"YAML Error: {e}") diff --git a/plex_meta_manager.py b/plex_meta_manager.py index 1454ba41..5b8f9a83 100644 --- a/plex_meta_manager.py +++ b/plex_meta_manager.py @@ -846,7 +846,6 @@ def library_operations(config, library): logger.info("") util.separator(f"Starting TMDb Collections") logger.info("") - suffixes = util.get_list(library.tmdb_collections["remove_suffix"]) new_collections = {} for _i, _n in tmdb_collections.items(): if int(_i) not in library.tmdb_collections["exclude_ids"]: @@ -854,10 +853,9 @@ def library_operations(config, library): for k, v in library.tmdb_collections["dictionary_variables"]: if int(_i) in v: template[k] = v[int(_i)] - if suffixes: - for suffix in suffixes: - if _n.endswith(suffix): - _n = _n[:-len(_n)] + for suffix in library.tmdb_collections["remove_suffix"]: + if _n.endswith(suffix): + _n = _n[:-len(_n)] new_collections[_n.strip()] = {"template": template} metadata = MetadataFile(config, library, "Data", { "collections": new_collections, @@ -1044,7 +1042,7 @@ def run_collection(config, library, metadata, requested_collections): logger.info("") logger.info(f"Plex Server Movie pre-roll video updated to {builder.server_preroll}") - if (builder.item_details or builder.custom_sort or builder.sort_by) and run_item_details and builder.builders: + if (builder.item_details or builder.custom_sort) and run_item_details and builder.builders: try: builder.load_collection_items() except Failed: @@ -1053,7 +1051,7 @@ def run_collection(config, library, metadata, requested_collections): else: if builder.item_details: builder.update_item_details() - if builder.custom_sort or builder.sort_by: + if builder.custom_sort: library.run_sort.append(builder) # builder.sort_collection()