pycliarr.api.sonarr module

class pycliarr.api.sonarr.SonarrCli(*args, default_root_folder_id: int = 0, **kwargs)[source]

Bases: pycliarr.api.base_media.BaseCliMediaApi

Sonarr api client.

API reference:
https://github.com/Sonarr/Sonarr/wiki/API https://pub.dev/packages/sonarr

Note

Not all commands are implemented. Some commands available are implemented in BaseCliMediaApi: * get_calendar * get_command * get_quality_profiles * rename_files * get_disk_space * get_system_status * get_queue * delete_queue

Todo

  • get_wanted
  • get_logs
  • get_backup
  • get_episode_files
  • delete_episode_files
  • search_selected
add_serie(quality: int, tvdb_id: Optional[int] = None, serie_info: Optional[pycliarr.api.sonarr.SonarrSerieItem] = None, monitored_seasons: List[int] = [], monitored: bool = True, search: bool = True, season_folder: bool = True, path: Optional[str] = None, root_id: int = 0, language: int = 1) → Union[Dict[str, Any], List[Dict[str, Any]]][source]

addMovie adds a new serie to collection.

The serie description serie_info must be specified. If the IMDB or TMDB id is provided instead, it will be used to fetch the required serie description from TMDB.

Parameters:
  • quality – Quality profile to use, as retrieved by get_quality_profiles()
  • tvdb_id (Optional[int]) – TVDB id of the serie to add
  • serie_info (Optional[RadarrserieItem]) – Description of the serie to add
  • monitored_seasons – Optional list of seasons numbers to monitor. Latest season only by default.
  • monitored (bool) – Whether to monitor the serie. Default is True
  • search (bool) – Whether to search for the serie once added. Default is True
  • season_folder (bool) – If True (default), create a folder for each season.
  • path (Optional[str]) – Specify the path awhere the movie should be stored. Default is root/<serie name>.
  • root_id (Optional[int]) – Specify the root folder to use. Ignored if a path is specified. Default is root[0].
  • language (int) – Specify the language to use. Default is the first enabled (1)
Returns:

json response

Note: To further customize the parameters of the serie to add, manually look it up .. rubric:: Example

info = sonarr.lookup_serie(tvdb_id=tvdb_id) info[“seasons”] = {“seasonNumber”: 1, “monitored”: False} sonarr.add_serie(quality: 1, serie_info: info)

api_url_episode = '/api/v3/episode'
api_url_episodefile = '/api/v3/episodefile'
api_url_item = '/api/v3/series'
api_url_itemlookup = '/api/v3/series/lookup'
api_url_wanted_missing = '/api/wanted/missing'
build_serie_path(serie_info: pycliarr.api.sonarr.SonarrSerieItem, root_folder_id: int = 0) → pathlib.Path[source]

Build a serie folder path using the root folder specified. :param serie_info: :type serie_info: SonarrSerieItem :param root_folder_id: Id of the root folder (can be retrieved with get_root_folder()). :type root_folder_id: int :param If the id is not found or not specified, the first root folder in the list is used.:

Returns: Full path of the serie in the format <root path>/<serie name>

create_exclusion(title: str, tvdb_id: int) → Union[Dict[str, Any], List[Dict[str, Any]]][source]

Create the specified exclusions

Parameters:item_id (int) – id of the exclusions to create
Returns:json response
delete_episode_file(episode_id: int) → Union[Dict[str, Any], List[Dict[str, Any]]][source]

Delete the given episode file

Parameters:episode_id (int) – ID of the episode to delete
Returns:json response
delete_serie(serie_id: int, delete_files: bool = True, add_exclusion: bool = False) → Union[Dict[str, Any], List[Dict[str, Any]]][source]

Delete the serie with the given ID

Parameters:
  • serie_id (int) – Serie to delete
  • delete_files (bool) – Optional. Also delete files. Default is True
  • add_exclusion – Optionally exclude the serie from further tvdb auto add
Returns:

json response

edit_serie(serie_info: pycliarr.api.sonarr.SonarrSerieItem) → Union[Dict[str, Any], List[Dict[str, Any]]][source]

Edit a serie from the collection.

The serie description movie_info must be specified, usually by getting the information from get_serie()

Parameters:serie_info (Optional[RadarrMovieItem]) – Description of the movie to edit
Returns:json response
get_episode(serie_id: Optional[int] = None, episode_id: Optional[int] = None) → Union[Dict[str, Any], List[Dict[str, Any]], List[Union[Dict[str, Any], List[Dict[str, Any]]]]][source]

Returns specified episode or all for the given serie

Parameters:
  • serie_id (int) – ID of the serie to get all episodes from
  • episode_id (int) – ID of a specific episode to get
Returns:

json response

get_episode_file(serie_id: Optional[int] = None, episode_id: Optional[int] = None) → Union[Dict[str, Any], List[Dict[str, Any]], List[Union[Dict[str, Any], List[Dict[str, Any]]]]][source]

Returns specified episode file or all for the given serie

Parameters:
  • serie_id (int) – ID of the serie to get all episodes files from
  • episode_id (int) – ID of a specific episode file to get
Returns:

json response

get_queue(page: int = 1, sort_key: str = 'progress', page_size: int = 20, sort_dir: str = 'ascending', include_unknown: bool = True) → Union[Dict[str, Any], List[Dict[str, Any]]][source]

Get queue info (downloading/completed, ok/warning) as json

Parameters:
  • page (int) - 1-indexed (1 default) –
  • sort_key (string) –
  • page_size (int) – 10
  • sort_dir (string) – asc
  • options (Dict[str, Any]={}) – Optional additional options
get_serie(serie_id: Optional[int] = None) → Union[pycliarr.api.sonarr.SonarrSerieItem, List[pycliarr.api.sonarr.SonarrSerieItem]][source]

Get specified serie, or all if no id provided from server collection.

Parameters:serie_id (Optional[int]) –
Returns:SonarrSerieItem if a serie id is specified, or a list of SonarrSerieItem
lookup_serie(term: Optional[str] = None, tvdb_id: Optional[int] = None) → Union[pycliarr.api.sonarr.SonarrSerieItem, List[pycliarr.api.sonarr.SonarrSerieItem], None][source]

Search for a serie based on keyword, or tvdb id.

If tvdb id is provided, it will be used. If not, the keywords will be used. One of term, or tvdb_id must be specified.

Parameters:
  • term (Optional[str]) – Keywords to seach for
  • tvdb_id (Optional[str]) – TVDB serie id
Returns:

json response

Search for missing episodes. :returns: json response

refresh_serie(serie_id: Optional[int] = None) → Union[Dict[str, Any], List[Dict[str, Any]]][source]

Refresh serie information and rescan disk.

Parameters:serie_id (Optional[int]) – serie to refresh, if not set all series will be refreshed and scanned
Returns:json response
rescan_serie(serie_id: Optional[int] = None) → Union[Dict[str, Any], List[Dict[str, Any]]][source]

Scan disk for any downloaded serie for all or specified serie.

Parameters:serie_id (Optional[int]) – serie to refresh, if not set all series will be refreshed and scanned
Returns:json response
class pycliarr.api.sonarr.SonarrSerieItem(**kwargs)[source]

Bases: pycliarr.api.base_api.BaseCliApiItem

Class for handling serie info.