From 58a967c892ef78cb6cf8ab790c2af8728e8c079e Mon Sep 17 00:00:00 2001 From: morpheus65535 Date: Sat, 8 Jan 2022 14:26:40 -0500 Subject: [PATCH] Added settings to change the hearing-impaired subtitles file extension to use when saving to disk. --- bazarr/config.py | 6 +++++- bazarr/init.py | 3 +++ frontend/src/Settings/Subtitles/index.tsx | 11 +++++++++++ frontend/src/Settings/Subtitles/options.ts | 15 +++++++++++++++ libs/subliminal_patch/core.py | 7 ++++++- 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/bazarr/config.py b/bazarr/config.py index a577da32a..843e92823 100644 --- a/bazarr/config.py +++ b/bazarr/config.py @@ -73,7 +73,8 @@ defaults = { 'wanted_search_frequency': '3', 'wanted_search_frequency_movie': '3', 'subzero_mods': '[]', - 'dont_notify_manual_actions': 'False' + 'dont_notify_manual_actions': 'False', + 'hi_extension': 'hi' }, 'auth': { 'type': 'None', @@ -368,6 +369,9 @@ def save_settings(settings_items): if key == 'settings-general-debug': configure_debug = True + if key == 'settings-general-hi_extension': + os.environ["SZ_HI_EXTENSION"] = str(value) + if key in ['settings-general-anti_captcha_provider', 'settings-anticaptcha-anti_captcha_key', 'settings-deathbycaptcha-username', 'settings-deathbycaptcha-password']: configure_captcha = True diff --git a/bazarr/init.py b/bazarr/init.py index fffac5ee5..2d94b858c 100644 --- a/bazarr/init.py +++ b/bazarr/init.py @@ -23,6 +23,9 @@ startTime = time.time() # set subliminal_patch user agent os.environ["SZ_USER_AGENT"] = "Bazarr/{}".format(os.environ["BAZARR_VERSION"]) +# set subliminal_patch hearing-impaired extension to use when naming subtitles +os.environ["SZ_HI_EXTENSION"] = settings.general.hi_extension + # set anti-captcha provider and key configure_captcha_func() diff --git a/frontend/src/Settings/Subtitles/index.tsx b/frontend/src/Settings/Subtitles/index.tsx index 20bdc72d7..17e5f1d56 100644 --- a/frontend/src/Settings/Subtitles/index.tsx +++ b/frontend/src/Settings/Subtitles/index.tsx @@ -16,6 +16,7 @@ import { antiCaptchaOption, colorOptions, folderOptions, + hiExtensionOptions, } from "./options"; const subzeroOverride = (key: string) => { @@ -87,6 +88,16 @@ const SettingsSubtitlesView: FunctionComponent = () => { + + + + What file extension to use when saving hearing-impaired subtitles to + disk (e.g., video.en.sdh.srt). + + diff --git a/frontend/src/Settings/Subtitles/options.ts b/frontend/src/Settings/Subtitles/options.ts index 88cfe7ee6..fe6adaa2a 100644 --- a/frontend/src/Settings/Subtitles/options.ts +++ b/frontend/src/Settings/Subtitles/options.ts @@ -1,3 +1,18 @@ +export const hiExtensionOptions: SelectorOption[] = [ + { + label: ".hi (Hearing-Impaired)", + value: "hi", + }, + { + label: ".sdh (Subtitles for the Deaf or Hard-of-Hearing)", + value: "sdh", + }, + { + label: ".cc (Close Captioned)", + value: "cc", + }, +]; + export const folderOptions: SelectorOption[] = [ { label: "AlongSide Media File", diff --git a/libs/subliminal_patch/core.py b/libs/subliminal_patch/core.py index 08415a3c5..3ecd9d1b6 100644 --- a/libs/subliminal_patch/core.py +++ b/libs/subliminal_patch/core.py @@ -1011,17 +1011,22 @@ def get_subtitle_path(video_path, language=None, extension='.srt', forced_tag=Fa :param language: language of the subtitle to put in the path. :type language: :class:`~babelfish.language.Language` :param str extension: extension of the subtitle. + :param bool forced_tag: is the subtitles forced/foreign? + :param bool hi_tag: is the subtitles hearing-impaired? + :param list tags: list of custom tags :return: path of the subtitle. :rtype: str """ subtitle_root = os.path.splitext(video_path)[0] tags = tags or [] + hi_extension = os.environ.get("SZ_HI_EXTENSION", "hi") + if forced_tag: tags.append("forced") elif hi_tag: - tags.append("hi") + tags.append(hi_extension) if language: subtitle_root += '.' + str(language.basename)