From ae7643b38ccf9b78d73ed24c71984402c6287382 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Sat, 18 Dec 2021 17:45:09 -0500 Subject: [PATCH] #517 added radarr_remove_by_tag and sonarr_remove_by_tag operations --- modules/config.py | 9 +++++++-- modules/library.py | 2 ++ modules/radarr.py | 15 +++++++++++++++ modules/sonarr.py | 15 +++++++++++++++ plex_meta_manager.py | 7 +++++++ 5 files changed, 46 insertions(+), 2 deletions(-) diff --git a/modules/config.py b/modules/config.py index 5cfeaa9b..9d2cbeb2 100644 --- a/modules/config.py +++ b/modules/config.py @@ -148,9 +148,9 @@ class ConfigFile: elif attribute not in loaded_config[parent]: loaded_config[parent][attribute] = default else: endline = "" yaml.round_trip_dump(loaded_config, open(self.config_path, "w"), indent=None, block_seq_indent=2) - if default_is_none and var_type in ["list", "int_list"]: return default if default else [] + if default_is_none and var_type in ["list", "int_list", "comma_list"]: return default if default else [] elif data[attribute] is None: - if default_is_none and var_type in ["list", "int_list"]: return default if default else [] + if default_is_none and var_type in ["list", "int_list", "comma_list"]: return default if default else [] elif default_is_none: return None else: message = f"{text} is blank" elif var_type == "url": @@ -166,6 +166,7 @@ class ConfigFile: if os.path.exists(os.path.abspath(data[attribute])): return data[attribute] else: message = f"Path {os.path.abspath(data[attribute])} does not exist" elif var_type == "list": return util.get_list(data[attribute], split=False) + elif var_type == "comma_list": return util.get_list(data[attribute]) elif var_type == "int_list": return util.get_list(data[attribute], int_list=True) elif var_type == "list_path": temp_list = [] @@ -547,8 +548,12 @@ class ConfigFile: params["split_duplicates"] = check_for_attribute(lib["operations"], "split_duplicates", var_type="bool", default=False, save=False) if "radarr_add_all" in lib["operations"]: params["radarr_add_all"] = check_for_attribute(lib["operations"], "radarr_add_all", var_type="bool", default=False, save=False) + if "radarr_remove_by_tag" in lib["operations"]: + params["radarr_remove_by_tag"] = check_for_attribute(lib["operations"], "radarr_remove_by_tag", var_type="comma_list", default=False, save=False) if "sonarr_add_all" in lib["operations"]: 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 "tmdb_collections" in lib["operations"]: params["tmdb_collections"] = {"exclude_ids": [], "remove_suffix": None, "template": {"tmdb_collection_details": "<>"}} if lib["operations"]["tmdb_collections"] and isinstance(lib["operations"]["tmdb_collections"], dict): diff --git a/modules/library.py b/modules/library.py index 94e18d04..87d8afc0 100644 --- a/modules/library.py +++ b/modules/library.py @@ -66,7 +66,9 @@ class Library(ABC): self.mass_critic_rating_update = params["mass_critic_rating_update"] self.mass_trakt_rating_update = params["mass_trakt_rating_update"] self.radarr_add_all = params["radarr_add_all"] + 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.tmdb_collections = params["tmdb_collections"] self.genre_mapper = params["genre_mapper"] self.error_webhooks = params["error_webhooks"] diff --git a/modules/radarr.py b/modules/radarr.py index 74b5e0fe..481a908c 100644 --- a/modules/radarr.py +++ b/modules/radarr.py @@ -168,3 +168,18 @@ class Radarr: logger.info("") for tmdb_id in not_exists: logger.info(f"TMDb ID Not in Radarr | {tmdb_id}") + + def remove_all_with_tags(self, tags): + lower_tags = [_t.lower() for _t in tags] + remove_items = [] + for movie in self.api.all_movies(): + tag_strs = [_t.label.lower() for _t in movie.tags] + remove = True + for tag in lower_tags: + if tag not in tag_strs: + remove = False + break + if remove: + remove_items.append(movie) + if remove_items: + self.api.delete_multiple_movies(remove_items) diff --git a/modules/sonarr.py b/modules/sonarr.py index 43179202..89c0ad37 100644 --- a/modules/sonarr.py +++ b/modules/sonarr.py @@ -194,3 +194,18 @@ class Sonarr: logger.info("") for tvdb_id in not_exists: logger.info(f"TVDb ID Not in Sonarr | {tvdb_id}") + + def remove_all_with_tags(self, tags): + lower_tags = [_t.lower() for _t in tags] + remove_items = [] + for series in self.api.all_series(): + tag_strs = [_t.label.lower() for _t in series.tags] + remove = True + for tag in lower_tags: + if tag not in tag_strs: + remove = False + break + if remove: + remove_items.append(series) + if remove_items: + self.api.delete_multiple_series(remove_items) diff --git a/plex_meta_manager.py b/plex_meta_manager.py index 6ea61567..bc264af1 100644 --- a/plex_meta_manager.py +++ b/plex_meta_manager.py @@ -655,7 +655,9 @@ def library_operations(config, library): logger.debug(f"Mass Trakt Rating Update: {library.mass_trakt_rating_update}") 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}") logger.debug(f"Sonarr Add All: {library.sonarr_add_all}") + logger.debug(f"Sonarr Remove by Tag: {library.sonarr_remove_by_tag}") logger.debug(f"TMDb Collections: {library.tmdb_collections}") logger.debug(f"Genre Mapper: {library.genre_mapper}") tmdb_operation = library.assets_for_all or library.mass_genre_update or library.mass_audience_rating_update \ @@ -862,6 +864,11 @@ def library_operations(config, library): }) run_collection(config, library, metadata, metadata.get_collections(None)) + if library.radarr_remove_by_tag: + library.Radarr.remove_all_with_tags(library.radarr_remove_by_tag) + if library.sonarr_remove_by_tag: + library.Sonarr.remove_all_with_tags(library.sonarr_remove_by_tag) + if library.delete_collections_with_less is not None or library.delete_unmanaged_collections: logger.info("") print_suffix = ""