mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-03 06:25:10 +00:00
fix(snapshot): keep every manifest tree of a shared URL and restore each track from its own tree
This commit is contained in:
@@ -223,3 +223,71 @@ def test_an_export_from_a_remote_client_imports_every_track(tmp_path):
|
||||
imported = export_and_import(tmp_path, round_trip(tracks))
|
||||
assert (len(imported.videos), len(imported.audio)) == (1, 1)
|
||||
assert stitched(imported.videos[0]) == ["main-1", "main-2", "main-3"]
|
||||
|
||||
|
||||
OTHER_MPD = mpd("""
|
||||
<Period id="main-1" duration="PT30S">
|
||||
<AdaptationSet contentType="audio" mimeType="audio/mp4" lang="en">
|
||||
<Representation id="a1" codecs="mp4a.40.2" bandwidth="128000" audioSamplingRate="48000">
|
||||
<SegmentTemplate media="other/a1_$Number$.m4s" initialization="other/a1_init.mp4"
|
||||
duration="4" timescale="1" startNumber="1"/>
|
||||
</Representation>
|
||||
<Representation id="a2" codecs="mp4a.40.2" bandwidth="256000" audioSamplingRate="96000">
|
||||
<SegmentTemplate media="other/a2_$Number$.m4s" initialization="other/a2_init.mp4"
|
||||
duration="4" timescale="1" startNumber="1"/>
|
||||
</Representation>
|
||||
</AdaptationSet>
|
||||
</Period>""")
|
||||
|
||||
|
||||
def two_trees(other_url: str = URL) -> Tracks:
|
||||
"""The tracks of two manifests under one URL, the way a service merges a second release.
|
||||
|
||||
Its first audio track has the attributes and the parser id of the first tree's audio, so the
|
||||
service gives every track an id of its own.
|
||||
"""
|
||||
tracks = Tracks()
|
||||
tracks.manifest_url = URL
|
||||
other = DASH.from_text(OTHER_MPD, other_url).to_tracks(language="en")
|
||||
for index, track in enumerate([*service_tracks(), *other]):
|
||||
track.id = f"EXAMPLE-{index}"
|
||||
tracks.add(track)
|
||||
return tracks
|
||||
|
||||
|
||||
def media(track: Track) -> str:
|
||||
return track.data["dash"]["representation"].find("SegmentTemplate").get("media")
|
||||
|
||||
|
||||
def test_every_tree_under_one_url_restores_its_own_tracks():
|
||||
tracks = two_trees()
|
||||
client = round_trip(tracks)
|
||||
assert {t.id: media(t) for t in client} == {t.id: media(t) for t in tracks}
|
||||
assert stitched(client.videos[0]) == ["main-1", "main-2", "main-3"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("other_url", [URL, URL + "?sig=2"])
|
||||
def test_an_import_restores_every_tree_under_one_url(tmp_path, other_url):
|
||||
tracks = two_trees(other_url)
|
||||
imported = export_and_import(tmp_path, tracks)
|
||||
assert sorted(media(t) for t in imported) == sorted(media(t) for t in tracks)
|
||||
|
||||
|
||||
def test_one_tree_parsed_twice_is_saved_once():
|
||||
first, second = service_tracks(), service_tracks()
|
||||
tracks = Tracks(first.videos[0], second.audio[0])
|
||||
saved = capture(tracks)["manifests"]
|
||||
assert len(saved) == 1
|
||||
assert sorted(saved[0]["track_ids"]) == sorted(str(t.id) for t in tracks)
|
||||
|
||||
|
||||
def test_a_snapshot_without_track_ids_still_restores():
|
||||
tracks = service_tracks()
|
||||
saved = json.loads(json.dumps(capture(tracks)))
|
||||
for entry in saved["manifests"]:
|
||||
entry.pop("track_ids", None)
|
||||
client = Tracks()
|
||||
for track in tracks:
|
||||
client.add(track_from_dict(track_to_dict(track)))
|
||||
restore(client, saved)
|
||||
assert {t.id: media(t) for t in client} == {t.id: media(t) for t in tracks}
|
||||
|
||||
Reference in New Issue
Block a user