#517 added radarr_remove_by_tag and sonarr_remove_by_tag operations

pull/528/head
meisnate12 3 years ago
parent b18aa534c6
commit ae7643b38c

@ -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": "<<collection_id>>"}}
if lib["operations"]["tmdb_collections"] and isinstance(lib["operations"]["tmdb_collections"], dict):

@ -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"]

@ -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)

@ -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)

@ -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 = ""

Loading…
Cancel
Save