Skip to content

Commit

Permalink
excluded items now are returned with the invalid items
Browse files Browse the repository at this point in the history
  • Loading branch information
meisnate12 committed Nov 12, 2021
1 parent 7501e1e commit 212bcfa
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 34 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ To delete multiple Series in Sonarr use |delete_multiple_series|_ with the Serie
not_exist = sonarr.delete_multiple_series(series_ids)
Respect Sonarr List Exclusions
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
----------------------------------------------------------

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

Expand Down Expand Up @@ -245,7 +245,7 @@ To delete multiple Movies in Radarr use |delete_multiple_movies|_ with the Movie
not_exist = radarr.delete_multiple_movies(movie_ids)
Respect Radarr List Exclusions
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
----------------------------------------------------------

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

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.0
1.2.1
22 changes: 11 additions & 11 deletions arrapi/apis/radarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def add_multiple_movies(self, ids: List[Union[int, str, Movie]],
minimum_availability: str = "announced",
tags: Optional[List[Union[str, int, Tag]]] = None,
per_request: int = None
) -> Tuple[List[Movie], List[Movie], List[int]]:
) -> Tuple[List[Movie], List[Movie], List[Union[int, str, Movie]]]:
""" Adds multiple Movies to Radarr in a single call by their TMDb IDs.
Parameters:
Expand All @@ -145,7 +145,7 @@ def add_multiple_movies(self, ids: List[Union[int, str, Movie]],
per_request (int): Number of Movies to add per request.
Returns:
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.
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.
Raises:
:class:`~arrapi.exceptions.Invalid`: When one of the options given is invalid.
Expand All @@ -155,7 +155,7 @@ def add_multiple_movies(self, ids: List[Union[int, str, Movie]],
json = []
movies = []
existing_movies = []
not_found_ids = []
invalid_ids = []
for item in ids:
try:
if isinstance(item, Movie):
Expand All @@ -164,22 +164,22 @@ def add_multiple_movies(self, ids: List[Union[int, str, Movie]],
movie = self.get_movie(imdb_id=item)
else:
if self.exclusions and int(item) in self.exclusions:
continue
raise NotFound
movie = self.get_movie(tmdb_id=item)
if self.exclusions and movie.tmdbId in self.exclusions:
continue
raise NotFound
try:
json.append(movie._get_add_data(options))
except Exists:
existing_movies.append(movie)
except NotFound:
not_found_ids.append(item)
invalid_ids.append(item)
if len(json) > 0:
if per_request is None:
per_request = len(json)
for i in range(0, len(json), per_request):
movies.extend([Movie(self, data=m) for m in self._raw.post_movie_import(json[i:i+per_request])])
return movies, existing_movies, not_found_ids
return movies, existing_movies, invalid_ids

def edit_multiple_movies(self, ids: List[Union[int, str, Movie]],
root_folder: Optional[Union[str, int, RootFolder]] = None,
Expand All @@ -190,7 +190,7 @@ def edit_multiple_movies(self, ids: List[Union[int, str, Movie]],
tags: Optional[List[Union[str, int, Tag]]] = None,
apply_tags: str = "add",
per_request: int = None
) -> Tuple[List[Movie], List[int]]:
) -> Tuple[List[Movie], List[Union[int, str, Movie]]]:
""" Edit multiple Movies in Radarr by their TMDb IDs.
Parameters:
Expand All @@ -205,7 +205,7 @@ def edit_multiple_movies(self, ids: List[Union[int, str, Movie]],
per_request (int): Number of Movies to edit per request.
Returns:
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.
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.
Raises:
:class:`~arrapi.exceptions.Invalid`: When one of the options given is invalid.
Expand All @@ -227,7 +227,7 @@ def delete_multiple_movies(self, ids: List[Union[int, str, Movie]],
addImportExclusion: bool = False,
deleteFiles: bool = False,
per_request: int = None
) -> List[int]:
) -> List[Union[int, str, Movie]]:
""" Deletes multiple Movies in Radarr by their TMDb IDs.
Parameters:
Expand All @@ -237,7 +237,7 @@ def delete_multiple_movies(self, ids: List[Union[int, str, Movie]],
per_request (int): Number of Movies to delete per request.
Returns:
List[int]: List of TMDb IDs that could not be found in Radarr.
List[Union[int, str, Movie]]: List of Movies that could not be found in Radarr.
"""
valid_ids, invalid_ids = self._validate_ids(ids)
if len(valid_ids) > 0:
Expand Down
40 changes: 20 additions & 20 deletions arrapi/apis/sonarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def search_series(self, term: str) -> List[Series]:
"""
return [Series(self, data=d) for d in self._raw.get_series_lookup(term)]

def add_multiple_series(self, tvdb_ids: List[Union[Series, int]],
def add_multiple_series(self, ids: List[Union[Series, int]],
root_folder: Union[str, int, RootFolder],
quality_profile: Union[str, int, QualityProfile],
language_profile: Union[str, int, LanguageProfile],
Expand All @@ -148,11 +148,11 @@ def add_multiple_series(self, tvdb_ids: List[Union[Series, int]],
series_type: str = "standard",
tags: Optional[List[Union[str, int, Tag]]] = None,
per_request: int = None
) -> Tuple[List[Series], List[Series], List[int]]:
) -> Tuple[List[Series], List[Series], List[Union[int, Series]]]:
""" Adds multiple Series to Sonarr in a single call by their TVDb IDs.
Parameters:
tvdb_ids (List[Union[int, Series]]): List of TVDB IDs or Series lookups to add.
ids (List[Union[int, Series]]): List of TVDB IDs or Series lookups to add.
root_folder (Union[str, int, RootFolder]): Root Folder for the Series.
quality_profile (Union[str, int, QualityProfile]): Quality Profile for the Series.
language_profile (Union[str, int, LanguageProfile]): Language Profile for the Series.
Expand All @@ -165,7 +165,7 @@ def add_multiple_series(self, tvdb_ids: List[Union[Series, int]],
per_request (int): Number of Series to add per request.
Returns:
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.
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.
Raises:
:class:`~arrapi.exceptions.Invalid`: When one of the options given is invalid.
Expand All @@ -176,31 +176,31 @@ def add_multiple_series(self, tvdb_ids: List[Union[Series, int]],
json = []
series = []
existing_series = []
not_found_ids = []
for item in tvdb_ids:
invalid_ids = []
for item in ids:
try:
if isinstance(item, Series):
show = item
else:
if self.exclusions and int(item) in self.exclusions:
continue
raise NotFound
show = self.get_series(tvdb_id=item)
if self.exclusions and show.tvdbId in self.exclusions:
continue
raise NotFound
try:
json.append(show._get_add_data(options))
except Exists:
existing_series.append(show)
except NotFound:
not_found_ids.append(item)
invalid_ids.append(item)
if len(json) > 0:
if per_request is None:
per_request = len(json)
for i in range(0, len(json), per_request):
series.extend([Series(self, data=s) for s in self._raw.post_series_import(json[i:i+per_request])])
return series, existing_series, not_found_ids
return series, existing_series, invalid_ids

def edit_multiple_series(self, tvdb_ids: List[Union[Series, int]],
def edit_multiple_series(self, ids: List[Union[Series, int]],
root_folder: Optional[Union[str, int, RootFolder]] = None,
move_files: bool = False,
quality_profile: Optional[Union[str, int, QualityProfile]] = None,
Expand All @@ -212,11 +212,11 @@ def edit_multiple_series(self, tvdb_ids: List[Union[Series, int]],
tags: Optional[List[Union[str, int, Tag]]] = None,
apply_tags: str = "add",
per_request: int = None
) -> Tuple[List[Series], List[int]]:
) -> Tuple[List[Series], List[Union[Series, int]]]:
""" Edit multiple Series in Sonarr by their TVDb IDs.
Parameters:
tvdb_ids (List[Union[int, Series]]): List of Series IDs or Series objects you want to edit.
ids (List[Union[int, Series]]): List of Series IDs or Series objects you want to edit.
root_folder (Union[str, int, RootFolder]): Root Folder to change the Series to.
move_files (bool): When changing the root folder do you want to move the files to the new path.
quality_profile (Optional[Union[str, int, QualityProfile]]): Quality Profile to change the Series to.
Expand All @@ -230,7 +230,7 @@ def edit_multiple_series(self, tvdb_ids: List[Union[Series, int]],
per_request (int): Number of Series to edit per request.
Returns:
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.
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.
Raises:
:class:`~arrapi.exceptions.Invalid`: When one of the options given is invalid.
Expand All @@ -240,7 +240,7 @@ def edit_multiple_series(self, tvdb_ids: List[Union[Series, int]],
monitor=monitor, monitored=monitored, season_folder=season_folder,
series_type=series_type, tags=tags, apply_tags=apply_tags)
series_list = []
valid_ids, invalid_ids = self._validate_tvdb_ids(tvdb_ids)
valid_ids, invalid_ids = self._validate_tvdb_ids(ids)
if len(valid_ids) > 0:
if per_request is None:
per_request = len(valid_ids)
Expand All @@ -253,23 +253,23 @@ def edit_multiple_series(self, tvdb_ids: List[Union[Series, int]],
series_list.extend([Series(self, data=s) for s in self._raw.put_series_editor(json)])
return series_list, invalid_ids

def delete_multiple_series(self, tvdb_ids: List[Union[int, Series]],
def delete_multiple_series(self, ids: List[Union[int, Series]],
addImportExclusion: bool = False,
deleteFiles: bool = False,
per_request: int = None
) -> List[int]:
) -> List[Union[Series, int]]:
""" Deletes multiple Series in Sonarr by their TVDb IDs.
Parameters:
tvdb_ids (List[Union[int, Series]]): List of TVDb IDs or Series objects you want to delete.
ids (List[Union[int, Series]]): List of TVDb IDs or Series objects you want to delete.
addImportExclusion (bool): Add Import Exclusion for these TVDb IDs.
deleteFiles (bool): Delete Files for these TVDb IDs.
per_request (int): Number of Series to delete per request.
Returns:
List[int]: List of TVDb IDs that could not be found in Sonarr.
List[Union[Series, int]]: List of Series that could not be found in Sonarr.
"""
valid_ids, invalid_ids = self._validate_tvdb_ids(tvdb_ids)
valid_ids, invalid_ids = self._validate_tvdb_ids(ids)
if len(valid_ids) > 0:
json = {
"deleteFiles": deleteFiles,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_radarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def setUpClass(cls):
has_config = True
if not has_config:
cls.radarr.add_root_folder(f"{cls.root}/")
for movie in cls.radarr.all_movies():
movie.delete()
for tag in cls.radarr.all_tags():
tag.delete()

Expand Down
2 changes: 2 additions & 0 deletions tests/test_sonarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def setUpClass(cls):
has_config = True
if not has_config:
cls.sonarr.add_root_folder(f"{cls.root}/")
for series in cls.sonarr.all_series():
series.delete()
for tag in cls.sonarr.all_tags():
tag.delete()

Expand Down

0 comments on commit 212bcfa

Please sign in to comment.