Improved Sonarr versions prior to 3.x detection.

pull/1485/head v0.9.7-beta.3
morpheus65535 3 years ago
parent e3f358bc4f
commit 96b8b5ccce

@ -49,7 +49,7 @@ def browse_sonarr_filesystem(path='#'):
sonarr_version = get_sonarr_version()
if path == '#':
path = ''
if sonarr_version.startswith('2'):
if sonarr_version.startswith(('0.', '2.')):
url_sonarr_api_filesystem = url_sonarr() + "/api/filesystem?path=" + path + \
"&allowFoldersWithoutTrailingSlashes=true&includeFiles=false&apikey=" + \
settings.sonarr.apikey

@ -63,7 +63,7 @@ def sync_episodes(series_id=None, send_event=True):
continue
else:
# For Sonarr v3, we need to update episodes to integrate the episodeFile API endpoint results
if sonarr_version.startswith('3'):
if not sonarr_version.startswith(('0.', '2.')):
episodeFiles = get_episodesFiles_from_sonarr_api(url=url_sonarr(), apikey_sonarr=apikey_sonarr,
series_id=seriesId['sonarrSeriesId'])
for episode in episodes:
@ -187,7 +187,7 @@ def sync_one_episode(episode_id):
else:
# For Sonarr v3, we need to update episodes to integrate the episodeFile API endpoint results
if sonarr_version.startswith('3'):
if not sonarr_version.startswith(('0.', '2.')):
episodeFile = get_episodesFiles_from_sonarr_api(url=url, apikey_sonarr=apikey_sonarr,
episode_file_id=existing_episode['episode_file_id'])
if episode_data['hasFile']:
@ -339,10 +339,10 @@ def episodeParser(episode):
def get_series_from_sonarr_api(series_id, url, apikey_sonarr, sonarr_version):
if series_id:
url_sonarr_api_series = url + "/api/{0}series/{1}?apikey={2}".format(
'' if sonarr_version.startswith('2') else 'v3/', series_id, apikey_sonarr)
'' if sonarr_version.startswith(('0.', '2.')) else 'v3/', series_id, apikey_sonarr)
else:
url_sonarr_api_series = url + "/api/{0}series?apikey={1}".format(
'' if sonarr_version.startswith('2') else 'v3/', apikey_sonarr)
'' if sonarr_version.startswith(('0.', '2.')) else 'v3/', apikey_sonarr)
try:
r = requests.get(url_sonarr_api_series, timeout=60, verify=False, headers=headers)
r.raise_for_status()
@ -375,10 +375,10 @@ def get_series_from_sonarr_api(series_id, url, apikey_sonarr, sonarr_version):
def get_episodes_from_sonarr_api(url, apikey_sonarr, sonarr_version, series_id=None, episode_id=None):
if series_id:
url_sonarr_api_episode = url + "/api/{0}episode?seriesId={1}&apikey={2}".format(
'' if sonarr_version.startswith('2') else 'v3/', series_id, apikey_sonarr)
'' if sonarr_version.startswith(('0.', '2.')) else 'v3/', series_id, apikey_sonarr)
elif episode_id:
url_sonarr_api_episode = url + "/api/{0}episode/{1}?apikey={2}".format(
'' if sonarr_version.startswith('2') else 'v3/', episode_id, apikey_sonarr)
'' if sonarr_version.startswith(('0.', '2.')) else 'v3/', episode_id, apikey_sonarr)
else:
return

@ -18,7 +18,7 @@ def get_sonarr_rootfolder():
sonarr_version = get_sonarr_version()
# Get root folder data from Sonarr
if sonarr_version.startswith('2'):
if sonarr_version.startswith(('0.', '2.')):
url_sonarr_api_rootfolder = url_sonarr() + "/api/rootfolder?apikey=" + apikey_sonarr
else:
url_sonarr_api_rootfolder = url_sonarr() + "/api/v3/rootfolder?apikey=" + apikey_sonarr

@ -212,7 +212,7 @@ def get_profile_list():
profiles_list = []
# Get profiles data from Sonarr
if sonarr_version.startswith('2'):
if sonarr_version.startswith(('0.', '2.')):
url_sonarr_api_series = url_sonarr() + "/api/profile?apikey=" + apikey_sonarr
else:
url_sonarr_api_series = url_sonarr() + "/api/v3/languageprofile?apikey=" + apikey_sonarr
@ -230,7 +230,7 @@ def get_profile_list():
return None
# Parsing data returned from Sonarr
if sonarr_version.startswith('2'):
if sonarr_version.startswith(('0.', '2.')):
for profile in profiles_json.json():
profiles_list.append([profile['id'], profile['language'].capitalize()])
else:
@ -250,10 +250,11 @@ def profile_id_to_language(id_, profiles):
def get_tags():
apikey_sonarr = settings.sonarr.apikey
sonarr_version = get_sonarr_version()
tagsDict = []
# Get tags data from Sonarr
if get_sonarr_version().startswith('2'):
if sonarr_version.startswith(('0.', '2.')):
url_sonarr_api_series = url_sonarr() + "/api/tag?apikey=" + apikey_sonarr
else:
url_sonarr_api_series = url_sonarr() + "/api/v3/tag?apikey=" + apikey_sonarr
@ -290,7 +291,7 @@ def seriesParser(show, action, sonarr_version, tags_dict, serie_default_profile,
alternate_titles = str([item['title'] for item in show['alternateTitles']])
audio_language = []
if sonarr_version.startswith('2'):
if sonarr_version.startswith(('0.', '2.')):
audio_language = profile_id_to_language(show['qualityProfileId'], audio_profiles)
else:
audio_language = profile_id_to_language(show['languageProfileId'], audio_profiles)
@ -334,7 +335,7 @@ def seriesParser(show, action, sonarr_version, tags_dict, serie_default_profile,
def get_series_from_sonarr_api(url, apikey_sonarr, sonarr_version, sonarr_series_id=None):
url_sonarr_api_series = url + "/api/{0}series/{1}?apikey={2}".format(
'' if sonarr_version.startswith('2') else 'v3/', sonarr_series_id if sonarr_series_id else "", apikey_sonarr)
'' if sonarr_version.startswith(('0.', '2.')) else 'v3/', sonarr_series_id if sonarr_series_id else "", apikey_sonarr)
try:
r = requests.get(url_sonarr_api_series, timeout=60, verify=False, headers=headers)
r.raise_for_status()

@ -132,7 +132,7 @@ def series_images(url):
apikey = settings.sonarr.apikey
baseUrl = settings.sonarr.base_url
sonarr_version = get_sonarr_version()
if sonarr_version.startswith('2'):
if sonarr_version.startswith(('0.', '2.')):
url_image = (url_sonarr() + '/api/' + url.lstrip(baseUrl) + '?apikey=' +
apikey).replace('poster-250', 'poster-500')
else:

@ -34,7 +34,7 @@ class SonarrSignalrClient:
def start(self):
sonarr_version = get_sonarr_version()
if sonarr_version.startswith('2.'):
if sonarr_version.startswith(('0.', '2.')):
logging.warning('BAZARR can only sync from Sonarr v3 SignalR feed to get real-time update. You should '
'consider upgrading your version({}).'.format(sonarr_version))
raise gevent.GreenletExit

@ -255,9 +255,10 @@ def get_sonarr_version():
def get_sonarr_platform():
sonarr_platform = ''
sonarr_version = get_sonarr_version()
if settings.general.getboolean('use_sonarr'):
try:
if get_sonarr_version().startswith('2'):
if sonarr_version.startswith(('0.', '2.')):
sv = url_sonarr() + "/api/system/status?apikey=" + settings.sonarr.apikey
else:
sv = url_sonarr() + "/api/v3/system/status?apikey=" + settings.sonarr.apikey
@ -272,8 +273,9 @@ def get_sonarr_platform():
def notify_sonarr(sonarr_series_id):
sonarr_version = get_sonarr_version()
try:
if get_sonarr_version().startswith('2'):
if sonarr_version.startswith(('0.', '2.')):
url = url_sonarr() + "/api/command?apikey=" + settings.sonarr.apikey
else:
url = url_sonarr() + "/api/v3/command?apikey=" + settings.sonarr.apikey

Loading…
Cancel
Save