Skip to content

Commit

Permalink
#46 Update api for Sonarr v4
Browse files Browse the repository at this point in the history
  • Loading branch information
whatdaybob committed Jan 25, 2023
1 parent 5f63299 commit 0bb9f32
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
2 changes: 2 additions & 0 deletions app/config.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ sonarr:
apikey: 12341234
ssl: false
# basedir: '/sonarr' # if you have sonarr running with a basedir set (e.g. behind a proxy)
# version: v4 # if running v4 beta, allows the v3 api endpoints

ytdl:
# For information on format refer to https://github.com/ytdl-org/youtube-dl#format-selection
default_format: bestvideo[width<=1920]+bestaudio/best[width<=1920]
Expand Down
32 changes: 21 additions & 11 deletions app/sonarr_youtubedl.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ def __init__(self):

# Sonarr Setup
try:
api = "api"
scheme = "http"
basedir = ""
if cfg['sonarr']['ssl'].lower() == ['true']:
if cfg['sonarr'].get('version', '').lower() == 'v4':
api = "api/v3"
logger.debug('Sonarr api set to v4')
if cfg['sonarr']['ssl'].lower() == 'true':
scheme = "https"
if cfg['sonarr'].get('basedir', ''):
basedir = '/' + cfg['sonarr'].get('basedir', '')
Expand All @@ -67,6 +71,7 @@ def __init__(self):
str(cfg['sonarr']['port']),
basedir
)
self.sonarr_api_version = api
self.api_key = cfg['sonarr']['apikey']
except Exception:
sys.exit("Error with sonarr config.yml values.")
Expand All @@ -87,33 +92,37 @@ def get_episodes_by_series_id(self, series_id):
"""Returns all episodes for the given series"""
logger.debug('Begin call Sonarr for all episodes for series_id: {}'.format(series_id))
args = {'seriesId': series_id}
res = self.request_get("{}/api/episode".format(
self.base_url),
args
res = self.request_get("{}/{}/episode".format(
self.base_url,
self.sonarr_api_version
), args
)
return res.json()

def get_episode_files_by_series_id(self, series_id):
"""Returns all episode files for the given series"""
res = self.request_get("{}/api/episodefile?seriesId={}".format(
self.base_url,
res = self.request_get("{}/{}/episodefile?seriesId={}".format(
self.base_url,
self.sonarr_api_version,
series_id
))
return res.json()

def get_series(self):
"""Return all series in your collection"""
logger.debug('Begin call Sonarr for all available series')
res = self.request_get("{}/api/series".format(
self.base_url
res = self.request_get("{}/{}/series".format(
self.base_url,
self.sonarr_api_version
))
return res.json()

def get_series_by_series_id(self, series_id):
"""Return the series with the matching ID or 404 if no matching series is found"""
logger.debug('Begin call Sonarr for specific series series_id: {}'.format(series_id))
res = self.request_get("{}/api/series/{}".format(
res = self.request_get("{}/{}/series/{}".format(
self.base_url,
self.sonarr_api_version,
series_id
))
return res.json()
Expand Down Expand Up @@ -162,8 +171,9 @@ def rescanseries(self, series_id):
"seriesId": str(series_id)
}
res = self.request_put(
"{}/api/command".format(self.base_url),
None,
"{}/{}/command".format(self.base_url),
None,
self.sonarr_api_version,
data
)
return res.json()
Expand Down

0 comments on commit 0bb9f32

Please sign in to comment.