diff --git a/modules/builder.py b/modules/builder.py index 90430d31..fda5086b 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -777,10 +777,7 @@ class CollectionBuilder: def _details(self, method_name, method_data, method_final, methods): if method_name == "collection_mode": - if str(method_data).lower() in plex.collection_mode_options: - self.details[method_name] = plex.collection_mode_options[str(method_data).lower()] - else: - raise Failed(f"{self.Type} Error: {method_data} collection_mode invalid\n\tdefault (Library default)\n\thide (Hide Collection)\n\thide_items (Hide Items in this Collection)\n\tshow_items (Show this Collection and its Items)") + self.details[method_name] = util.check_collection_mode(method_data) elif method_name == "collection_minimum": self.minimum = self._parse(method_name, method_data, datatype="int", minimum=1) elif method_name == "server_preroll": @@ -2148,10 +2145,7 @@ class CollectionBuilder: logger.info(f"Detail: content_rating updated Collection Content Rating to {self.details['content_rating']}") if "collection_mode" in self.details: - if int(self.obj.collectionMode) not in plex.collection_mode_keys\ - or plex.collection_mode_keys[int(self.obj.collectionMode)] != self.details["collection_mode"]: - self.library.collection_mode_query(self.obj, self.details["collection_mode"]) - logger.info(f"Detail: collection_mode updated Collection Mode to {self.details['collection_mode']}") + self.library.collection_mode_query(self.obj, self.details["collection_mode"]) if "collection_order" in self.details: if int(self.obj.collectionSort) not in plex.collection_order_keys\ diff --git a/modules/config.py b/modules/config.py index be616479..98c6e7b4 100644 --- a/modules/config.py +++ b/modules/config.py @@ -482,7 +482,12 @@ class ConfigFile: continue params = { "mapping_name": str(library_name), - "name": str(lib["library_name"]) if lib and "library_name" in lib and lib["library_name"] else str(library_name) + "name": str(lib["library_name"]) if lib and "library_name" in lib and lib["library_name"] else str(library_name), + "tmdb_collections": None, + "genre_mapper": None, + "radarr_remove_by_tag": None, + "sonarr_remove_by_tag": None, + "mass_collection_mode": None } display_name = f"{params['name']} ({params['mapping_name']})" if lib and "library_name" in lib and lib["library_name"] else params["mapping_name"] @@ -527,10 +532,6 @@ class ConfigFile: params["split_duplicates"] = check_for_attribute(lib, "split_duplicates", var_type="bool", default=False, save=False, do_print=False) params["radarr_add_all"] = check_for_attribute(lib, "radarr_add_all", var_type="bool", default=False, save=False, do_print=False) params["sonarr_add_all"] = check_for_attribute(lib, "sonarr_add_all", var_type="bool", default=False, save=False, do_print=False) - params["tmdb_collections"] = None - params["genre_mapper"] = None - params["radarr_remove_by_tag"] = None - params["sonarr_remove_by_tag"] = None if lib and "operations" in lib and lib["operations"]: if isinstance(lib["operations"], dict): @@ -558,6 +559,11 @@ class ConfigFile: params["sonarr_add_all"] = check_for_attribute(lib["operations"], "sonarr_add_all", var_type="bool", default=False, save=False) if "sonarr_remove_by_tag" in lib["operations"]: params["sonarr_remove_by_tag"] = check_for_attribute(lib["operations"], "sonarr_remove_by_tag", var_type="comma_list", default=False, save=False) + if "mass_collection_mode" in lib["operations"]: + try: + params["mass_collection_mode"] = util.check_collection_mode(lib["operations"]["mass_collection_mode"]) + except Failed as e: + logger.error(e) if "tmdb_collections" in lib["operations"]: params["tmdb_collections"] = { "exclude_ids": [], diff --git a/modules/library.py b/modules/library.py index 8ae65f2e..786cb4c5 100644 --- a/modules/library.py +++ b/modules/library.py @@ -70,6 +70,7 @@ class Library(ABC): self.radarr_remove_by_tag = params["radarr_remove_by_tag"] self.sonarr_add_all = params["sonarr_add_all"] self.sonarr_remove_by_tag = params["sonarr_remove_by_tag"] + self.mass_collection_mode = params["mass_collection_mode"] self.tmdb_collections = params["tmdb_collections"] self.genre_mapper = params["genre_mapper"] self.error_webhooks = params["error_webhooks"] diff --git a/modules/plex.py b/modules/plex.py index 037b96e4..84fe0842 100644 --- a/modules/plex.py +++ b/modules/plex.py @@ -339,7 +339,9 @@ class Plex(Library): @retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_plex) def collection_mode_query(self, collection, data): - collection.modeUpdate(mode=data) + if int(collection.collectionMode) not in collection_mode_keys or collection_mode_keys[int(collection.collectionMode)] != data: + collection.modeUpdate(mode=data) + logger.info(f"Detail: collection_order updated Collection Order to {data}") @retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_plex) def collection_order_query(self, collection, data): diff --git a/modules/util.py b/modules/util.py index 0455a589..90e4130a 100644 --- a/modules/util.py +++ b/modules/util.py @@ -1,6 +1,7 @@ import glob, logging, os, re, signal, sys, time, traceback from datetime import datetime, timedelta from logging.handlers import RotatingFileHandler +from modules import plex from pathvalidate import is_valid_filename, sanitize_filename from plexapi.exceptions import BadRequest, NotFound, Unauthorized from plexapi.video import Season, Episode, Movie @@ -347,6 +348,11 @@ def is_string_filter(values, modifier, data): if jailbreak: break return (jailbreak and modifier in [".not", ".isnot"]) or (not jailbreak and modifier in ["", ".is", ".begins", ".ends", ".regex"]) +def check_collection_mode(collection_mode): + if collection_mode and str(collection_mode).lower() in plex.collection_mode_options: + return plex.collection_mode_options[str(collection_mode).lower()] + else: + raise Failed(f"Config Error: {collection_mode} collection_mode invalid\n\tdefault (Library default)\n\thide (Hide Collection)\n\thide_items (Hide Items in this Collection)\n\tshow_items (Show this Collection and its Items)") def check_day(_m, _d): if _m in [1, 3, 5, 7, 8, 10, 12] and _d > 31: diff --git a/plex_meta_manager.py b/plex_meta_manager.py index ab7baa71..1454ba41 100644 --- a/plex_meta_manager.py +++ b/plex_meta_manager.py @@ -653,6 +653,7 @@ def library_operations(config, library): logger.debug(f"Mass Audience Rating Update: {library.mass_audience_rating_update}") logger.debug(f"Mass Critic Rating Update: {library.mass_critic_rating_update}") logger.debug(f"Mass Trakt Rating Update: {library.mass_trakt_rating_update}") + logger.debug(f"Mass Collection Mode Update: {library.mass_collection_mode}") logger.debug(f"Split Duplicates: {library.split_duplicates}") logger.debug(f"Radarr Add All: {library.radarr_add_all}") logger.debug(f"Radarr Remove by Tag: {library.radarr_remove_by_tag}") @@ -891,6 +892,8 @@ def library_operations(config, library): logger.info(f"{col.title} Deleted") elif col.title not in library.collections: unmanaged_collections.append(col) + if library.mass_collection_mode: + library.collection_mode_query(col, library.mass_collection_mode) if library.show_unmanaged and len(unmanaged_collections) > 0: logger.info("")