From bed98832ed2a5b596265712bb3c0ac77d28ed264 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Mon, 3 Jun 2019 20:16:37 -0400 Subject: [PATCH] Added settings to disable UTF8 subtitles re-encoding. --- bazarr/config.py | 1 + bazarr/get_subtitle.py | 12 +++++++++++- bazarr/main.py | 6 ++++++ views/settings_subtitles.tpl | 25 +++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/bazarr/config.py b/bazarr/config.py index 87e31b0db..8be7bd128 100644 --- a/bazarr/config.py +++ b/bazarr/config.py @@ -31,6 +31,7 @@ defaults = { 'page_size': '25', 'minimum_score_movie': '70', 'use_embedded_subs': 'True', + 'utf8_encode': 'True', 'ignore_pgs_subs': 'False', 'adaptive_searching': 'False', 'enabled_providers': '', diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py index 0a1605479..a642f539b 100644 --- a/bazarr/get_subtitle.py +++ b/bazarr/get_subtitle.py @@ -103,6 +103,11 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName, # fixme: supply all missing languages, not only one, to hit providers only once who support multiple languages in # one query + if settings.general.getboolean('utf8_encode'): + os.environ["SZ_KEEP_ENCODING"] = "" + else: + os.environ["SZ_KEEP_ENCODING"] = True + logging.debug('BAZARR Searching subtitles for this file: ' + path) if hi == "True": hi = "force HI" @@ -328,7 +333,12 @@ def manual_search(path, language, hi, providers, providers_auth, sceneName, titl def manual_download_subtitle(path, language, hi, subtitle, provider, providers_auth, sceneName, title, media_type): logging.debug('BAZARR Manually downloading subtitles for this file: ' + path) - + + if settings.general.getboolean('utf8_encode'): + os.environ["SZ_KEEP_ENCODING"] = "" + else: + os.environ["SZ_KEEP_ENCODING"] = True + subtitle = pickle.loads(codecs.decode(subtitle.encode(), "base64")) use_scenename = settings.general.getboolean('use_scenename') use_postprocessing = settings.general.getboolean('use_postprocessing') diff --git a/bazarr/main.py b/bazarr/main.py index 12bd58451..0998ccb86 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -1243,6 +1243,11 @@ def save_settings(): settings_general_embedded = 'False' else: settings_general_embedded = 'True' + settings_general_utf8_encode = request.forms.get('settings_general_utf8_encode') + if settings_general_utf8_encode is None: + settings_general_utf8_encode = 'False' + else: + settings_general_utf8_encode = 'True' settings_general_ignore_pgs = request.forms.get('settings_general_ignore_pgs') if settings_general_ignore_pgs is None: settings_general_ignore_pgs = 'False' @@ -1347,6 +1352,7 @@ def save_settings(): settings.general.minimum_score_movie = text_type(settings_general_minimum_score_movies) settings.general.use_embedded_subs = text_type(settings_general_embedded) + settings.general.utf8_encode = text_type(settings_general_utf8_encode) settings.general.ignore_pgs_subs = text_type(settings_general_ignore_pgs) settings.general.adaptive_searching = text_type(settings_general_adaptive_searching) settings.general.multithreading = text_type(settings_general_multithreading) diff --git a/views/settings_subtitles.tpl b/views/settings_subtitles.tpl index e6fc91885..f04d98ff2 100644 --- a/views/settings_subtitles.tpl +++ b/views/settings_subtitles.tpl @@ -236,6 +236,25 @@ + +