Skip to content

Commit

Permalink
fix for multiple ids in the same call
Browse files Browse the repository at this point in the history
  • Loading branch information
meisnate12 committed Nov 24, 2021
1 parent 49c650c commit cffa043
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 23 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.4
1.2.5
23 changes: 15 additions & 8 deletions arrapi/apis/radarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,21 @@ def _validate_ids(self, ids):
""" Validate IDs. """
valid_ids = []
invalid_ids = []
used_ids = []
radarr_ids = {}
for m in self.all_movies():
radarr_ids[m.tmdbId] = m
radarr_ids[str(m.tmdbId)] = m
radarr_ids[m.imdbId] = m
for _id in ids:
if isinstance(_id, Movie):
if isinstance(_id, Movie) and str(_id.tmdbId) not in used_ids and str(_id.imdbId) not in used_ids:
valid_ids.append(_id.id)
elif _id in radarr_ids:
used_ids.append(str(_id.tmdbId))
used_ids.append(str(_id.imdbId))
elif _id in radarr_ids and str(_id.tmdbId) not in used_ids and str(_id.imdbId) not in used_ids:
valid_ids.append(radarr_ids[_id].id)
used_ids.append(str(_id.tmdbId))
used_ids.append(str(_id.imdbId))
else:
invalid_ids.append(_id)
return valid_ids, invalid_ids
Expand Down Expand Up @@ -264,26 +269,28 @@ def add_multiple_movies(self, ids: List[Union[int, str, Movie, Tuple[Union[int,
movies = []
existing_movies = []
invalid_ids = []
for item in ids:
path = item[1] if isinstance(item, tuple) else None
item = item[0] if isinstance(item, tuple) else item
used_ids = []
for input_item in ids:
path = input_item[1] if isinstance(input_item, tuple) else None
item = input_item[0] if isinstance(input_item, tuple) else input_item
try:
if isinstance(item, Movie):
movie = item
elif str(item).startswith("tt"):
movie = self.get_movie(imdb_id=item)
else:
if self.exclusions and int(item) in self.exclusions:
if int(item) in used_ids or (self.exclusions and int(item) in self.exclusions):
raise NotFound
movie = self.get_movie(tmdb_id=item)
if self.exclusions and movie.tmdbId in self.exclusions:
if movie.tmdbId in used_ids or (self.exclusions and movie.tmdbId in self.exclusions):
raise NotFound
used_ids.append(movie.tmdbId)
try:
json.append(movie._get_add_data(options, path=path))
except Exists:
existing_movies.append(movie)
except NotFound:
invalid_ids.append(item)
invalid_ids.append(input_item)
if len(json) > 0:
if per_request is None:
per_request = len(json)
Expand Down
36 changes: 22 additions & 14 deletions arrapi/apis/sonarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,24 @@ def _validate_series_type(self, series_type):
""" Validate Series Type options. """
return self._validate_options("Series Type", series_type, self.series_type_options)

def _validate_tvdb_ids(self, tvdb_ids):
def _validate_tvdb_ids(self, ids):
""" Validate TVDb IDs. """
valid_ids = []
invalid_ids = []
tvdb_sonarr_ids = {m.tvdbId: m for m in self.all_series()}
for tvdb_id in tvdb_ids:
if isinstance(tvdb_id, Series):
tvdb_id = tvdb_id.tvdbId
if tvdb_id in tvdb_sonarr_ids:
valid_ids.append(tvdb_sonarr_ids[tvdb_id].id)
used_ids = []
sonarr_ids = {}
for s in self.all_series():
sonarr_ids[s.tvdbId] = s
sonarr_ids[str(s.tvdbId)] = s
for _id in ids:
if isinstance(_id, Series) and str(_id.tvdbId) not in used_ids:
valid_ids.append(_id.id)
used_ids.append(str(_id.tvdbId))
elif _id in sonarr_ids and str(_id.tvdbId) not in used_ids:
valid_ids.append(sonarr_ids[_id].id)
used_ids.append(str(_id))
else:
invalid_ids.append(tvdb_id)
invalid_ids.append(_id)
return valid_ids, invalid_ids

def respect_list_exclusions_when_adding(self):
Expand Down Expand Up @@ -295,24 +301,26 @@ def add_multiple_series(self, ids: List[Union[Series, int, Tuple[Union[Series, i
series = []
existing_series = []
invalid_ids = []
for item in ids:
path = item[1] if isinstance(item, tuple) else None
item = item[0] if isinstance(item, tuple) else item
used_ids = []
for input_item in ids:
path = input_item[1] if isinstance(input_item, tuple) else None
item = input_item[0] if isinstance(input_item, tuple) else input_item
try:
if isinstance(item, Series):
show = item
else:
if self.exclusions and int(item) in self.exclusions:
if int(item) in used_ids or (self.exclusions and int(item) in self.exclusions):
raise NotFound
show = self.get_series(tvdb_id=item)
if self.exclusions and show.tvdbId in self.exclusions:
if show.tvdbId in used_ids or (self.exclusions and show.tvdbId in self.exclusions):
raise NotFound
used_ids.append(show.tmdbId)
try:
json.append(show._get_add_data(options, path=path))
except Exists:
existing_series.append(show)
except NotFound:
invalid_ids.append(item)
invalid_ids.append(input_item)
if len(json) > 0:
if per_request is None:
per_request = len(json)
Expand Down

0 comments on commit cffa043

Please sign in to comment.