mirror of
https://github.com/morpheus65535/bazarr
synced 2024-12-23 16:23:41 +00:00
547f8c428d
* Add 'Language-equals' support This feature will treat couples of languages as equal for list-subtitles operations. It's optional; its methods won't do anything if an empy list is set. See more info at docstrings from 'subliminal_patch.core'. For example, let's say I only want to have "Spanish (es.srt)" subtitles and I don't care about the differences between Spain and LATAM spanish. This feature will allow me to always get European Spanish even from LATAM Spanish providers like Argenteam and Subdivx. Example for config.ini: language_equals = ['spa-MX:spa'] (Which means all Latam Spanish subtitles from every provider will be converted to European Spanish) * Add PT and ZH language tests * Add HI and Forced parsing for language pairs Format example: ["en@HI:en", "es-MX@forced:es-MX"] * Update languages.py * Update API definition to reflect the previous change * Add language equals table to the UI (test only) * Add global language selector and get language from code3 utilities * Add unit tests for language equal feature * Add encode function to language equal feature * Add CRUD methods to the language equals panel * Add equals description * Add parsing support for alpha3 custom languages * no log: add more tests * Add forced and hi support to the language equal target --------- Co-authored-by: morpheus65535 <louis_vezina@hotmail.com> Co-authored-by: LASER-Yi <liangyi0007@gmail.com>
168 lines
5.2 KiB
Python
168 lines
5.2 KiB
Python
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from subliminal_patch import core
|
|
|
|
|
|
def test_scan_video_movie(tmpdir):
|
|
video_path = Path(tmpdir, "Taxi Driver 1976 Bluray 720p x264.mkv")
|
|
video_path.touch()
|
|
|
|
result = core.scan_video(str(video_path))
|
|
assert isinstance(result, core.Movie)
|
|
|
|
|
|
def test_scan_video_episode(tmpdir):
|
|
video_path = Path(tmpdir, "The Wire S01E01 Bluray 720p x264.mkv")
|
|
video_path.touch()
|
|
|
|
result = core.scan_video(str(video_path))
|
|
assert isinstance(result, core.Episode)
|
|
|
|
|
|
@pytest.fixture
|
|
def pool_instance():
|
|
yield core.SZProviderPool({"argenteam"}, {})
|
|
|
|
|
|
def test_pool_update_w_nothing(pool_instance):
|
|
pool_instance.update({}, {}, [], {})
|
|
assert pool_instance.providers == set()
|
|
assert pool_instance.discarded_providers == set()
|
|
|
|
|
|
def test_pool_update_w_multiple_providers(pool_instance):
|
|
assert pool_instance.providers == {"argenteam"}
|
|
pool_instance.update({"argenteam", "subdivx", "subf2m"}, {}, [], {})
|
|
assert pool_instance.providers == {"argenteam", "subdivx", "subf2m"}
|
|
|
|
|
|
def test_pool_update_discarded_providers(pool_instance):
|
|
assert pool_instance.providers == {"argenteam"}
|
|
|
|
# Provider was discarded internally
|
|
pool_instance.discarded_providers = {"argenteam"}
|
|
|
|
assert pool_instance.discarded_providers == {"argenteam"}
|
|
|
|
# Provider is set to be used again
|
|
pool_instance.update({"subdivx", "argenteam"}, {}, [], {})
|
|
|
|
assert pool_instance.providers == {"argenteam", "subdivx"}
|
|
|
|
# Provider should disappear from discarded providers
|
|
assert pool_instance.discarded_providers == set()
|
|
|
|
|
|
def test_pool_update_discarded_providers_2(pool_instance):
|
|
assert pool_instance.providers == {"argenteam"}
|
|
|
|
# Provider was discarded internally
|
|
pool_instance.discarded_providers = {"argenteam"}
|
|
|
|
assert pool_instance.discarded_providers == {"argenteam"}
|
|
|
|
# Provider is not set to be used again
|
|
pool_instance.update({"subdivx"}, {}, [], {})
|
|
|
|
assert pool_instance.providers == {"subdivx"}
|
|
|
|
# Provider should not disappear from discarded providers
|
|
assert pool_instance.discarded_providers == {"argenteam"}
|
|
|
|
|
|
def test_language_equals_init():
|
|
assert core._LanguageEquals([(core.Language("spa"), core.Language("spa", "MX"))])
|
|
|
|
|
|
def test_language_equals_init_invalid():
|
|
with pytest.raises(ValueError):
|
|
assert core._LanguageEquals([(core.Language("spa", "MX"),)])
|
|
|
|
|
|
def test_language_equals_init_empty_list_gracefully():
|
|
assert core._LanguageEquals([]) == []
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"langs",
|
|
[
|
|
[(core.Language("spa"), core.Language("spa", "MX"))],
|
|
[(core.Language("por"), core.Language("por", "BR"))],
|
|
[(core.Language("zho"), core.Language("zho", "TW"))],
|
|
],
|
|
)
|
|
def test_language_equals_check_set(langs):
|
|
equals = core._LanguageEquals(langs)
|
|
lang_set = {langs[0]}
|
|
assert equals.check_set(lang_set) == set(langs)
|
|
|
|
|
|
def test_language_equals_check_set_do_nothing():
|
|
equals = core._LanguageEquals([(core.Language("eng"), core.Language("spa"))])
|
|
lang_set = {core.Language("spa")}
|
|
assert equals.check_set(lang_set) == {core.Language("spa")}
|
|
|
|
|
|
def test_language_equals_check_set_do_nothing_w_forced():
|
|
equals = core._LanguageEquals(
|
|
[(core.Language("spa", forced=True), core.Language("spa", "MX"))]
|
|
)
|
|
lang_set = {core.Language("spa")}
|
|
assert equals.check_set(lang_set) == {core.Language("spa")}
|
|
|
|
|
|
@pytest.fixture
|
|
def language_equals_pool_intance():
|
|
equals = [(core.Language("spa"), core.Language("spa", "MX"))]
|
|
yield core.SZProviderPool({"subdivx"}, language_equals=equals)
|
|
|
|
|
|
def test_language_equals_pool_intance_list_subtitles(
|
|
language_equals_pool_intance, movies
|
|
):
|
|
subs = language_equals_pool_intance.list_subtitles(
|
|
movies["dune"], {core.Language("spa")}
|
|
)
|
|
assert subs
|
|
assert all(sub.language == core.Language("spa", "MX") for sub in subs)
|
|
|
|
|
|
def test_language_equals_pool_intance_list_subtitles_reversed(movies):
|
|
equals = [(core.Language("spa", "MX"), core.Language("spa"))]
|
|
language_equals_pool_intance = core.SZProviderPool(
|
|
{"subdivx"}, language_equals=equals
|
|
)
|
|
subs = language_equals_pool_intance.list_subtitles(
|
|
movies["dune"], {core.Language("spa")}
|
|
)
|
|
assert subs
|
|
assert all(sub.language == core.Language("spa") for sub in subs)
|
|
|
|
|
|
def test_language_equals_pool_intance_list_subtitles_empty_lang_equals(movies):
|
|
language_equals_pool_intance = core.SZProviderPool(
|
|
{"subdivx"}, language_equals=None
|
|
)
|
|
subs = language_equals_pool_intance.list_subtitles(
|
|
movies["dune"], {core.Language("spa")}
|
|
)
|
|
assert subs
|
|
assert not all(sub.language == core.Language("spa", "MX") for sub in subs)
|
|
|
|
|
|
def test_language_equals_pool_intance_list_subtitles_return_nothing(movies):
|
|
equals = [
|
|
(core.Language("spa", "MX"), core.Language("eng")),
|
|
(core.Language("spa"), core.Language("eng")),
|
|
]
|
|
language_equals_pool_intance = core.SZProviderPool(
|
|
{"subdivx"}, language_equals=equals
|
|
)
|
|
subs = language_equals_pool_intance.list_subtitles(
|
|
movies["dune"], {core.Language("spa")}
|
|
)
|
|
assert not language_equals_pool_intance.download_best_subtitles(
|
|
subs, movies["dune"], {core.Language("spa")}
|
|
)
|