mirror of
https://github.com/morpheus65535/bazarr.git
synced 2024-12-27 01:28:16 +08:00
Updated fallback language for embeddedsubtitles provider to be able to specify the one to use
This commit is contained in:
parent
5dd001317d
commit
ad8f116c78
6 changed files with 31 additions and 14 deletions
|
@ -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()
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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():
|
||||
|
|
|
@ -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_}
|
||||
|
|
Loading…
Reference in a new issue