Skip to content

Commit 212bcfa

Browse files
committed
excluded items now are returned with the invalid items
1 parent 7501e1e commit 212bcfa

File tree

6 files changed

+38
-34
lines changed

6 files changed

+38
-34
lines changed

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ To delete multiple Series in Sonarr use |delete_multiple_series|_ with the Serie
140140
not_exist = sonarr.delete_multiple_series(series_ids)
141141
142142
Respect Sonarr List Exclusions
143-
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
143+
----------------------------------------------------------
144144

145145
To respect Sonarr's List Exclusions, before running |sonarr_add|_ or |add_multiple_series|_ you can use |sonarr_exclusions|_ like so.
146146

@@ -245,7 +245,7 @@ To delete multiple Movies in Radarr use |delete_multiple_movies|_ with the Movie
245245
not_exist = radarr.delete_multiple_movies(movie_ids)
246246
247247
Respect Radarr List Exclusions
248-
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
248+
----------------------------------------------------------
249249

250250
To respect Radarr's List Exclusions, before running |radarr_add|_ or |add_multiple_movies|_ you can use |radarr_exclusions|_ like so.
251251

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.2.0
1+
1.2.1

arrapi/apis/radarr.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def add_multiple_movies(self, ids: List[Union[int, str, Movie]],
131131
minimum_availability: str = "announced",
132132
tags: Optional[List[Union[str, int, Tag]]] = None,
133133
per_request: int = None
134-
) -> Tuple[List[Movie], List[Movie], List[int]]:
134+
) -> Tuple[List[Movie], List[Movie], List[Union[int, str, Movie]]]:
135135
""" Adds multiple Movies to Radarr in a single call by their TMDb IDs.
136136
137137
Parameters:
@@ -145,7 +145,7 @@ def add_multiple_movies(self, ids: List[Union[int, str, Movie]],
145145
per_request (int): Number of Movies to add per request.
146146
147147
Returns:
148-
Tuple[List[:class:`~arrapi.objs.reload.Movie`], List[:class:`~arrapi.objs.reload.Movie`], List[int]]: List of Movies that were able to be added, List of Movies already in Radarr, List of TMDb IDs of Movies that could not be found.
148+
Tuple[List[:class:`~arrapi.objs.reload.Movie`], List[:class:`~arrapi.objs.reload.Movie`], List[Union[int, str, Movie]]]: List of Movies that were able to be added, List of Movies already in Radarr, List of Movies that could not be found or were excluded.
149149
150150
Raises:
151151
:class:`~arrapi.exceptions.Invalid`: When one of the options given is invalid.
@@ -155,7 +155,7 @@ def add_multiple_movies(self, ids: List[Union[int, str, Movie]],
155155
json = []
156156
movies = []
157157
existing_movies = []
158-
not_found_ids = []
158+
invalid_ids = []
159159
for item in ids:
160160
try:
161161
if isinstance(item, Movie):
@@ -164,22 +164,22 @@ def add_multiple_movies(self, ids: List[Union[int, str, Movie]],
164164
movie = self.get_movie(imdb_id=item)
165165
else:
166166
if self.exclusions and int(item) in self.exclusions:
167-
continue
167+
raise NotFound
168168
movie = self.get_movie(tmdb_id=item)
169169
if self.exclusions and movie.tmdbId in self.exclusions:
170-
continue
170+
raise NotFound
171171
try:
172172
json.append(movie._get_add_data(options))
173173
except Exists:
174174
existing_movies.append(movie)
175175
except NotFound:
176-
not_found_ids.append(item)
176+
invalid_ids.append(item)
177177
if len(json) > 0:
178178
if per_request is None:
179179
per_request = len(json)
180180
for i in range(0, len(json), per_request):
181181
movies.extend([Movie(self, data=m) for m in self._raw.post_movie_import(json[i:i+per_request])])
182-
return movies, existing_movies, not_found_ids
182+
return movies, existing_movies, invalid_ids
183183

184184
def edit_multiple_movies(self, ids: List[Union[int, str, Movie]],
185185
root_folder: Optional[Union[str, int, RootFolder]] = None,
@@ -190,7 +190,7 @@ def edit_multiple_movies(self, ids: List[Union[int, str, Movie]],
190190
tags: Optional[List[Union[str, int, Tag]]] = None,
191191
apply_tags: str = "add",
192192
per_request: int = None
193-
) -> Tuple[List[Movie], List[int]]:
193+
) -> Tuple[List[Movie], List[Union[int, str, Movie]]]:
194194
""" Edit multiple Movies in Radarr by their TMDb IDs.
195195
196196
Parameters:
@@ -205,7 +205,7 @@ def edit_multiple_movies(self, ids: List[Union[int, str, Movie]],
205205
per_request (int): Number of Movies to edit per request.
206206
207207
Returns:
208-
Tuple[List[:class:`~arrapi.objs.reload.Movie`], List[int]]: List of Movies that were able to be edited, List of TMDb IDs that could not be found in Radarr.
208+
Tuple[List[:class:`~arrapi.objs.reload.Movie`], List[Union[int, str, Movie]]]: List of Movies that were able to be edited, List of Movies that could not be found in Radarr.
209209
210210
Raises:
211211
:class:`~arrapi.exceptions.Invalid`: When one of the options given is invalid.
@@ -227,7 +227,7 @@ def delete_multiple_movies(self, ids: List[Union[int, str, Movie]],
227227
addImportExclusion: bool = False,
228228
deleteFiles: bool = False,
229229
per_request: int = None
230-
) -> List[int]:
230+
) -> List[Union[int, str, Movie]]:
231231
""" Deletes multiple Movies in Radarr by their TMDb IDs.
232232
233233
Parameters:
@@ -237,7 +237,7 @@ def delete_multiple_movies(self, ids: List[Union[int, str, Movie]],
237237
per_request (int): Number of Movies to delete per request.
238238
239239
Returns:
240-
List[int]: List of TMDb IDs that could not be found in Radarr.
240+
List[Union[int, str, Movie]]: List of Movies that could not be found in Radarr.
241241
"""
242242
valid_ids, invalid_ids = self._validate_ids(ids)
243243
if len(valid_ids) > 0:

