less radarr/sonarr calls

This commit is contained in:
meisnate12 2021-04-02 14:15:43 -04:00
parent 1e9c901466
commit f5fc9a8509
3 changed files with 40 additions and 26 deletions

View file

@ -1077,7 +1077,7 @@ class CollectionBuilder:
if self.details["save_missing"] is True:
self.library.add_missing(collection_name, missing_movies_with_names, True)
if self.do_arr and self.library.Radarr:
self.library.Radarr.add_tmdb([missing_id for title, missing_id in missing_movies_with_names], tag=self.details["arr_tag"], folder=self.details["arr_folder"])
self.library.Radarr.add_tmdb([missing_id for title, missing_id in missing_movies_with_names], tags=self.details["arr_tag"], folder=self.details["arr_folder"])
if self.run_again:
self.missing_movies.extend([missing_id for title, missing_id in missing_movies_with_names])
if len(missing_shows) > 0 and self.library.is_show:
@ -1106,7 +1106,7 @@ class CollectionBuilder:
if self.details["save_missing"] is True:
self.library.add_missing(collection_name, missing_shows_with_names, False)
if self.do_arr and self.library.Sonarr:
self.library.Sonarr.add_tvdb([missing_id for title, missing_id in missing_shows_with_names], tag=self.details["arr_tag"], folder=self.details["arr_folder"])
self.library.Sonarr.add_tvdb([missing_id for title, missing_id in missing_shows_with_names], tags=self.details["arr_tag"], folder=self.details["arr_folder"])
if self.run_again:
self.missing_shows.extend([missing_id for title, missing_id in missing_shows_with_names])

View file

@ -28,6 +28,7 @@ class RadarrAPI:
self.quality_profile_id = profile["id"]
if not self.quality_profile_id:
raise Failed(f"Radarr Error: quality_profile: {params['quality_profile']} does not exist in radarr. Profiles available: {profiles}")
self.tags = self.get_tags()
self.tmdb = tmdb
self.url = params["url"]
self.version = params["version"]
@ -37,22 +38,28 @@ class RadarrAPI:
self.search = params["search"]
self.tag = params["tag"]
def add_tmdb(self, tmdb_ids, tag=None, folder=None):
def get_tags(self):
return {tag["label"]: tag["id"] for tag in self.send_get("tag")}
def add_tags(self, tags):
added = False
for label in tags:
if label not in self.tags:
added = True
self.send_post("tag", {"label": str(label)})
if added:
self.tags = self.get_tags()
def add_tmdb(self, tmdb_ids, tags=None, folder=None):
logger.info("")
logger.debug(f"TMDb IDs: {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", {"label": str(label)})
for t in self.send_get("tag"):
tag_cache[t["label"]] = t["id"]
for label in tag:
if label in tag_cache:
tag_nums.append(tag_cache[label])
if tags is None:
tags = self.tag
if tags:
self.add_tags(tags)
tag_nums = [self.tags[label] for label in tags if label in self.tags]
for tmdb_id in tmdb_ids:
try:
movie = self.tmdb.get_movie(tmdb_id)

View file

@ -44,6 +44,7 @@ class SonarrAPI:
if self.language_profile_id is None:
self.language_profile_id = 1
self.tags = self.get_tags()
self.tvdb = tvdb
self.language = language
self.url = params["url"]
@ -55,22 +56,28 @@ class SonarrAPI:
self.season_folder = params["season_folder"]
self.tag = params["tag"]
def add_tvdb(self, tvdb_ids, tag=None, folder=None):
def get_tags(self):
return {tag["label"]: tag["id"] for tag in self.send_get("tag")}
def add_tags(self, tags):
added = False
for label in tags:
if label not in self.tags:
added = True
self.send_post("tag", {"label": str(label)})
if added:
self.tags = self.get_tags()
def add_tvdb(self, tvdb_ids, tags=None, folder=None):
logger.info("")
logger.debug(f"TVDb IDs: {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", {"label": str(label)})
for t in self.send_get("tag"):
tag_cache[t["label"]] = t["id"]
for label in tag:
if label in tag_cache:
tag_nums.append(tag_cache[label])
if tags is None:
tags = self.tag
if tags:
self.add_tags(tags)
tag_nums = [self.tags[label] for label in tags if label in self.tags]
for tvdb_id in tvdb_ids:
try:
show = self.tvdb.get_series(self.language, tvdb_id)