diff --git a/modules/config.py b/modules/config.py index 4047658d..8f67ecc8 100644 --- a/modules/config.py +++ b/modules/config.py @@ -154,6 +154,7 @@ class Config: self.general["radarr"]["root_folder_path"] = check_for_attribute(self.data, "root_folder_path", parent="radarr", default_is_none=True) if "radarr" in self.data else None self.general["radarr"]["add"] = check_for_attribute(self.data, "add", parent="radarr", var_type="bool", default=False) if "radarr" in self.data else False self.general["radarr"]["search"] = check_for_attribute(self.data, "search", parent="radarr", var_type="bool", default=False) if "radarr" in self.data else False + self.general["radarr"]["tag"] = util.get_list(check_for_attribute(self.data, "tag", parent="radarr", default_is_none=True), lower=True) if "radarr" in self.data else None self.general["sonarr"] = {} self.general["sonarr"]["url"] = check_for_attribute(self.data, "url", parent="sonarr", default_is_none=True) if "sonarr" in self.data else None @@ -163,6 +164,7 @@ class Config: self.general["sonarr"]["root_folder_path"] = check_for_attribute(self.data, "root_folder_path", parent="sonarr", default_is_none=True) if "sonarr" in self.data else None self.general["sonarr"]["add"] = check_for_attribute(self.data, "add", parent="sonarr", var_type="bool", default=False) if "sonarr" in self.data else False self.general["sonarr"]["search"] = check_for_attribute(self.data, "search", parent="sonarr", var_type="bool", default=False) if "sonarr" in self.data else False + self.general["sonarr"]["tag"] = util.get_list(check_for_attribute(self.data, "tag", parent="sonarr", default_is_none=True), lower=True) if "sonarr" in self.data else None self.general["tautulli"] = {} self.general["tautulli"]["url"] = check_for_attribute(self.data, "url", parent="tautulli", default_is_none=True) if "tautulli" in self.data else None @@ -318,6 +320,12 @@ class Config: else: logger.warning("Config Warning: radarr sub-attribute search is blank using general value: {}".format(self.general["radarr"]["search"])) + if "tag" in libs[lib]["radarr"]: + if libs[lib]["radarr"]["tag"]: + params["radarr"]["tag"] = util.get_list(libs[lib]["radarr"]["tag"], lower=True) + else: + logger.warning("Config Warning: radarr sub-attribute tag is blank using general value: {}".format(self.general["radarr"]["tag"])) + if not params["radarr"]["url"] or not params["radarr"]["token"] or not params["radarr"]["quality_profile"] or not params["radarr"]["root_folder_path"]: params["radarr"] = None @@ -374,6 +382,12 @@ class Config: else: logger.warning("Config Warning: sonarr sub-attribute search is blank using general value: {}".format(self.general["sonarr"]["search"])) + if "tag" in libs[lib]["sonarr"]: + if libs[lib]["sonarr"]["tag"]: + params["sonarr"]["tag"] = util.get_list(libs[lib]["sonarr"]["tag"], lower=True) + else: + logger.warning("Config Warning: sonarr sub-attribute tag is blank using general value: {}".format(self.general["sonarr"]["tag"])) + if not params["sonarr"]["url"] or not params["sonarr"]["token"] or not params["sonarr"]["quality_profile"] or not params["sonarr"]["root_folder_path"] or params["library_type"] == "movie": params["sonarr"] = None @@ -597,6 +611,7 @@ class Config: elif method_name == "add_to_arr": if isinstance(collections[c][m], bool): details[method_name] = collections[c][m] else: raise Failed("Collection Error: add_to_arr must be either true or false") + elif method_name == "arr_tag": details[method_name] = util.get_list(collections[c][m]) elif method_name == "show_filtered": if isinstance(collections[c][m], bool): show_filtered = collections[c][m] else: raise Failed("Collection Error: show_filtered must be either true or false using the default false") @@ -872,6 +887,9 @@ class Config: if library.Sonarr: do_arr = details["add_to_arr"] if "add_to_arr" in details else library.Sonarr.add + movie_tag = details["arr_tag"] if "arr_tag" in details else None + show_tag = details["arr_tag"] if "arr_tag" in details else None + items_found = 0 library.clear_collection_missing(collection_name) @@ -990,7 +1008,7 @@ class Config: logger.info("{} Movie{} Missing".format(len(missing_movies_with_names), "s" if len(missing_movies_with_names) > 1 else "")) library.save_missing(collection_name, missing_movies_with_names, True) if do_arr and library.Radarr: - library.Radarr.add_tmdb([missing_id for title, missing_id in missing_movies_with_names]) + library.Radarr.add_tmdb([missing_id for title, missing_id in missing_movies_with_names], tag=movie_tag) if len(missing_shows) > 0 and library.is_show: missing_shows_with_names = [] for missing_id in missing_shows: @@ -1000,10 +1018,10 @@ class Config: logger.info("{} Collection | ? | {} (TVDB: {})".format(collection_name, title, missing_id)) except Failed as e: logger.error(e) - logger.info("{} Show{} Missing".format(len(missing_shows), "s" if len(missing_shows) > 1 else "")) + logger.info("{} Show{} Missing".format(len(missing_shows_with_names), "s" if len(missing_shows_with_names) > 1 else "")) library.save_missing(c, missing_shows_with_names, False) if do_arr and library.Sonarr: - library.Sonarr.add_tvdb(missing_shows) + library.Sonarr.add_tvdb([missing_id for title, missing_id in missing_shows_with_names], tag=show_tag) library.del_collection_if_empty(collection_name) diff --git a/modules/radarr.py b/modules/radarr.py index a0257edf..270fc231 100644 --- a/modules/radarr.py +++ b/modules/radarr.py @@ -37,11 +37,24 @@ class RadarrAPI: self.root_folder_path = params["root_folder_path"] self.add = params["add"] self.search = params["search"] + self.tag = params["tag"] - def add_tmdb(self, tmdb_ids): + def add_tmdb(self, tmdb_ids, tag=None): logger.info("") logger.debug("TMDb IDs: {}".format(tmdb_ids)) + tag_nums = [] add_count = 0 + if tag is None: + tag = self.tag + if tag: + tag_cache = {} + for label in tag: + self.send_post("{}tag".format(self.base_url), {"label": str(label)}) + for t in self.send_get("{}tag".format(self.base_url)).json(): + tag_cache[t["label"]] = t["id"] + for label in tag: + if label in tag_cache + tag_nums.append(tag_cache[label]) for tmdb_id in tmdb_ids: try: movie = self.tmdb.get_movie(tmdb_id) @@ -74,6 +87,8 @@ class RadarrAPI: "images": [{"covertype": "poster", "url": poster}], "addOptions": {"searchForMovie": self.search} } + if tag_nums: + url_json["tags"] = tag_nums response = self.send_post("{}movie".format(self.base_url), url_json) if response.status_code < 400: logger.info("Added to Radarr | {:<6} | {}".format(tmdb_id, movie.title)) @@ -86,6 +101,10 @@ class RadarrAPI: logger.error("Radarr Error: {}".format(response.json())) logger.info("{} Movie{} added to Radarr".format(add_count, "s" if add_count > 1 else "")) + @retry(stop_max_attempt_number=6, wait_fixed=10000) + def send_get(self, url, url_json): + return requests.get(url, json=url_json, params=self.url_params) + @retry(stop_max_attempt_number=6, wait_fixed=10000) def send_post(self, url, url_json): return requests.post(url, json=url_json, params=self.url_params) diff --git a/modules/sonarr.py b/modules/sonarr.py index 1351ebcb..fd4d6ba0 100644 --- a/modules/sonarr.py +++ b/modules/sonarr.py @@ -38,11 +38,24 @@ class SonarrAPI: self.root_folder_path = params["root_folder_path"] self.add = params["add"] self.search = params["search"] + self.tag = params["tag"] - def add_tvdb(self, tvdb_ids): + def add_tvdb(self, tvdb_ids, tag=None): logger.info("") logger.debug("TVDb IDs: {}".format(tvdb_ids)) + tag_nums = [] add_count = 0 + if tag is None: + tag = self.tag + if tag: + tag_cache = {} + for label in tag: + self.send_post("{}tag".format(self.base_url), {"label": str(label)}) + for t in self.send_get("{}tag".format(self.base_url)).json(): + tag_cache[t["label"]] = t["id"] + for label in tag: + if label in tag_cache + tag_nums.append(tag_cache[label]) for tvdb_id in tvdb_ids: try: show = self.tvdb.get_series(self.language, tvdb_id=tvdb_id) @@ -65,6 +78,8 @@ class SonarrAPI: "images": [{"covertype": "poster", "url": show.poster_path}], "addOptions": {"searchForMissingEpisodes": self.search} } + if tag_nums: + url_json["tags"] = tag_nums response = self.send_post("{}series".format(self.base_url), url_json) if response.status_code < 400: logger.info("Added to Sonarr | {:<6} | {}".format(tvdb_id, show.title)) @@ -77,6 +92,10 @@ class SonarrAPI: logger.error("Sonarr Error: {}".format(response.json())) logger.info("{} Show{} added to Sonarr".format(add_count, "s" if add_count > 1 else "")) + @retry(stop_max_attempt_number=6, wait_fixed=10000) + def send_get(self, url, url_json): + return requests.get(url, json=url_json, params=self.url_params) + @retry(stop_max_attempt_number=6, wait_fixed=10000) def send_post(self, url, url_json): return requests.post(url, json=url_json, params=self.url_params)