From d38f9df168558fe8478696174107b6fc0ae026fd Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Tue, 7 Dec 2021 02:10:07 -0500 Subject: [PATCH] #232 genre_mapper library operation --- modules/config.py | 9 +++++++++ modules/library.py | 3 ++- plex_meta_manager.py | 16 +++++++++++++--- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/modules/config.py b/modules/config.py index b4f1dd74..f7188c7a 100644 --- a/modules/config.py +++ b/modules/config.py @@ -456,6 +456,7 @@ class Config: 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 if lib and "operations" in lib and lib["operations"]: if isinstance(lib["operations"], dict): @@ -490,6 +491,14 @@ class Config: logger.warning("Config Warning: Using default template for tmdb_collections") else: logger.error("Config Error: tmdb_collections blank using default settings") + if "genre_mapper" in lib["operations"]: + if lib["operations"]["genre_mapper"] and isinstance(lib["operations"]["genre_mapper"], dict): + params["genre_mapper"] = {} + for new_genre, old_genres in lib["operations"]["genre_mapper"].items(): + for old_genre in util.get_list(old_genres, split=False): + params["genre_mapper"][old_genre] = new_genre + else: + logger.error("Config Error: genre_mapper is blank") else: logger.error("Config Error: operations must be a dictionary") diff --git a/modules/library.py b/modules/library.py index ed44ef22..e5f5b537 100644 --- a/modules/library.py +++ b/modules/library.py @@ -59,9 +59,10 @@ class Library(ABC): self.mass_audience_rating_update = params["mass_audience_rating_update"] self.mass_critic_rating_update = params["mass_critic_rating_update"] self.mass_trakt_rating_update = params["mass_trakt_rating_update"] - self.tmdb_collections = params["tmdb_collections"] self.radarr_add_all = params["radarr_add_all"] self.sonarr_add_all = params["sonarr_add_all"] + self.tmdb_collections = params["tmdb_collections"] + self.genre_mapper = params["genre_mapper"] self.error_webhooks = params["error_webhooks"] self.collection_changes_webhooks = params["collection_changes_webhooks"] self.split_duplicates = params["split_duplicates"] # TODO: Here or just in Plex? diff --git a/plex_meta_manager.py b/plex_meta_manager.py index 4bc5e005..a1a155db 100644 --- a/plex_meta_manager.py +++ b/plex_meta_manager.py @@ -230,6 +230,7 @@ def update_libraries(config): logger.debug(f"Radarr Add All: {library.radarr_add_all}") logger.debug(f"Sonarr Add All: {library.sonarr_add_all}") logger.debug(f"TMDb Collections: {library.tmdb_collections}") + logger.debug(f"Genre Mapper: {library.genre_mapper}") logger.debug(f"Clean Bundles: {library.clean_bundles}") logger.debug(f"Empty Trash: {library.empty_trash}") logger.debug(f"Optimize: {library.optimize}") @@ -442,9 +443,6 @@ def library_operations(config, library, items=None): else: logger.info(util.adjust_space(f"{item.title[:25]:<25} | No TVDb ID for Guid: {item.guid}")) - if not tmdb_item and not omdb_item and not tvdb_item: - continue - if library.tmdb_collections and tmdb_item and tmdb_item.belongs_to_collection: tmdb_collections[tmdb_item.belongs_to_collection.id] = tmdb_item.belongs_to_collection.name @@ -493,6 +491,18 @@ def library_operations(config, library, items=None): logger.info(util.adjust_space(f"{item.title[:25]:<25} | Critic Rating | {new_rating}")) except Failed: pass + if library.genre_mapper: + try: + adds = [] + deletes = [] + library.reload(item) + for genre in item.genres: + if genre.tag in library.genre_mapper: + deletes.append(genre.tag) + adds.append(library.genre_mapper[genre.tag]) + library.edit_tags("genre", item, add_tags=adds, remove_tags=deletes) + except Failed: + pass if library.Radarr and library.radarr_add_all: try: