Merge branch 'development' into morpheus

# Conflicts:
#	bazarr/get_series.py
pull/543/head
Louis Vézina 5 years ago
commit 2e950a14f6

@ -4,10 +4,27 @@ import subprocess as sp
import time import time
import os import os
import sys import sys
import platform
from bazarr import libs
from bazarr.get_args import args from bazarr.get_args import args
def check_python_version():
python_version = platform.python_version_tuple()
minimum_python_version_tuple = (2, 7, 13)
minimum_python_version = ".".join(str(i) for i in minimum_python_version_tuple)
if int(python_version[0]) > minimum_python_version_tuple[0]:
print "Python 3 isn't supported. Please use Python " + minimum_python_version + " or greater."
os._exit(0)
elif int(python_version[1]) < minimum_python_version_tuple[1] or int(python_version[2]) < minimum_python_version_tuple[2]:
print "Python " + minimum_python_version + " or greater required. Current version is " + platform.python_version() + ". Please upgrade Python."
os._exit(0)
check_python_version()
dir_name = os.path.dirname(__file__) dir_name = os.path.dirname(__file__)

@ -11,6 +11,7 @@ from get_args import args
from config import settings, url_sonarr from config import settings, url_sonarr
from list_subtitles import list_missing_subtitles from list_subtitles import list_missing_subtitles
from database import TableShows from database import TableShows
from utils import get_sonarr_version
def update_series(): def update_series():
@ -24,7 +25,7 @@ def update_series():
if apikey_sonarr is None: if apikey_sonarr is None:
pass pass
else: else:
get_profile_list() audio_profiles = get_profile_list()
# Get shows data from Sonarr # Get shows data from Sonarr
url_sonarr_api_series = url_sonarr + "/api/series?apikey=" + apikey_sonarr url_sonarr_api_series = url_sonarr + "/api/series?apikey=" + apikey_sonarr
@ -84,7 +85,7 @@ def update_series():
'overview': unicode(overview), 'overview': unicode(overview),
'poster': unicode(poster), 'poster': unicode(poster),
'fanart': unicode(fanart), 'fanart': unicode(fanart),
'audio_language': unicode(profile_id_to_language((show['qualityProfileId'] if sonarr_version == 2 else show['languageProfileId']))), 'audio_language': unicode(profile_id_to_language((show['qualityProfileId'] if sonarr_version == 2 else show['languageProfileId']), audio_profiles)),
'sort_title': unicode(show['sortTitle']), 'sort_title': unicode(show['sortTitle']),
'year': unicode(show['year']), 'year': unicode(show['year']),
'alternate_titles': unicode(alternateTitles)}) 'alternate_titles': unicode(alternateTitles)})
@ -99,7 +100,7 @@ def update_series():
'overview': overview, 'overview': overview,
'poster': poster, 'poster': poster,
'fanart': fanart, 'fanart': fanart,
'audio_language': profile_id_to_language(show['qualityProfileId']), 'audio_language': profile_id_to_language(show['qualityProfileId'], audio_profiles),
'sort_title': show['sortTitle'], 'sort_title': show['sortTitle'],
'year': show['year'], 'year': show['year'],
'alternate_titles': alternateTitles, 'alternate_titles': alternateTitles,
@ -112,7 +113,7 @@ def update_series():
'overview': overview, 'overview': overview,
'poster': poster, 'poster': poster,
'fanart': fanart, 'fanart': fanart,
'audio_language': profile_id_to_language(show['qualityProfileId']), 'audio_language': profile_id_to_language(show['qualityProfileId'], audio_profiles),
'sort_title': show['sortTitle'], 'sort_title': show['sortTitle'],
'year': show['year'], 'year': show['year'],
'alternate_title': alternateTitles}) 'alternate_title': alternateTitles})
@ -163,53 +164,38 @@ def update_series():
def get_profile_list(): def get_profile_list():
apikey_sonarr = settings.sonarr.apikey apikey_sonarr = settings.sonarr.apikey
sonarr_version = get_sonarr_version()
profiles_list = []
# Get profiles data from Sonarr # Get profiles data from Sonarr
error = False
url_sonarr_api_series = url_sonarr + "/api/profile?apikey=" + apikey_sonarr if sonarr_version.startswith('2'):
try: url_sonarr_api_series = url_sonarr + "/api/profile?apikey=" + apikey_sonarr
profiles_json = requests.get(url_sonarr_api_series, timeout=60, verify=False) elif sonarr_version.startswith('3'):
except requests.exceptions.ConnectionError as errc: url_sonarr_api_series = url_sonarr + "/api/v3/languageprofile?apikey=" + apikey_sonarr
error = True
logging.exception("BAZARR Error trying to get profiles from Sonarr. Connection Error.")
except requests.exceptions.Timeout as errt:
error = True
logging.exception("BAZARR Error trying to get profiles from Sonarr. Timeout Error.")
except requests.exceptions.RequestException as err:
error = True
logging.exception("BAZARR Error trying to get profiles from Sonarr.")
url_sonarr_api_series_v3 = url_sonarr + "/api/v3/languageprofile?apikey=" + apikey_sonarr
try: try:
profiles_json_v3 = requests.get(url_sonarr_api_series_v3, timeout=60, verify=False) profiles_json = requests.get(url_sonarr_api_series, timeout=60, verify=False)
except requests.exceptions.ConnectionError as errc: except requests.exceptions.ConnectionError as errc:
error = True
logging.exception("BAZARR Error trying to get profiles from Sonarr. Connection Error.") logging.exception("BAZARR Error trying to get profiles from Sonarr. Connection Error.")
except requests.exceptions.Timeout as errt: except requests.exceptions.Timeout as errt:
error = True
logging.exception("BAZARR Error trying to get profiles from Sonarr. Timeout Error.") logging.exception("BAZARR Error trying to get profiles from Sonarr. Timeout Error.")
except requests.exceptions.RequestException as err: except requests.exceptions.RequestException as err:
error = True
logging.exception("BAZARR Error trying to get profiles from Sonarr.") logging.exception("BAZARR Error trying to get profiles from Sonarr.")
else:
global profiles_list
profiles_list = []
if not error:
# Parsing data returned from Sonarr # Parsing data returned from Sonarr
global sonarr_version if sonarr_version.startswith('2'):
if type(profiles_json_v3.json()) != list:
sonarr_version = 2
for profile in profiles_json.json(): for profile in profiles_json.json():
profiles_list.append([profile['id'], profile['language'].capitalize()]) profiles_list.append([profile['id'], profile['language'].capitalize()])
else: elif sonarr_version.startswith('3'):
sonarr_version = 3 for profile in profiles_json.json():
for profile in profiles_json_v3.json():
profiles_list.append([profile['id'], profile['name'].capitalize()]) profiles_list.append([profile['id'], profile['name'].capitalize()])
return profiles_list
return None
def profile_id_to_language(id): def profile_id_to_language(id, profiles):
for profile in profiles_list: for profile in profiles:
if id == profile[0]: if id == profile[0]:
return profile[1] return profile[1]

Loading…
Cancel
Save