feat(tracks): add native track names with muxing.track_names

Set muxing.track_names to native to name an unnamed track in its own language (中文(繁體), Português (Portugal)) in place of English. The same script and region rules apply. --list, the muxed names and the REST API track_name follow the option. A test fixture resets the muxing options, so a local unshackle.yaml cannot change test results.
This commit is contained in:
imSp4rky
2026-10-24 12:43:50 -06:00
parent 1175035317
commit ecf17baffe
7 changed files with 87 additions and 6 deletions
+7
View File
@@ -8,6 +8,7 @@ from typing import Any
import pytest
from unshackle.core.config import config
from unshackle.core.update_checker import UpdateChecker
# shutdown() blocks until the serve loop polls again, and the 0.5s default is paid by every
@@ -38,3 +39,9 @@ def no_update_check(monkeypatch: pytest.MonkeyPatch) -> None:
return None
monkeypatch.setattr(UpdateChecker, "check_for_updates", no_release)
@pytest.fixture(autouse=True)
def default_muxing(monkeypatch: pytest.MonkeyPatch) -> None:
"""Mux with the default options, whatever the muxing block of the local unshackle.yaml sets."""
monkeypatch.setattr(config, "muxing", {})
+36
View File
@@ -5,6 +5,7 @@ import pytest
from langcodes import Language
from unshackle.core import binaries
from unshackle.core.config import config
from unshackle.core.tracks import Audio, Subtitle, Tracks, Video
from unshackle.core.utilities import language_name, multi_script_languages, with_script
@@ -72,6 +73,41 @@ def test_language_name(tag: str, expected: Optional[str]) -> None:
assert language_name(Language.get(tag)) == expected
@pytest.mark.parametrize(
("tag", "expected"),
[
("zh-Hant-TW", "中文(繁體)"),
("zh-Hans-CN", "中文(简体)"),
("zh-Hant-HK", "中文(繁體,香港)"),
("zh-Hans-MO", "中文(简体,澳门)"),
("zh-TW", "中文(台灣)"),
("zh-HK", "中文(香港)"),
("cmn-Hant", "中文(繁體)"),
("yue-Hant", "粵語(繁體)"),
("sr-ME", "Srpski (Crna Gora)"),
("ka", "ქართული"),
("hy", "Հայերեն"),
("pt-BR", "Português"),
("pt-PT", "Português (Portugal)"),
("es-419", "Español (Latinoamérica)"),
("sr-Latn-ME", "Srpski (latinica, Crna Gora)"),
("ja-JP", "日本語"),
("en-GB", "English (United Kingdom)"),
("en-HK", "English (Hong Kong)"),
("qaa", None),
],
)
def test_native_language_name(tag: str, expected: Optional[str], monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(config, "muxing", {"track_names": "native"})
assert language_name(Language.get(tag)) == expected
def test_native_subtitle_name_keeps_the_flag(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(config, "muxing", {"track_names": "native"})
assert sub("zh-TW", sdh=True).get_track_name() == "中文(繁體) (SDH)"
assert sub("zh", name="Mandarin").get_track_name() == "Mandarin"
def test_subtitle_names_and_tags_the_script_but_keeps_its_language() -> None:
track = sub("zh-TW")
assert track.name is None