From 18e7c8446919aeee95ce9873fc302b9ffe4297e1 Mon Sep 17 00:00:00 2001 From: YozoraXCII <96386153+YozoraXCII@users.noreply.github.com> Date: Sun, 13 Mar 2022 20:44:42 +0000 Subject: [PATCH] [7] Resolve content_rating_mapper issues --- VERSION | 2 +- modules/config.py | 15 +++++++++++++++ modules/library.py | 3 ++- plex_meta_manager.py | 24 +++++++++++++++--------- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/VERSION b/VERSION index fa9c14dc..9504e7dc 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.16.1-develop6 +1.16.1-develop7 diff --git a/modules/config.py b/modules/config.py index 8ead5ebb..9b8a0f4d 100644 --- a/modules/config.py +++ b/modules/config.py @@ -593,6 +593,7 @@ class ConfigFile: "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, + "content_rating_mapper": None, "radarr_remove_by_tag": None, "sonarr_remove_by_tag": None, "mass_collection_mode": None, @@ -735,6 +736,20 @@ class ConfigFile: params["genre_mapper"][old_genre] = new_genre else: logger.error("Config Error: genre_mapper is blank") + if "content_rating_mapper" in lib["operations"]: + if lib["operations"]["content_rating_mapper"] and isinstance(lib["operations"]["content_rating_mapper"], dict): + params["content_rating_mapper"] = {} + for new_rating, old_ratings in lib["operations"]["content_rating_mapper"].items(): + if old_ratings is None: + params["content_rating_mapper"][new_rating] = old_ratings + else: + for old_rating in util.get_list(old_ratings): + if old_rating == new_rating: + logger.error("Config Error: Content Ratings cannot be mapped to themselves") + else: + params["content_rating_mapper"][old_rating] = new_rating + else: + logger.error("Config Error: content_rating_mapper is blank") if "genre_collections" in lib["operations"]: params["genre_collections"] = { "exclude_genres": [], diff --git a/modules/library.py b/modules/library.py index 9ad5e2d0..6e57f27c 100644 --- a/modules/library.py +++ b/modules/library.py @@ -83,6 +83,7 @@ class Library(ABC): self.tmdb_collections = params["tmdb_collections"] self.genre_collections = params["genre_collections"] self.genre_mapper = params["genre_mapper"] + self.content_rating_mapper = params["content_rating_mapper"] self.error_webhooks = params["error_webhooks"] self.changes_webhooks = params["changes_webhooks"] self.split_duplicates = params["split_duplicates"] # TODO: Here or just in Plex? @@ -94,7 +95,7 @@ class Library(ABC): self.items_library_operation = True if self.assets_for_all or self.mass_genre_update or self.mass_audience_rating_update \ or self.mass_critic_rating_update or self.mass_content_rating_update or self.mass_trakt_rating_update \ - or self.genre_mapper or self.tmdb_collections or self.radarr_add_all_existing or self.sonarr_add_all_existing else False + or self.genre_mapper or self.content_rating_mapper or self.tmdb_collections or self.radarr_add_all_existing or self.sonarr_add_all_existing else False self.library_operation = True if self.items_library_operation or self.delete_unmanaged_collections or self.delete_collections_with_less \ or self.radarr_remove_by_tag or self.sonarr_remove_by_tag or self.mass_collection_mode \ or self.genre_collections or self.show_unmanaged or self.metadata_backup or self.update_blank_track_titles else False diff --git a/plex_meta_manager.py b/plex_meta_manager.py index 93a4199a..97777c2b 100644 --- a/plex_meta_manager.py +++ b/plex_meta_manager.py @@ -418,6 +418,7 @@ def library_operations(config, library): logger.debug(f"TMDb Collections: {library.tmdb_collections}") logger.debug(f"Genre Collections: {library.genre_collections}") logger.debug(f"Genre Mapper: {library.genre_mapper}") + logger.debug(f"Content Rating Mapper: {library.content_rating_mapper}") logger.debug(f"Metadata Backup: {library.metadata_backup}") logger.debug(f"Item Operation: {library.items_library_operation}") logger.debug("") @@ -613,17 +614,22 @@ def library_operations(config, library): except Failed: pass - if library.genre_mapper: + if library.genre_mapper or library.content_rating_mapper: try: - adds = [] - deletes = [] library.reload(item) - for genre in item.genres: - if genre.tag in library.genre_mapper: - deletes.append(genre.tag) - if library.genre_mapper[genre.tag]: - adds.append(library.genre_mapper[genre.tag]) - library.edit_tags("genre", item, add_tags=adds, remove_tags=deletes) + if library.genre_mapper: + adds = [] + deletes = [] + for genre in item.genres: + if genre.tag in library.genre_mapper: + deletes.append(genre.tag) + if library.genre_mapper[genre.tag]: + adds.append(library.genre_mapper[genre.tag]) + library.edit_tags("genre", item, add_tags=adds, remove_tags=deletes) + if library.content_rating_mapper: + if item.contentRating in library.content_rating_mapper: + library.edit_query(item, {"contentRating.value": library.content_rating_mapper[item.contentRating], "contentRating.locked": 1}) + logger.info(f"{item.title[:25]:<25} | Content Rating | {library.content_rating_mapper[item.contentRating]}") except Failed: pass