fix(import): keep the values a service set on exported tracks and export a song as a song

This commit is contained in:
imSp4rky
2026-12-02 17:19:10 -07:00
parent 95d36378f4
commit 0c93f1dc63
6 changed files with 122 additions and 18 deletions
+44 -1
View File
@@ -21,7 +21,8 @@ import requests
from unshackle.core.import_service import ImportService
from unshackle.core.manifests import DASH
from unshackle.core.tracks import Audio, Subtitle, Video
from unshackle.core.tracks import Audio, Subtitle, Tracks, Video
from unshackle.core.wire import track_to_dict
MPD_TEMPLATE = """<?xml version="1.0"?>
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" type="static" mediaPresentationDuration="PT10M">
@@ -300,3 +301,45 @@ def test_a_file_row_can_name_its_codec_and_range_by_name(tmp_path: Path) -> None
def test_a_file_row_marked_stereo_imports_as_a_3d_video(tmp_path: Path) -> None:
service = file_export(tmp_path, [{**FILE_ROWS[0], "stereo": True}])
assert service.get_tracks(next(iter(service.get_titles()))).videos[0].stereo
MPD_SERVICE_VALUES = """<?xml version="1.0"?>
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" type="static" mediaPresentationDuration="PT10M">
<Period id="1">
<AdaptationSet contentType="audio" mimeType="audio/mp4" lang="en">
<Representation id="a1" codecs="ec-3" bandwidth="640000" audioSamplingRate="48000">
<BaseURL>a.mp4</BaseURL><SegmentBase indexRange="0-1"/>
</Representation>
</AdaptationSet>
<AdaptationSet contentType="text" mimeType="application/mp4" lang="en">
<Representation id="s1" codecs="stpp" bandwidth="1000"><BaseURL>s.mp4</BaseURL><SegmentBase indexRange="0-1"/></Representation>
</AdaptationSet>
</Period>
</MPD>
"""
SERVICE_VALUES = {"atmos": True, "bit_depth": 24, "sample_rate": 96000, "note": "EXAMPLE_TIER", "name": "Example Mix"}
def import_with(tmp_path: Path, kind: str, drop: str = "", **values: Any) -> Tracks:
"""Import the manifest with the export dict of its ``kind`` track, given the values a service set after the parse."""
parsed = getattr(
DASH.from_text(MPD_SERVICE_VALUES, "https://example.invalid/m.mpd").to_tracks(language="en"), kind
)[0]
exported = {k: v for k, v in json.loads(json.dumps(track_to_dict(parsed))).items() if k != drop}
return get_tracks(make_service(tmp_path, "en", {exported["id"]: {**exported, **values}}), MPD_SERVICE_VALUES)
def test_the_values_a_service_set_on_a_track_survive_the_reparse(tmp_path: Path) -> None:
audio = import_with(tmp_path, "audio", **SERVICE_VALUES).audio
assert [(t.atmos, t.bit_depth, t.sample_rate, t.note, t.name) for t in audio] == [tuple(SERVICE_VALUES.values())]
assert audio[0].data.get("dash") is not None
def test_a_value_an_older_export_does_not_record_keeps_the_manifest_value(tmp_path: Path) -> None:
assert [t.sample_rate for t in import_with(tmp_path, "audio", drop="sample_rate").audio] == [48000]
def test_a_subtitle_keeps_the_manifest_codec_its_download_converted(tmp_path: Path) -> None:
subtitles = import_with(tmp_path, "subtitles", codec="TimedTextMarkupLang", sdh=True).subtitles
assert [(t.codec, t.sdh) for t in subtitles] == [(Subtitle.Codec.fTTML, True)]