Files
unshackle/tests/lang_selection/test_original_audio_ids.py
imSp4rky a4ce70a53c 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.
2026-10-15 12:26:39 -06:00

47 lines
1.6 KiB
Python

from __future__ import annotations
from typing import Optional
import pytest
from unshackle.core.api.handlers import original_audio_ids
class FakeTrack:
def __init__(self, language: str) -> None:
self.id = language
self.language = language
class FakeTitle:
def __init__(self, language: Optional[str]) -> None:
self.language = language
@pytest.mark.parametrize(
"title_language,track_languages,expected",
[
# paradigm collapse: CLDR calls these the same language, RFC 4647 picks the specific one
(["en"], ["en", "en-US"], ["en"]),
(["en"], ["en-US", "en-GB"], ["en-US"]),
(["pt"], ["pt-BR", "pt-PT"], ["pt-BR"]),
(["es"], ["es-ES", "es-419"], ["es-ES"]),
# non-paradigm regionals: exact mode drops them, so the fuzzy fallback catches
# them and the flag still matches what a default 'orig' download selects
(["es"], ["es-419"], ["es-419"]),
(["fr"], ["fr-CA"], ["fr-CA"]),
# the service chose the title's region, so a different region still counts
(["en-US"], ["en-GB"], ["en-GB"]),
(["zh-HK"], ["zh-Hant", "zh-Hans"], ["zh-Hant"]),
# alias
(["zh"], ["cmn"], ["cmn"]),
# nothing in the original language, and no language on the title at all
(["en"], ["ja", "de"], []),
([None], ["en"], []),
],
)
def test_original_audio_ids(title_language: list, track_languages: list[str], expected: list[str]) -> None:
tracks = [FakeTrack(t) for t in track_languages]
ids = original_audio_ids(tracks, FakeTitle(title_language[0]))
assert [t for t in track_languages if t in ids] == expected