mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-03 06:25:10 +00:00
97 lines
3.5 KiB
Python
97 lines
3.5 KiB
Python
"""The {atmos} token of the naming context."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import types
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from unshackle.core.titles.episode import Episode
|
|
from unshackle.core.titles.movie import Movie
|
|
from unshackle.core.titles.music import Song
|
|
from unshackle.core.tracks import Audio
|
|
from unshackle.core.wire import deserialize_audio
|
|
|
|
|
|
class DummyService:
|
|
pass
|
|
|
|
|
|
def media_info(*formats: str, joc: bool = False, path: Path | None = None) -> types.SimpleNamespace:
|
|
"""A MediaInfo of the file at ``path`` with one 2.0 audio track per format, JOC only when asked."""
|
|
tracks = [
|
|
types.SimpleNamespace(
|
|
language="en",
|
|
format=fmt,
|
|
channel_layout="L R",
|
|
channellayout_original=None,
|
|
channel_s=2,
|
|
channels=2,
|
|
format_additionalfeatures="JOC" if joc else None,
|
|
joc=None,
|
|
)
|
|
for fmt in formats
|
|
]
|
|
general = [types.SimpleNamespace(complete_name=str(path))] if path else []
|
|
return types.SimpleNamespace(general_tracks=general, video_tracks=[], audio_tracks=tracks)
|
|
|
|
|
|
def audio(codec: Audio.Codec, atmos: bool, language: str = "en") -> Audio:
|
|
extra = {"atmos": True} if atmos else None
|
|
return Audio(id_=f"{codec.name}-{language}", url="https://x/a", codec=codec, language=language, extra=extra)
|
|
|
|
|
|
TITLES = {
|
|
"movie": lambda: Movie(id_="movie-0001", service=DummyService, name="The Film", year=2024, language="en"),
|
|
"episode": lambda: Episode(
|
|
id_="episode-0001", service=DummyService, title="The Show", season=1, number=2, language="en"
|
|
),
|
|
"song": lambda: Song(
|
|
id_="song-0001",
|
|
service=DummyService,
|
|
name="The Song",
|
|
artist="EXAMPLE",
|
|
album="The Album",
|
|
track=1,
|
|
language="en",
|
|
),
|
|
}
|
|
|
|
|
|
@pytest.mark.parametrize("kind", TITLES)
|
|
def test_an_atmos_track_names_a_file_mediainfo_shows_without_joc(kind: str) -> None:
|
|
title = TITLES[kind]()
|
|
title.tracks.add(audio(Audio.Codec.AC4, atmos=True))
|
|
assert title.build_template_context(media_info("AC-4"))["atmos"] == "Atmos"
|
|
|
|
|
|
def test_a_track_from_the_remote_server_carries_atmos() -> None:
|
|
title = TITLES["song"]()
|
|
title.tracks.add(
|
|
deserialize_audio({"id": "a", "url": "https://x/a", "codec": "AC4", "language": "en", "atmos": True})
|
|
)
|
|
assert title.build_template_context(media_info("AC-4"))["atmos"] == "Atmos"
|
|
|
|
|
|
def test_joc_in_mediainfo_still_names_atmos() -> None:
|
|
assert TITLES["movie"]().build_template_context(media_info("E-AC-3", joc=True))["atmos"] == "Atmos"
|
|
|
|
|
|
def test_a_file_without_the_atmos_track_is_not_named_atmos() -> None:
|
|
"""With the audio split by codec, the AAC file of a title with an Atmos track has no Atmos."""
|
|
title = TITLES["movie"]()
|
|
title.tracks.add(audio(Audio.Codec.AC4, atmos=True))
|
|
title.tracks.add(audio(Audio.Codec.AAC, atmos=False))
|
|
assert title.build_template_context(media_info("AAC"))["atmos"] == ""
|
|
|
|
|
|
def test_a_file_of_one_track_reads_only_that_track(tmp_path: Path) -> None:
|
|
"""A track saved on its own is not named Atmos for another track of the same codec."""
|
|
title = TITLES["movie"]()
|
|
atmos, plain = audio(Audio.Codec.EC3, atmos=True), audio(Audio.Codec.EC3, atmos=False, language="de")
|
|
atmos.path, plain.path = tmp_path / "en.mp4", tmp_path / "de.mp4"
|
|
title.tracks.add([atmos, plain])
|
|
assert title.build_template_context(media_info("E-AC-3", path=plain.path))["atmos"] == ""
|
|
assert title.build_template_context(media_info("E-AC-3", path=atmos.path))["atmos"] == "Atmos"
|