From db7951ced2749da0ac4537807b817aab40b916e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Sun, 5 Jan 2020 10:33:36 -0500 Subject: [PATCH 1/3] Fix for #737. --- bazarr/get_subtitle.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py index 81d2e8a6e..be4d36ad2 100644 --- a/bazarr/get_subtitle.py +++ b/bazarr/get_subtitle.py @@ -249,6 +249,11 @@ def download_subtitle(path, language, hi, forced, providers, providers_auth, sce if os.name == 'nt': out = out.decode(encoding) + + try: + out = out.decode(sys.stdout.encoding) + except (UnicodeDecodeError, AttributeError): + pass except: if out == "": @@ -474,6 +479,11 @@ def manual_download_subtitle(path, language, hi, forced, subtitle, provider, pro if os.name == 'nt': out = out.decode(encoding) + + try: + out = out.decode(sys.stdout.encoding) + except (UnicodeDecodeError, AttributeError): + pass except: if out == "": From a7689393e17995a6c132352365a7a6c5a515f46e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Sun, 5 Jan 2020 12:49:12 -0500 Subject: [PATCH 2/3] Fix for #718. --- bazarr/get_series.py | 46 +++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/bazarr/get_series.py b/bazarr/get_series.py index 1cd46b2ef..d34a509b5 100644 --- a/bazarr/get_series.py +++ b/bazarr/get_series.py @@ -62,19 +62,21 @@ def update_series(): seriesListLength = len(r.json()) for i, show in enumerate(r.json(), 1): notifications.write(msg="Getting series data from Sonarr...", queue='get_series', item=i, length=seriesListLength) - try: - overview = six.text_type(show['overview']) - except: - overview = "" - try: - poster_big = show['images'][2]['url'].split('?')[0] - poster = os.path.splitext(poster_big)[0] + '-250' + os.path.splitext(poster_big)[1] - except: - poster = "" - try: - fanart = show['images'][0]['url'].split('?')[0] - except: - fanart = "" + + if 'overview' in show: + overview = show['overview'] + else: + overview = '' + + poster = '' + fanart = '' + for image in show['images']: + if image['coverType'] == 'poster': + poster_big = image['url'].split('?')[0] + poster = os.path.splitext(poster_big)[0] + '-250' + os.path.splitext(poster_big)[1] + + if image['coverType'] == 'fanart': + fanart = image['url'].split('?')[0] if show['alternateTitles'] != None: alternateTitles = str([item['title'] for item in show['alternateTitles']]) @@ -85,17 +87,17 @@ def update_series(): current_shows_sonarr.append(show['id']) if show['id'] in current_shows_db_list: - series_to_update.append({'title': six.text_type(show["title"]), - 'path': six.text_type(show["path"]), + series_to_update.append({'title': show["title"], + 'path': show["path"], 'tvdbId': int(show["tvdbId"]), 'sonarrSeriesId': int(show["id"]), - 'overview': six.text_type(overview), - 'poster': six.text_type(poster), - 'fanart': six.text_type(fanart), - 'audio_language': six.text_type(profile_id_to_language((show['qualityProfileId'] if get_sonarr_version().startswith('2') else show['languageProfileId']), audio_profiles)), - 'sortTitle': six.text_type(show['sortTitle']), - 'year': six.text_type(show['year']), - 'alternateTitles': six.text_type(alternateTitles)}) + 'overview': overview, + 'poster': poster, + 'fanart': fanart, + 'audio_language': profile_id_to_language((show['qualityProfileId'] if get_sonarr_version().startswith('2') else show['languageProfileId']), audio_profiles), + 'sortTitle': show['sortTitle'], + 'year': show['year'], + 'alternateTitles': alternateTitles}) else: if serie_default_enabled is True: series_to_add.append({'title': show["title"], From 298a563b4f80e876d400760202072a61e957c253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Mon, 6 Jan 2020 17:11:01 -0500 Subject: [PATCH 3/3] Fix for #737. --- bazarr/get_subtitle.py | 107 ++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 66 deletions(-) diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py index be4d36ad2..698afd853 100644 --- a/bazarr/get_subtitle.py +++ b/bazarr/get_subtitle.py @@ -40,6 +40,7 @@ from analytics import track_event import six from six.moves import range from functools import reduce +from locale import getpreferredencoding def get_video(path, title, sceneName, use_scenename, providers=None, media_type="movie"): @@ -234,39 +235,7 @@ def download_subtitle(path, language, hi, forced, providers, providers_auth, sce command = pp_replace(postprocessing_cmd, path, downloaded_path, downloaded_language, downloaded_language_code2, downloaded_language_code3, subtitle.language.forced) - try: - if os.name == 'nt': - codepage = subprocess.Popen("chcp", shell=True, stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - # wait for the process to terminate - out_codepage, err_codepage = codepage.communicate() - encoding = out_codepage.split(':')[-1].strip() - - process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - # wait for the process to terminate - out, err = process.communicate() - - if os.name == 'nt': - out = out.decode(encoding) - - try: - out = out.decode(sys.stdout.encoding) - except (UnicodeDecodeError, AttributeError): - pass - - except: - if out == "": - logging.error( - 'BAZARR Post-processing result for file ' + path + ' : Nothing returned from command execution') - else: - logging.error('BAZARR Post-processing result for file ' + path + ' : ' + out) - else: - if out == "": - logging.info( - 'BAZARR Post-processing result for file ' + path + ' : Nothing returned from command execution') - else: - logging.info('BAZARR Post-processing result for file ' + path + ' : ' + out) + postprocessing(command, path) # fixme: support multiple languages at once if media_type == 'series': @@ -464,39 +433,7 @@ def manual_download_subtitle(path, language, hi, forced, subtitle, provider, pro command = pp_replace(postprocessing_cmd, path, downloaded_path, downloaded_language, downloaded_language_code2, downloaded_language_code3, subtitle.language.forced) - try: - if os.name == 'nt': - codepage = subprocess.Popen("chcp", shell=True, stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - # wait for the process to terminate - out_codepage, err_codepage = codepage.communicate() - encoding = out_codepage.split(':')[-1].strip() - - process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - # wait for the process to terminate - out, err = process.communicate() - - if os.name == 'nt': - out = out.decode(encoding) - - try: - out = out.decode(sys.stdout.encoding) - except (UnicodeDecodeError, AttributeError): - pass - - except: - if out == "": - logging.error( - 'BAZARR Post-processing result for file ' + path + ' : Nothing returned from command execution') - else: - logging.error('BAZARR Post-processing result for file ' + path + ' : ' + out) - else: - if out == "": - logging.info( - 'BAZARR Post-processing result for file ' + path + ' : Nothing returned from command execution') - else: - logging.info('BAZARR Post-processing result for file ' + path + ' : ' + out) + postprocessing(command, path) if media_type == 'series': reversed_path = path_replace_reverse(path) @@ -1183,3 +1120,41 @@ def upgrade_subtitles(): store_subtitles_movie(movie['video_path'], path_replace_movie(movie['video_path'])) history_log_movie(3, movie['radarrId'], message, path, language_code, provider, score) send_notifications_movie(movie['radarrId'], message) + + +def postprocessing(command, path): + try: + encoding = getpreferredencoding() + if os.name == 'nt': + if six.PY3: + codepage = subprocess.Popen("chcp", shell=True, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, encoding=getpreferredencoding()) + else: + codepage = subprocess.Popen("chcp", shell=True, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + # wait for the process to terminate + out_codepage, err_codepage = codepage.communicate() + encoding = out_codepage.split(':')[-1].strip() + + if six.PY3: + process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, encoding=encoding) + else: + process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + # wait for the process to terminate + out, err = process.communicate() + + if six.PY2: + out = out.decode(encoding) + + out = out.replace('\n', ' ').replace('\r', ' ') + + except Exception as e: + logging.error('BAZARR Post-processing failed for file ' + path + ' : ' + repr(e)) + else: + if out == "": + logging.info( + 'BAZARR Post-processing result for file ' + path + ' : Nothing returned from command execution') + else: + logging.info('BAZARR Post-processing result for file ' + path + ' : ' + out)