mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-15 21:45:10 +00:00
feat(tracks)!: match a language tag to the variant it means
A tag with a region (en-US, es-419) matches only that variant and reports a miss instead of taking another region. A bare tag takes the variant it means (pt -> pt-BR, es -> es-ES) and falls back to any variant only when that one is missing. `orig` prefers the title's own tag, `-sl orig` resolves, forced and SDH subtitles are picked from their own pools, and the track name no longer strips the region from the cached language. BREAKING CHANGE: -l es-419 no longer selects es-ES, and language_priority, language_tags and muxing.default_language treat a regional tag as exact.
This commit is contained in:
@@ -5,7 +5,7 @@ from __future__ import annotations
|
||||
import pytest
|
||||
from langcodes import Language
|
||||
|
||||
from unshackle.core.utilities import excluded_language_tags, partition_exclusions
|
||||
from unshackle.core.utilities import matched_language_tags, partition_exclusions
|
||||
from unshackle.core.utils.click_types import LANGUAGE_RANGE
|
||||
|
||||
|
||||
@@ -42,34 +42,38 @@ def test_partition_reads_the_tokens_language_range_produces():
|
||||
|
||||
|
||||
def test_close_match_excludes_the_regional_variants():
|
||||
assert excluded_language_tags(["es"], ["es-419", "es-ES", "en-US"]) == {"es-419", "es-ES"}
|
||||
assert matched_language_tags(["es"], ["es-419", "es-ES", "en-US"], every_variant=True) == {"es-419", "es-ES"}
|
||||
|
||||
|
||||
def test_selection_takes_only_the_variant_a_bare_tag_means():
|
||||
assert matched_language_tags(["es"], ["es-419", "es-ES", "en-US"]) == {"es-ES"}
|
||||
|
||||
|
||||
def test_exact_match_prefers_the_string_equal_tag():
|
||||
# same string preference as selection: an exact 'es' only takes 'es' when it exists
|
||||
assert excluded_language_tags(["es"], ["es", "es-ES", "es-419"], exact=True) == {"es"}
|
||||
assert matched_language_tags(["es"], ["es", "es-ES", "es-419"], exact=True) == {"es"}
|
||||
|
||||
|
||||
def test_exact_match_falls_back_to_the_paradigm_variant():
|
||||
# no literal 'es' available, so 'es' resolves the way an exact '-sl es' selection would
|
||||
assert excluded_language_tags(["es"], ["es-ES", "es-419"], exact=True) == {"es-ES"}
|
||||
assert matched_language_tags(["es"], ["es-ES", "es-419"], exact=True) == {"es-ES"}
|
||||
|
||||
|
||||
def test_exact_match_keeps_an_unnamed_regional_variant():
|
||||
assert excluded_language_tags(["es-ES"], ["es-ES", "es-419"], exact=True) == {"es-ES"}
|
||||
assert matched_language_tags(["es-ES"], ["es-ES", "es-419"], exact=True) == {"es-ES"}
|
||||
|
||||
|
||||
def test_language_objects_are_accepted():
|
||||
assert excluded_language_tags(["es"], [Language.get("es")]) == {"es"}
|
||||
assert matched_language_tags(["es"], [Language.get("es")]) == {"es"}
|
||||
|
||||
|
||||
def test_an_untagged_track_is_never_excluded():
|
||||
assert excluded_language_tags(["es"], [None, "en-US"]) == set()
|
||||
assert matched_language_tags(["es"], [None, "en-US"]) == set()
|
||||
|
||||
|
||||
def test_no_exclusions_excludes_nothing():
|
||||
assert excluded_language_tags([], ["es-419", "en-US"]) == set()
|
||||
assert matched_language_tags([], ["es-419", "en-US"]) == set()
|
||||
|
||||
|
||||
def test_an_unmatched_language_is_kept():
|
||||
assert excluded_language_tags(["es", "fr"], ["en-US", "ja-JP"]) == set()
|
||||
assert matched_language_tags(["es", "fr"], ["en-US", "ja-JP"]) == set()
|
||||
|
||||
@@ -20,6 +20,12 @@ def test_a_list_matches_any_of_its_entries() -> None:
|
||||
assert evaluate_language_tag(rules, JA, []) == "ASIAN"
|
||||
|
||||
|
||||
def test_a_regional_rule_does_not_match_another_region() -> None:
|
||||
rules = [{"audio": "es-419", "tag": "LATAM"}]
|
||||
assert evaluate_language_tag(rules, [Language.get("es-ES")], []) == ""
|
||||
assert evaluate_language_tag(rules, [Language.get("es-419")], []) == "LATAM"
|
||||
|
||||
|
||||
def test_subs_contain_all_needs_every_entry() -> None:
|
||||
rules = [{"subs_contain_all": ["en", "fr"], "tag": "MULTI"}]
|
||||
assert evaluate_language_tag(rules, JA, EN_ES) == ""
|
||||
|
||||
Reference in New Issue
Block a user