Skip to content

Commit

Permalink
add helper methods
Browse files Browse the repository at this point in the history
  • Loading branch information
meisnate12 committed Nov 23, 2021
1 parent 84c06ae commit 49c650c
Show file tree
Hide file tree
Showing 4 changed files with 225 additions and 7 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.3
1.2.4
106 changes: 105 additions & 1 deletion arrapi/apis/radarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,111 @@ def search_movies(self, term: str) -> List[Movie]:
"""
return [Movie(self, data=d) for d in self._raw.get_movie_lookup(term)]

def add_multiple_movies(self, ids: List[Union[int, str, Movie]],
def add_movie(
self,
root_folder: Union[str, int, "RootFolder"],
quality_profile: Union[str, int, "QualityProfile"],
movie_id: Optional[int] = None,
tmdb_id: Optional[int] = None,
imdb_id: Optional[str] = None,
monitor: bool = True,
search: bool = True,
minimum_availability: str = "announced",
tags: Optional[List[Union[str, int, Tag]]] = None
) -> Movie:
""" Gets a :class:`~arrapi.objs.reload.Movie` by one of the IDs and adds it to Radarr.
Parameters:
root_folder (Union[str, int, RootFolder]): Root Folder for the Movie.
quality_profile (Union[str, int, QualityProfile]): Quality Profile for the Movie.
movie_id (Optional[int]): Search by Radarr Movie ID.
tmdb_id (Optional[int]): Search by TMDb ID.
imdb_id (Optional[int]): Search by IMDb ID.
monitor (bool): Monitor the Movie.
search (bool): Search for the Movie after adding.
minimum_availability (str): Minimum Availability for the Movie. Valid options are announced, inCinemas, released, or preDB.
tags (Optional[List[Union[str, int, Tag]]]): Tags to be added to the Movie.
Returns:
:class:`~arrapi.objs.reload.Movie`: Movie for the ID given.
Raises:
:class:`ValueError`: When no ID is given.
:class:`~arrapi.exceptions.NotFound`: When there's no movie with that ID.
:class:`~arrapi.exceptions.Invalid`: When one of the options given is invalid.
:class:`~arrapi.exceptions.Exists`: When the Movie already Exists in Radarr.
"""
movie = self.get_movie(movie_id=movie_id, tmdb_id=tmdb_id, imdb_id=imdb_id)
movie.add(root_folder, quality_profile, monitor=monitor, search=search,
minimum_availability=minimum_availability, tags=tags)
return movie

def edit_movie(
self,
movie_id: Optional[int] = None,
tmdb_id: Optional[int] = None,
imdb_id: Optional[str] = None,
path: Optional[str] = None,
move_files: bool = False,
quality_profile: Optional[Union[str, int, "QualityProfile"]] = None,
monitored: Optional[bool] = None,
minimum_availability: Optional[str] = None,
tags: Optional[List[Union[str, int, Tag]]] = None,
apply_tags: str = "add"
) -> Movie:
""" Gets a :class:`~arrapi.objs.reload.Movie` by one of the IDs and edits it in Radarr.
Parameters:
movie_id (Optional[int]): Search by Radarr Movie ID.
tmdb_id (Optional[int]): Search by TMDb ID.
imdb_id (Optional[int]): Search by IMDb ID.
path (Optional[str]): Path to change the Movie to.
move_files (bool): When changing the path do you want to move the files to the new path.
quality_profile (Optional[Union[str, int, QualityProfile]]): Quality Profile to change the Movie to.
monitored (Optional[bool]): Monitor the 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.
Raises:
:class:`ValueError`: When no ID is given or when theres no options given.
:class:`~arrapi.exceptions.Invalid`: When one of the options given is invalid.
:class:`~arrapi.exceptions.NotFound`: When there's no movie with that ID or when the Movie hasn't been added to Radarr.
"""
movie = self.get_movie(movie_id=movie_id, tmdb_id=tmdb_id, imdb_id=imdb_id)
movie.edit(path=path, move_files=move_files, quality_profile=quality_profile, monitored=monitored,
minimum_availability=minimum_availability, tags=tags, apply_tags=apply_tags)
return movie

def delete_movie(
self,
movie_id: Optional[int] = None,
tmdb_id: Optional[int] = None,
imdb_id: Optional[str] = None,
addImportExclusion: bool = False,
deleteFiles: bool = False
) -> Movie:
""" Gets a :class:`~arrapi.objs.reload.Movie` by one of the IDs and deletes it from Radarr.
Parameters:
movie_id (Optional[int]): Search by Radarr Movie ID.
tmdb_id (Optional[int]): Search by TMDb ID.
imdb_id (Optional[int]): Search by IMDb ID.
addImportExclusion (bool): Add Import Exclusion for this Movie.
deleteFiles (bool): Delete Files for this Movie.
Returns:
:class:`~arrapi.objs.reload.Movie`: Movie for the ID given.
Raises:
:class:`ValueError`: When no ID is given.
:class:`~arrapi.exceptions.NotFound`: When there's no movie with that ID or when the Movie hasn't been added to Radarr.
"""
movie = self.get_movie(movie_id=movie_id, tmdb_id=tmdb_id, imdb_id=imdb_id)
movie.delete(addImportExclusion=addImportExclusion, deleteFiles=deleteFiles)
return movie

def add_multiple_movies(self, ids: List[Union[int, str, Movie, Tuple[Union[int, str, Movie], str]]],
root_folder: Union[str, int, RootFolder],
quality_profile: Union[str, int, QualityProfile],
monitor: bool = True,
Expand Down
116 changes: 115 additions & 1 deletion arrapi/apis/sonarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,121 @@ 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, ids: List[Union[Series, int]],
def add_series(
self,
root_folder: Union[str, int, "RootFolder"],
quality_profile: Union[str, int, "QualityProfile"],
language_profile: Union[str, int, "LanguageProfile"],
series_id: Optional[int] = None,
tvdb_id: Optional[int] = None,
monitor: str = "all",
season_folder: bool = True,
search: bool = True,
unmet_search: bool = True,
series_type: str = "standard",
tags: Optional[List[Union[str, int, Tag]]] = None
) -> Series:
""" Gets a :class:`~arrapi.objs.reload.Series` by one of the IDs and adds it to Sonarr.
Parameters:
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.
series_id (Optional[int]): Search by Sonarr Series ID.
tvdb_id (Optional[int]): Search by TVDb ID.
monitor (bool): How to monitor the Series. Valid options are all, future, missing, existing, pilot, firstSeason, latestSeason, or none.
season_folder (bool): Use Season Folders for the Series.
search (bool): Start search for missing episodes of the Series after adding.
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.
Returns:
:class:`~arrapi.objs.reload.Series`: Series for the ID given.
Raises:
:class:`ValueError`: When no ID is given.
:class:`~arrapi.exceptions.NotFound`: When there's no series with that ID.
:class:`~arrapi.exceptions.Invalid`: When one of the options given is invalid.
:class:`~arrapi.exceptions.Exists`: When the Series already Exists in Sonarr.
"""
series = self.get_series(series_id=series_id, tvdb_id=tvdb_id)
series.add(root_folder, quality_profile, language_profile, monitor=monitor, season_folder=season_folder,
search=search, unmet_search=unmet_search, series_type=series_type, tags=tags)
return series

def edit_series(
self,
series_id: Optional[int] = None,
tvdb_id: Optional[int] = None,
path: Optional[str] = None,
move_files: bool = False,
quality_profile: Optional[Union[str, int, "QualityProfile"]] = None,
language_profile: Optional[Union[str, int, "LanguageProfile"]] = None,
monitor: Optional[str] = None,
monitored: Optional[bool] = None,
season_folder: Optional[bool] = None,
series_type: Optional[str] = None,
tags: Optional[List[Union[str, int, Tag]]] = None,
apply_tags: str = "add"
) -> Series:
""" Gets a :class:`~arrapi.objs.reload.Series` by one of the IDs and edits it in Sonarr.
Parameters:
series_id (Optional[int]): Search by Sonarr Series ID.
tvdb_id (Optional[int]): Search by TVDb ID.
path (Optional[str]): Path to change the Series to.
move_files (bool): When changing the path 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.
language_profile (Optional[Union[str, int, LanguageProfile]]): Language Profile to change the Series to.
monitor (Optional[str]): How you want the Series monitored. Valid options are all, future, missing, existing, pilot, firstSeason, latestSeason, or none.
monitored (Optional[bool]): Monitor the Series.
season_folder (Optional[bool]): Use Season Folders for the Series.
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.
Returns:
:class:`~arrapi.objs.reload.Series`: Series for the ID given.
Raises:
:class:`ValueError`: When no ID is given or when theres no options given.
:class:`~arrapi.exceptions.Invalid`: When one of the options given is invalid.
:class:`~arrapi.exceptions.NotFound`: When there's no series with that ID or when the Series hasn't been added to Sonarr.
"""
series = self.get_series(series_id=series_id, tvdb_id=tvdb_id)
series.edit(path=path, move_files=move_files, quality_profile=quality_profile,
language_profile=language_profile, monitor=monitor, monitored=monitored,
season_folder=season_folder, series_type=series_type, tags=tags, apply_tags=apply_tags)
return series

def delete_series(
self,
series_id: Optional[int] = None,
tvdb_id: Optional[int] = None,
addImportExclusion: bool = False,
deleteFiles: bool = False
) -> Series:
""" Gets a :class:`~arrapi.objs.reload.Series` by one of the IDs and deletes it from Sonarr.
Parameters:
series_id (Optional[int]): Search by Sonarr Series ID.
tvdb_id (Optional[int]): Search by TVDb ID.
addImportExclusion (bool): Add Import Exclusion for this Series.
deleteFiles (bool): Delete Files for this Series.
Returns:
:class:`~arrapi.objs.reload.Series`: Series for the ID given.
Raises:
:class:`ValueError`: When no ID is given.
:class:`~arrapi.exceptions.NotFound`: When there's no series with that ID or when the Series hasn't been added to Sonarr.
"""
series = self.get_series(series_id=series_id, tvdb_id=tvdb_id)
series.delete(addImportExclusion=addImportExclusion, deleteFiles=deleteFiles)
return series

def add_multiple_series(self, ids: List[Union[Series, int, Tuple[Union[Series, int], str]]],
root_folder: Union[str, int, RootFolder],
quality_profile: Union[str, int, QualityProfile],
language_profile: Union[str, int, LanguageProfile],
Expand Down
8 changes: 4 additions & 4 deletions arrapi/objs/reload.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def edit(self,
Raises:
:class:`ValueError`: When theres no options given.
:class:`~arrapi.exceptions.Invalid`: When one of the options given is invalid.
:class:`~arrapi.exceptions.NotFound`: When the Movie isn't found in Radarr and must be added to Radarr before editing.
:class:`~arrapi.exceptions.NotFound`: When the Movie hasn't been added to Radarr.
"""
if not self.id:
raise NotFound(f"{self.title} not found Radarr, it must be added before editing")
Expand Down Expand Up @@ -363,7 +363,7 @@ def delete(self, addImportExclusion: bool = False, deleteFiles: bool = False) ->
deleteFiles (bool): Delete Files for this Movie.
Raises:
:class:`~arrapi.exceptions.NotFound`: When the Movie isn't found in Radarr.
:class:`~arrapi.exceptions.NotFound`: When the Movie hasn't been added to Radarr.
"""
if not self.id:
raise NotFound(f"{self.title} not found Radarr, it must be added before deleting")
Expand Down Expand Up @@ -594,7 +594,7 @@ def edit(self,
Raises:
:class:`ValueError`: When theres no options given.
:class:`~arrapi.exceptions.Invalid`: When one of the options given is invalid.
:class:`~arrapi.exceptions.NotFound`: When the Series isn't found in Sonarr and must be added to Sonarr before editing.
:class:`~arrapi.exceptions.NotFound`: When the Series hasn't been added to Sonarr.
"""
if not self.id:
raise NotFound(f"{self.title} not found in Sonarr, it must be added before editing")
Expand Down Expand Up @@ -628,7 +628,7 @@ def delete(self, addImportExclusion: bool = False, deleteFiles: bool = False) ->
deleteFiles (bool): Delete Files for this Series.
Raises:
:class:`~arrapi.exceptions.NotFound`: When the Series isn't found in Sonarr.
:class:`~arrapi.exceptions.NotFound`: When the Series hasn't been added to Sonarr.
"""
if not self.id:
raise NotFound(f"{self.title} not found in Sonarr, it must be added before deleting")
Expand Down

0 comments on commit 49c650c

Please sign in to comment.