aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMrHereAndThere <[email protected]>2024-02-20 09:10:27 +0700
committerGitHub <[email protected]>2024-02-19 21:10:27 -0500
commitad8f116c78688ab038e834a8ad3a3b4c7bfee0c6 (patch)
tree3734b73ac800a5af6383599b2ba5419c388fc79d
parent5dd001317dc6e88885b392f9fe5107e324593f99 (diff)
downloadbazarr-ad8f116c78688ab038e834a8ad3a3b4c7bfee0c6.tar.gz
bazarr-ad8f116c78688ab038e834a8ad3a3b4c7bfee0c6.zip
Updated fallback language for embeddedsubtitles provider to be able to specify the one to use
-rw-r--r--bazarr/app/config.py9
-rw-r--r--bazarr/app/get_providers.py3
-rw-r--r--frontend/src/pages/Settings/Providers/list.ts10
-rw-r--r--libs/subliminal_patch/providers/embeddedsubtitles.py8
-rw-r--r--tests/bazarr/test_app_get_providers.py3
-rw-r--r--tests/subliminal_patch/test_embeddedsubtitles.py12
6 files changed, 31 insertions, 14 deletions
diff --git a/bazarr/app/config.py b/bazarr/app/config.py
index f4ce412fe..3920969e2 100644
--- a/bazarr/app/config.py
+++ b/bazarr/app/config.py
@@ -291,7 +291,8 @@ validators = [
Validator('embeddedsubtitles.included_codecs', must_exist=True, default=[], is_type_of=list),
Validator('embeddedsubtitles.hi_fallback', must_exist=True, default=False, is_type_of=bool),
Validator('embeddedsubtitles.timeout', must_exist=True, default=600, is_type_of=int, gte=1),
- Validator('embeddedsubtitles.unknown_as_english', must_exist=True, default=False, is_type_of=bool),
+ Validator('embeddedsubtitles.unknown_as_fallback', must_exist=True, default=False, is_type_of=bool),
+ Validator('embeddedsubtitles.fallback_lang', must_exist=True, default='en', is_type_of=str, cast=str),
# karagarga section
Validator('karagarga.username', must_exist=True, default='', is_type_of=str, cast=str),
@@ -448,6 +449,12 @@ if settings.general.wanted_search_frequency == 3:
if settings.general.wanted_search_frequency_movie == 3:
settings.general.wanted_search_frequency_movie = 6
+# backward compatibility embeddedsubtitles provider
+if hasattr(settings.embeddedsubtitles, 'unknown_as_english'):
+ if settings.embeddedsubtitles.unknown_as_english:
+ settings.embeddedsubtitles.unknown_as_fallback = True
+ settings.embeddedsubtitles.fallback_lang = 'en'
+ del settings.embeddedsubtitles.unknown_as_english
# save updated settings to file
write_config()
diff --git a/bazarr/app/get_providers.py b/bazarr/app/get_providers.py
index bba6cd990..7516c38b9 100644
--- a/bazarr/app/get_providers.py
+++ b/bazarr/app/get_providers.py
@@ -301,7 +301,8 @@ def get_providers_auth():
'ffprobe_path': _FFPROBE_BINARY,
'ffmpeg_path': _FFMPEG_BINARY,
'timeout': settings.embeddedsubtitles.timeout,
- 'unknown_as_english': settings.embeddedsubtitles.unknown_as_english,
+ 'unknown_as_fallback': settings.embeddedsubtitles.unknown_as_fallback,
+ 'fallback_lang': settings.embeddedsubtitles.fallback_lang,
},
'karagarga': {
'username': settings.karagarga.username,
diff --git a/frontend/src/pages/Settings/Providers/list.ts b/frontend/src/pages/Settings/Providers/list.ts
index 6beb38551..faaa9b992 100644
--- a/frontend/src/pages/Settings/Providers/list.ts
+++ b/frontend/src/pages/Settings/Providers/list.ts
@@ -156,8 +156,14 @@ export const ProviderList: Readonly<ProviderInfo[]> = [
},
{
type: "switch",
- key: "unknown_as_english",
- name: "Use subtitles with unknown info/language as english",
+ key: "unknown_as_fallback",
+ name: "Use subtitles with unknown info/language as fallback language",
+ },
+ {
+ type: "text",
+ key: "fallback_lang",
+ name: "Fallback language",
+ defaultValue: "en",
},
],
message:
diff --git a/libs/subliminal_patch/providers/embeddedsubtitles.py b/libs/subliminal_patch/providers/embeddedsubtitles.py
index 045347563..7fbf1bef8 100644
--- a/libs/subliminal_patch/providers/embeddedsubtitles.py
+++ b/libs/subliminal_patch/providers/embeddedsubtitles.py
@@ -85,7 +85,8 @@ class EmbeddedSubtitlesProvider(Provider):
ffmpeg_path=None,
hi_fallback=False,
timeout=600,
- unknown_as_english=False,
+ unknown_as_fallback=False,
+ fallback_lang="en",
):
self._included_codecs = set(included_codecs or _ALLOWED_CODECS)
@@ -97,7 +98,8 @@ class EmbeddedSubtitlesProvider(Provider):
cache_dir or tempfile.gettempdir(), self.__class__.__name__.lower()
)
self._hi_fallback = hi_fallback
- self._unknown_as_english = unknown_as_english
+ self._unknown_as_fallback = unknown_as_fallback
+ self._fallback_lang = fallback_lang
self._cached_paths = {}
self._timeout = int(timeout)
@@ -110,7 +112,7 @@ class EmbeddedSubtitlesProvider(Provider):
# Default is True
container.FFMPEG_STATS = False
- tags.LANGUAGE_FALLBACK = "en" if self._unknown_as_english else None
+ tags.LANGUAGE_FALLBACK = self._fallback_lang if self._unknown_as_fallback and self._fallback_lang else None
logger.debug("Language fallback set: %s", tags.LANGUAGE_FALLBACK)
def initialize(self):
diff --git a/tests/bazarr/test_app_get_providers.py b/tests/bazarr/test_app_get_providers.py
index e8f344ef2..af00cb02d 100644
--- a/tests/bazarr/test_app_get_providers.py
+++ b/tests/bazarr/test_app_get_providers.py
@@ -35,7 +35,8 @@ def test_get_providers_auth_embeddedsubtitles():
assert isinstance(item["ffprobe_path"], str)
assert isinstance(item["ffmpeg_path"], str)
assert isinstance(item["timeout"], str)
- assert isinstance(item["unknown_as_english"], bool)
+ assert isinstance(item["unknown_as_fallback"], bool)
+ assert isinstance(item["fallback_lang"], str)
def test_get_providers_auth_karagarga():
diff --git a/tests/subliminal_patch/test_embeddedsubtitles.py b/tests/subliminal_patch/test_embeddedsubtitles.py
index 47e322287..d7f157de1 100644
--- a/tests/subliminal_patch/test_embeddedsubtitles.py
+++ b/tests/subliminal_patch/test_embeddedsubtitles.py
@@ -126,8 +126,8 @@ def fake_streams():
@pytest.mark.parametrize("tags_", [{}, {"language": "und", "title": "Unknown"}])
-def test_list_subtitles_unknown_as_english(mocker, tags_, video_single_language):
- with EmbeddedSubtitlesProvider(unknown_as_english=True) as provider:
+def test_list_subtitles_unknown_as_fallback(mocker, tags_, video_single_language):
+ with EmbeddedSubtitlesProvider(unknown_as_fallback=True, fallback_lang="en") as provider:
fake = FFprobeSubtitleStream(
{"index": 3, "codec_name": "subrip", "tags": tags_}
)
@@ -141,10 +141,10 @@ def test_list_subtitles_unknown_as_english(mocker, tags_, video_single_language)
assert len(result) == 1
-def test_list_subtitles_unknown_as_english_w_real_english_subtitles(
+def test_list_subtitles_unknown_as_fallback_w_real_english_subtitles(
video_single_language, mocker
):
- with EmbeddedSubtitlesProvider(unknown_as_english=True) as provider:
+ with EmbeddedSubtitlesProvider(unknown_as_fallback=True, fallback_lang="en") as provider:
fakes = [
FFprobeSubtitleStream(
{"index": 3, "codec_name": "subrip", "tags": {"language": "und"}}
@@ -164,8 +164,8 @@ def test_list_subtitles_unknown_as_english_w_real_english_subtitles(
@pytest.mark.parametrize("tags_", [{}, {"language": "und", "title": "Unknown"}])
-def test_list_subtitles_unknown_as_english_disabled(tags_):
- with EmbeddedSubtitlesProvider(unknown_as_english=False):
+def test_list_subtitles_unknown_as_fallback_disabled(tags_):
+ with EmbeddedSubtitlesProvider(unknown_as_fallback=False,fallback_lang="en"):
with pytest.raises(LanguageNotFound):
assert FFprobeSubtitleStream(
{"index": 3, "codec_name": "subrip", "tags": tags_}