Skip to content

Commit

Permalink
add per_request parameter to the mass change methods
Browse files Browse the repository at this point in the history
  • Loading branch information
meisnate12 committed Aug 26, 2021
1 parent 9fab67b commit d582705
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 20 deletions.
2 changes: 1 addition & 1 deletion arrapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .lidarr import LidarrAPI
from .readarr import ReadarrAPI

__version__ = "1.1.2"
__version__ = "1.1.3"
__author__ = "Nathan Taggart"
__credits__ = "meisnate12"
__package_name__ = "arrapi"
Expand Down
34 changes: 25 additions & 9 deletions arrapi/radarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ def add_multiple_movies(self, ids: List[Union[int, str, Movie]],
monitor: bool = True,
search: bool = True,
minimum_availability: str = "announced",
tags: Optional[List[Union[str, int, Tag]]] = None
tags: Optional[List[Union[str, int, Tag]]] = None,
per_request: int = None
) -> Tuple[List[Movie], List[Movie], List[int]]:
""" Adds multiple Movies to Radarr in a single call by their TMDb IDs.
Expand All @@ -189,6 +190,7 @@ def add_multiple_movies(self, ids: List[Union[int, str, Movie]],
search (bool): Search for the Movies after adding.
minimum_availability (str): Minimum Availability for the Movies. Valid options are announced, inCinemas, released, or preDB.
tags (Optional[List[Union[str, int, Tag]]]): Tags to be added to the Movies.
per_request (int): Number of Movies to add per request.
Returns:
Tuple[List[:class:`~arrapi.objs.Movie`], List[:class:`~arrapi.objs.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.
Expand All @@ -199,8 +201,9 @@ def add_multiple_movies(self, ids: List[Union[int, str, Movie]],
options = self._validate_add_options(root_folder, quality_profile, monitor=monitor, search=search,
minimum_availability=minimum_availability, tags=tags)
json = []
not_found_ids = []
movies = []
existing_movies = []
not_found_ids = []
for item in ids:
try:
if isinstance(item, Movie):
Expand All @@ -215,7 +218,10 @@ def add_multiple_movies(self, ids: List[Union[int, str, Movie]],
existing_movies.append(movie)
except NotFound:
not_found_ids.append(item)
movies = [Movie(self, data=m) for m in self._post_movie_import(json)] if len(json) > 0 else []
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._post_movie_import(json[i:i+per_request])])
return movies, existing_movies, not_found_ids

def edit_multiple_movies(self, ids: List[Union[int, str, Movie]],
Expand All @@ -225,7 +231,8 @@ def edit_multiple_movies(self, ids: List[Union[int, str, Movie]],
monitored: Optional[bool] = None,
minimum_availability: Optional[str] = None,
tags: Optional[List[Union[str, int, Tag]]] = None,
apply_tags: str = "add"
apply_tags: str = "add",
per_request: int = None
) -> Tuple[List[Movie], List[int]]:
""" Edit multiple Movies in Radarr by their TMDb IDs.
Expand All @@ -238,6 +245,7 @@ def edit_multiple_movies(self, ids: List[Union[int, str, Movie]],
minimum_availability (Optional[str]): Minimum Availability to change the Movie to. Valid options are announced, inCinemas, released, or preDB.
tags (Optional[List[Union[str, int, Tag]]]): Tags to be added, replaced, or removed from the Movie.
apply_tags (str): How you want to edit the Tags. Valid options are add, replace, or remove.
per_request (int): Number of Movies to edit per request.
Returns:
Tuple[List[:class:`~arrapi.objs.Movie`], List[int]]: List of Movies that were able to be edited, List of TMDb IDs that could not be found in Radarr.
Expand All @@ -251,30 +259,38 @@ def edit_multiple_movies(self, ids: List[Union[int, str, Movie]],
movie_list = []
valid_ids, invalid_ids = self._validate_ids(ids)
if len(valid_ids) > 0:
json["movieIds"] = valid_ids
movie_list = [Movie(self, data=m) for m in self._put_movie_editor(json)]
if per_request is None:
per_request = len(valid_ids)
for i in range(0, len(valid_ids), per_request):
json["movieIds"] = valid_ids[i:i+per_request]
movie_list = [Movie(self, data=m) for m in self._put_movie_editor(json)]
return movie_list, invalid_ids

def delete_multiple_movies(self, ids: List[Union[int, str, Movie]],
addImportExclusion: bool = False,
deleteFiles: bool = False
deleteFiles: bool = False,
per_request: int = None
) -> List[int]:
""" Deletes multiple Movies in Radarr by their TMDb IDs.
Parameters:
ids (List[Union[int, str, Movie]]): List of TMDb IDs, IMDb IDs, or Movie objects you want to delete.
addImportExclusion (bool): Add Import Exclusion for these TMDb IDs.
deleteFiles (bool): Delete Files for these TMDb IDs.
per_request (int): Number of Movies to delete per request.
Returns:
List[int]: List of TMDb IDs that could not be found in Radarr.
"""
valid_ids, invalid_ids = self._validate_ids(ids)
if len(valid_ids) > 0:
json = {
"movieIds": valid_ids,
"deleteFiles": deleteFiles,
"addImportExclusion": addImportExclusion
}
self._delete_movie_editor(json)
if per_request is None:
per_request = len(valid_ids)
for i in range(0, len(valid_ids), per_request):
json["movieIds"] = valid_ids[i:i+per_request]
self._delete_movie_editor(json)
return invalid_ids
38 changes: 28 additions & 10 deletions arrapi/sonarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ def add_multiple_series(self, tvdb_ids: List[Union[Series, int]],
search: bool = True,
unmet_search: bool = True,
series_type: str = "standard",
tags: Optional[List[Union[str, int, Tag]]] = None
tags: Optional[List[Union[str, int, Tag]]] = None,
per_request: int = None
) -> Tuple[List[Series], List[Series], List[int]]:
""" Adds multiple Series to Sonarr in a single call by their TVDb IDs.
Expand All @@ -220,6 +221,7 @@ def add_multiple_series(self, tvdb_ids: List[Union[Series, int]],
unmet_search (bool): Start search for cutoff unmet episodes of the Series after adding.
series_type (str): Series Type for the Series. Valid options are ``standard``, ``daily``, or ``anime``.
tags (Optional[List[Union[str, int, Tag]]]): Tags to be added to the Series.
per_request (int): Number of Series to add per request.
Returns:
Tuple[List[:class:`~arrapi.objs.Series`], List[:class:`~arrapi.objs.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.
Expand All @@ -231,8 +233,9 @@ def add_multiple_series(self, tvdb_ids: List[Union[Series, int]],
season_folder=season_folder, search=search, unmet_search=unmet_search,
series_type=series_type, tags=tags)
json = []
not_found_ids = []
series = []
existing_series = []
not_found_ids = []
for tvdb_id in tvdb_ids:
try:
series = tvdb_id if isinstance(tvdb_id, Series) else self.get_series(tvdb_id=tvdb_id)
Expand All @@ -242,7 +245,10 @@ def add_multiple_series(self, tvdb_ids: List[Union[Series, int]],
existing_series.append(series)
except NotFound:
not_found_ids.append(tvdb_id)
series = [Series(self, data=s) for s in self._post_series_import(json)] if len(json) > 0 else []
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._post_series_import(json[i:i+per_request])])
return series, existing_series, not_found_ids

def edit_multiple_series(self, tvdb_ids: List[Union[Series, int]],
Expand All @@ -255,7 +261,8 @@ def edit_multiple_series(self, tvdb_ids: List[Union[Series, int]],
season_folder: Optional[bool] = None,
series_type: Optional[str] = None,
tags: Optional[List[Union[str, int, Tag]]] = None,
apply_tags: str = "add"
apply_tags: str = "add",
per_request: int = None
) -> Tuple[List[Series], List[int]]:
""" Edit multiple Series in Sonarr by their TVDb IDs.
Expand All @@ -271,6 +278,7 @@ def edit_multiple_series(self, tvdb_ids: List[Union[Series, int]],
series_type (Optional[str]): Series Type to change the Series to. Valid options are standard, daily, or anime.
tags (Optional[List[Union[str, int, Tag]]]): Tags to be added, replaced, or removed from the Series.
apply_tags (str): How you want to edit the Tags. Valid options are add, replace, or remove.
per_request (int): Number of Series to edit per request.
Returns:
Tuple[List[:class:`~arrapi.objs.Series`], List[int]]: List of TVDb that were able to be edited, List of TVDb IDs that could not be found in Sonarr.
Expand All @@ -285,34 +293,44 @@ def edit_multiple_series(self, tvdb_ids: List[Union[Series, int]],
series_list = []
valid_ids, invalid_ids = self._validate_tvdb_ids(tvdb_ids)
if len(valid_ids) > 0:
if per_request is None:
per_request = len(valid_ids)
if "monitor" in json:
self._edit_series_monitoring(valid_ids, json.pop("monitor"))
json["seriesIds"] = valid_ids
series_list = [Series(self, data=s) for s in self._put_series_editor(json)]
json_monitor = json.pop("monitor")
for i in range(0, len(valid_ids), per_request):
self._edit_series_monitoring(valid_ids[i:i+per_request], json_monitor)
for i in range(0, len(valid_ids), per_request):
json["seriesIds"] = valid_ids[i:i+per_request]
series_list.extend([Series(self, data=s) for s in self._put_series_editor(json)])
return series_list, invalid_ids

def delete_multiple_series(self, tvdb_ids: List[Union[int, Series]],
addImportExclusion: bool = False,
deleteFiles: bool = False
deleteFiles: bool = False,
per_request: int = None
) -> List[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.
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.
"""
valid_ids, invalid_ids = self._validate_tvdb_ids(tvdb_ids)
if len(valid_ids) > 0:
json = {
"seriesIds": valid_ids,
"deleteFiles": deleteFiles,
"addImportExclusion": addImportExclusion
}
self._delete_series_editor(json)
if per_request is None:
per_request = len(valid_ids)
for i in range(0, len(valid_ids), per_request):
json["seriesIds"] = valid_ids[i:i+per_request]
self._delete_series_editor(json)
return invalid_ids

def _get_languageProfile(self):
Expand Down

0 comments on commit d582705

Please sign in to comment.