arrapi/apis/sonarr.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def search_series(self, term: str) -> List[Series]:
137137
"""
138138
return [Series(self, data=d) for d in self._raw.get_series_lookup(term)]
139139

140-
def add_multiple_series(self, tvdb_ids: List[Union[Series, int]],
140+
def add_multiple_series(self, ids: List[Union[Series, int]],
141141
root_folder: Union[str, int, RootFolder],
142142
quality_profile: Union[str, int, QualityProfile],
143143
language_profile: Union[str, int, LanguageProfile],
@@ -148,11 +148,11 @@ def add_multiple_series(self, tvdb_ids: List[Union[Series, int]],
148148
series_type: str = "standard",
149149
tags: Optional[List[Union[str, int, Tag]]] = None,
150150
per_request: int = None
151-
) -> Tuple[List[Series], List[Series], List[int]]:
151+
) -> Tuple[List[Series], List[Series], List[Union[int, Series]]]:
152152
""" Adds multiple Series to Sonarr in a single call by their TVDb IDs.
153153
154154
Parameters:
155-
tvdb_ids (List[Union[int, Series]]): List of TVDB IDs or Series lookups to add.
155+
ids (List[Union[int, Series]]): List of TVDB IDs or Series lookups to add.
156156
root_folder (Union[str, int, RootFolder]): Root Folder for the Series.
157157
quality_profile (Union[str, int, QualityProfile]): Quality Profile for the Series.
158158
language_profile (Union[str, int, LanguageProfile]): Language Profile for the Series.
@@ -165,7 +165,7 @@ def add_multiple_series(self, tvdb_ids: List[Union[Series, int]],
165165
per_request (int): Number of Series to add per request.
166166
167167
Returns:
168-
Tuple[List[:class:`~arrapi.objs.reload.Series`], List[:class:`~arrapi.objs.reload.Series`], List[int]]: List of Series that were able to be added, List of Series already in Sonarr, List of TVDb IDs of Series that could not be found.
168+
Tuple[List[:class:`~arrapi.objs.reload.Series`], List[:class:`~arrapi.objs.reload.Series`], List[Union[int, Series]]]: List of Series that were able to be added, List of Series already in Sonarr, List of Series that could not be found or were excluded.
169169
170170
Raises:
171171
:class:`~arrapi.exceptions.Invalid`: When one of the options given is invalid.
@@ -176,31 +176,31 @@ def add_multiple_series(self, tvdb_ids: List[Union[Series, int]],
176176
json = []
177177
series = []
178178
existing_series = []
179-
not_found_ids = []
180-
for item in tvdb_ids:
179+
invalid_ids = []
180+
for item in ids:
181181
try:
182182
if isinstance(item, Series):
183183
show = item
184184
else:
185185
if self.exclusions and int(item) in self.exclusions:
186-
continue
186+
raise NotFound
187187
show = self.get_series(tvdb_id=item)
188188
if self.exclusions and show.tvdbId in self.exclusions:
189-
continue
189+
raise NotFound
190190
try:
191191
json.append(show._get_add_data(options))
192192
except Exists:
193193
existing_series.append(show)
194194
except NotFound:
195-
not_found_ids.append(item)
195+
invalid_ids.append(item)
196196
if len(json) > 0:
197197
if per_request is None:
198198
per_request = len(json)
199199
for i in range(0, len(json), per_request):
200200
series.extend([Series(self, data=s) for s in self._raw.post_series_import(json[i:i+per_request])])
201-
return series, existing_series, not_found_ids
201+
return series, existing_series, invalid_ids
202202

203-
def edit_multiple_series(self, tvdb_ids: List[Union[Series, int]],
203+
def edit_multiple_series(self, ids: List[Union[Series, int]],
204204
root_folder: Optional[Union[str, int, RootFolder]] = None,
205205
move_files: bool = False,
206206
quality_profile: Optional[Union[str, int, QualityProfile]] = None,
@@ -212,11 +212,11 @@ def edit_multiple_series(self, tvdb_ids: List[Union[Series, int]],
212212
tags: Optional[List[Union[str, int, Tag]]] = None,
213213
apply_tags: str = "add",
214214
per_request: int = None
215-
) -> Tuple[List[Series], List[int]]:
215+
) -> Tuple[List[Series], List[Union[Series, int]]]:
216216
""" Edit multiple Series in Sonarr by their TVDb IDs.
217217
218218
Parameters:
219-
tvdb_ids (List[Union[int, Series]]): List of Series IDs or Series objects you want to edit.
219+
ids (List[Union[int, Series]]): List of Series IDs or Series objects you want to edit.
220220
root_folder (Union[str, int, RootFolder]): Root Folder to change the Series to.
221221
move_files (bool): When changing the root folder do you want to move the files to the new path.
222222
quality_profile (Optional[Union[str, int, QualityProfile]]): Quality Profile to change the Series to.
@@ -230,7 +230,7 @@ def edit_multiple_series(self, tvdb_ids: List[Union[Series, int]],
230230
per_request (int): Number of Series to edit per request.
231231
232232
Returns:
233-
Tuple[List[:class:`~arrapi.objs.reload.Series`], List[int]]: List of TVDb that were able to be edited, List of TVDb IDs that could not be found in Sonarr.
233+
Tuple[List[:class:`~arrapi.objs.reload.Series`], List[Union[Series, int]]]: List of Series that were able to be edited, List of Series that could not be found in Sonarr.
234234
235235
Raises:
236236
:class:`~arrapi.exceptions.Invalid`: When one of the options given is invalid.
@@ -240,7 +240,7 @@ def edit_multiple_series(self, tvdb_ids: List[Union[Series, int]],
240240
monitor=monitor, monitored=monitored, season_folder=season_folder,
241241
series_type=series_type, tags=tags, apply_tags=apply_tags)
242242
series_list = []
243-
valid_ids, invalid_ids = self._validate_tvdb_ids(tvdb_ids)
243+
valid_ids, invalid_ids = self._validate_tvdb_ids(ids)
244244
if len(valid_ids) > 0:
245245
if per_request is None:
246246
per_request = len(valid_ids)
@@ -253,23 +253,23 @@ def edit_multiple_series(self, tvdb_ids: List[Union[Series, int]],
253253
series_list.extend([Series(self, data=s) for s in self._raw.put_series_editor(json)])
254254
return series_list, invalid_ids
255255

256-
def delete_multiple_series(self, tvdb_ids: List[Union[int, Series]],
256+
def delete_multiple_series(self, ids: List[Union[int, Series]],
257257
addImportExclusion: bool = False,
258258
deleteFiles: bool = False,
259259
per_request: int = None
260-
) -> List[int]:
260+
) -> List[Union[Series, int]]:
261261
""" Deletes multiple Series in Sonarr by their TVDb IDs.
262262
263263
Parameters:
264-
tvdb_ids (List[Union[int, Series]]): List of TVDb IDs or Series objects you want to delete.
264+
ids (List[Union[int, Series]]): List of TVDb IDs or Series objects you want to delete.
265265
addImportExclusion (bool): Add Import Exclusion for these TVDb IDs.
266266
deleteFiles (bool): Delete Files for these TVDb IDs.
267267
per_request (int): Number of Series to delete per request.
268268
269269
Returns:
270-
List[int]: List of TVDb IDs that could not be found in Sonarr.
270+
List[Union[Series, int]]: List of Series that could not be found in Sonarr.
271271
"""
272-
valid_ids, invalid_ids = self._validate_tvdb_ids(tvdb_ids)
272+
valid_ids, invalid_ids = self._validate_tvdb_ids(ids)
273273
if len(valid_ids) > 0:
274274
json = {
275275
"deleteFiles": deleteFiles,

tests/test_radarr.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def setUpClass(cls):
2121
has_config = True
2222
if not has_config:
2323
cls.radarr.add_root_folder(f"{cls.root}/")
24+
for movie in cls.radarr.all_movies():
25+
movie.delete()
2426
for tag in cls.radarr.all_tags():
2527
tag.delete()
2628

tests/test_sonarr.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ def setUpClass(cls):
2222
has_config = True
2323
if not has_config:
2424
cls.sonarr.add_root_folder(f"{cls.root}/")
25+
for series in cls.sonarr.all_series():
26+
series.delete()
2527
for tag in cls.sonarr.all_tags():
2628
tag.delete()
2729

0 commit comments

Comments
 (0)