feat(tracks): resume segment decryption and rolling merge through the segment store

This commit is contained in:
imSp4rky
2026-11-28 22:09:44 -07:00
parent f4d178c26b
commit 82991dd823
26 changed files with 1125 additions and 186 deletions
+9 -8
View File
@@ -9,6 +9,7 @@ import pytest
from unshackle.core import binaries
from unshackle.core.drm.segment_decrypt import SegmentDecrypter
from unshackle.core.tracks.segment_store import decrypted
pytestmark = pytest.mark.skipif(sys.platform == "win32", reason="the mp4decrypt stub is a shell script")
@@ -42,15 +43,15 @@ def test_segments_and_init_decrypt(tmp_path: Path, stub_mp4decrypt: Path) -> Non
decrypter = SegmentDecrypter(FakeDRM(), b"init-data", tmp_path / "work", workers=2)
work_dir = decrypter.work_dir
for segment in segments:
decrypter.submit(segment)
futures = [decrypter.submit(segment, decrypted(segment)) for segment in segments]
init_data = decrypter.finish()
assert init_data == b"init-data"
# the stub copies, so a replaced segment keeps its bytes under its original name
assert sorted(p.name for p in segment_dir.iterdir()) == ["000.mp4", "001.mp4", "002.mp4"]
for i, segment in enumerate(segments):
assert segment.read_bytes() == f"segment-{i}".encode()
# the stub copies, so each decrypted segment keeps its bytes under its decrypted name
assert sorted(p.name for p in segment_dir.iterdir()) == ["000.clear", "001.clear", "002.clear"]
for i, (segment, future) in enumerate(zip(segments, futures, strict=True)):
assert future.result() == decrypted(segment)
assert decrypted(segment).read_bytes() == f"segment-{i}".encode()
assert not work_dir.exists()
calls = read_argv(stub_mp4decrypt)
@@ -60,7 +61,7 @@ def test_segments_and_init_decrypt(tmp_path: Path, stub_mp4decrypt: Path) -> Non
assert len(segment_calls) == 3
for call in segment_calls:
assert call[call.index("--fragments-info") + 1].endswith("init.mp4")
assert call[-1].endswith(".dec")
assert call[-1].endswith(".clear.!dev")
assert Path(call[-2]).parent == segment_dir
init_calls = [call for call in calls if "--fragments-info" not in call]
@@ -85,7 +86,7 @@ def test_failure_reraises_and_leaves_no_temp_files(tmp_path: Path, monkeypatch:
segment.write_bytes(b"segment-0")
decrypter = SegmentDecrypter(FakeDRM(), b"init-data", tmp_path / "work", workers=1)
decrypter.submit(segment)
decrypter.submit(segment, decrypted(segment))
with pytest.raises(RuntimeError, match="no key"):
decrypter.finish()