mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-29 12:35:13 +00:00
feat(tracks): resume segment decryption and rolling merge through the segment store
This commit is contained in:
@@ -24,6 +24,7 @@ from unshackle.core.manifests.segment_pipeline import (
|
||||
license_drm,
|
||||
)
|
||||
from unshackle.core.remote_protocol import APIErrorCode
|
||||
from unshackle.core.tracks.segment_store import SegmentStore
|
||||
from unshackle.core.tracks.track import DownloadContext, Track
|
||||
|
||||
INIT = b"init" * 8
|
||||
@@ -107,10 +108,10 @@ class FakeDecrypter:
|
||||
def init_bytes(self) -> bytes:
|
||||
return DECRYPTED_INIT
|
||||
|
||||
def submit(self, segment: Path) -> Future:
|
||||
def submit(self, segment: Path, output: Path) -> Future:
|
||||
self.calls.append(("submit", segment.exists()))
|
||||
future: Future = Future()
|
||||
future.set_result(None)
|
||||
future.set_result(segment)
|
||||
return future
|
||||
|
||||
def finish(self) -> bytes:
|
||||
@@ -137,7 +138,10 @@ def fetch(ctx: DownloadContext, downloader: FakeDownloader, **kw: Any) -> tuple[
|
||||
ctx.save_dir.mkdir(parents=True, exist_ok=True)
|
||||
track = SimpleNamespace(id="EXAMPLE", downloader=downloader)
|
||||
urls = [{"url": f"https://cdn.example/{i}.m4s"} for i in range(len(PARTS))]
|
||||
return fetch_segments(track, ctx, SESSION, "EXAMPLE", urls, ctx.save_dir, "{i}.mp4", **kw) # type: ignore[arg-type]
|
||||
store = SegmentStore(track, ctx.save_dir) # type: ignore[arg-type]
|
||||
return fetch_segments( # type: ignore[arg-type]
|
||||
track, ctx, SESSION, "EXAMPLE", urls, ctx.save_dir, "{i}.mp4", store, **kw
|
||||
)
|
||||
|
||||
|
||||
def test_rolling_merge_writes_the_init_then_the_segments_in_order(tmp_path, seen):
|
||||
@@ -166,13 +170,13 @@ def test_without_rolling_merge_the_segments_stay_for_the_manifest_merge(tmp_path
|
||||
assert len(seen) == len(PARTS)
|
||||
|
||||
|
||||
def test_a_decrypter_gets_each_segment_before_its_event_and_heads_the_output(tmp_path, seen):
|
||||
def test_each_segment_gets_its_event_before_the_decrypter_and_the_decrypted_init_heads_the_output(tmp_path, seen):
|
||||
ctx = make_ctx(tmp_path)
|
||||
merger, decrypted_init = fetch(ctx, FakeDownloader(), rolling=True, init=INIT, decrypter=FakeDecrypter(seen))
|
||||
|
||||
assert decrypted_init == DECRYPTED_INIT
|
||||
assert ctx.save_path.read_bytes() == DECRYPTED_INIT + b"".join(PARTS)
|
||||
assert seen == [("submit", True), ("segment", True)] * len(PARTS) + [("finish", None)]
|
||||
assert seen == [("segment", True), ("submit", True)] * len(PARTS) + [("finish", None)]
|
||||
|
||||
|
||||
def test_a_failure_closes_the_decrypter_and_removes_the_output(tmp_path, seen):
|
||||
|
||||
Reference in New Issue
Block a user