mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-21 16:35:07 +00:00
fix(dl): treat audio muxed into the video as an available language
A muxed stream carries its audio in the video track, so -l orig no longer fails when the only separate audio tracks are dubs.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from unshackle.core.utilities import embedded_audio_langs
|
||||
|
||||
|
||||
def video(**data):
|
||||
return SimpleNamespace(data=data)
|
||||
|
||||
|
||||
def test_no_videos():
|
||||
assert embedded_audio_langs([], True) == []
|
||||
|
||||
|
||||
def test_video_without_a_declaration():
|
||||
assert embedded_audio_langs([video(), video(audio_language="")], True) == []
|
||||
|
||||
|
||||
def test_declared_language_is_returned():
|
||||
assert embedded_audio_langs([video(audio_language="zh-CN")], True) == ["zh-CN"]
|
||||
|
||||
|
||||
def test_every_declaring_video_counts():
|
||||
videos = [video(audio_language="zh-CN"), video(), video(audio_language="th")]
|
||||
assert embedded_audio_langs(videos, True) == ["zh-CN", "th"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("videos", [[video(audio_language="zh-CN")], [video(audio_language="zh-CN"), video()]])
|
||||
def test_dropping_the_video_drops_its_audio(videos):
|
||||
# --audio-only / --no-video discard the track the audio lives in, so nothing is embedded
|
||||
assert embedded_audio_langs(videos, False) == []
|
||||
@@ -0,0 +1,52 @@
|
||||
import pytest
|
||||
|
||||
from unshackle.core import binaries
|
||||
from unshackle.core.tracks import Tracks, Video
|
||||
|
||||
|
||||
def make_video(track_id: str, **data) -> Video:
|
||||
video = Video(
|
||||
id_=track_id,
|
||||
url=f"https://example.test/{track_id}.m3u8",
|
||||
language="zh",
|
||||
codec=Video.Codec.AVC,
|
||||
range_=Video.Range.SDR,
|
||||
width=1920,
|
||||
height=1080,
|
||||
bitrate=5_000_000,
|
||||
)
|
||||
video.data.update(data)
|
||||
return video
|
||||
|
||||
|
||||
def mux_until_mkvmerge_check(tracks: Tracks) -> None:
|
||||
# the embedded-audio metadata pass runs before the mkvmerge lookup, so a missing
|
||||
# binary stops the mux right after the state under test has been written
|
||||
with pytest.raises(RuntimeError, match="MKVToolNix"):
|
||||
tracks.mux("Test Title")
|
||||
|
||||
|
||||
def test_names_undeclared_video(monkeypatch):
|
||||
monkeypatch.setattr(binaries, "MKVToolNix", None)
|
||||
video = make_video("v1")
|
||||
tracks = Tracks(video)
|
||||
|
||||
mux_until_mkvmerge_check(tracks)
|
||||
|
||||
assert video.needs_repack
|
||||
assert video.data["audio_language"] == "zh"
|
||||
assert video.data["audio_language_name"] == "Chinese"
|
||||
|
||||
|
||||
def test_service_declaration_is_preserved(monkeypatch):
|
||||
monkeypatch.setattr(binaries, "MKVToolNix", None)
|
||||
declared = make_video("v1", audio_language="th", audio_language_name="Thai [Original]")
|
||||
undeclared = make_video("v2")
|
||||
tracks = Tracks([declared, undeclared])
|
||||
|
||||
mux_until_mkvmerge_check(tracks)
|
||||
|
||||
assert declared.data["audio_language"] == "th"
|
||||
assert declared.data["audio_language_name"] == "Thai [Original]"
|
||||
assert not declared.needs_repack
|
||||
assert undeclared.data["audio_language"] == "zh"
|
||||
Reference in New Issue
Block a user