mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-12 03:55:05 +00:00
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.
27 lines
837 B
Python
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
|