Files
unshackle/tests/tracks/test_mux_default_language.py
T
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

27 lines
837 B
Python

from __future__ import annotations
from typing import Optional
import pytest
from unshackle.core.tracks import Audio, Tracks
@pytest.mark.parametrize(
("languages", "preferred", "expected"),
[
(["en-GB", "en-US"], "en-US", 1),
# matched against every track at once, so the string-equal tag wins over a bare en
(["en", "en-US"], "en-US", 1),
(["en-GB", "fr"], "en-US", None),
(["fr", "en-GB"], "en", 1),
(["en-US"], None, None),
],
)
def test_first_match_index(languages: list[str], preferred: Optional[str], expected: Optional[int]) -> None:
tracks = [
Audio(id_=f"a{i}", url=f"https://x/{i}", language=lang, codec=Audio.Codec.AAC, bitrate=1)
for i, lang in enumerate(languages)
]
assert Tracks.first_match_index(tracks, preferred) == expected