|
|
@ -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]
|
|
|
|