refactor(tracks): fold segment resume into one segment store module

This commit is contained in:
imSp4rky
2026-11-28 19:21:05 -07:00
parent 5a2680d63d
commit 37357673fe
15 changed files with 633 additions and 368 deletions
+8 -3
View File
@@ -21,7 +21,8 @@ import requests
from unshackle.core.config import config
from unshackle.core.constants import DOWNLOAD_CANCELLED
from unshackle.core.manifests import DASH
from unshackle.core.tracks import resume
from unshackle.core.tracks import Video
from unshackle.core.tracks.segment_store import SegmentStore
from unshackle.core.tracks.track import DownloadContext
pytestmark = pytest.mark.skipif(shutil.which("ffprobe") is None, reason="requires ffprobe")
@@ -101,6 +102,10 @@ def make_track(text: str, srv):
return DASH.from_text(text, url=f"{base(srv)}manifest.mpd").to_tracks(language="en").videos[0]
def sidecar(ctx):
return SegmentStore(Video(url="", language="en"), ctx.save_dir).sidecar
def make_ctx(tmp_path):
return DownloadContext(
save_path=tmp_path / "out.mp4",
@@ -121,7 +126,7 @@ def test_second_run_reuses_completed_segments(server, tmp_path):
DASH.download_track(make_track(mpd(server), server), ctx)
assert (ctx.save_dir / "0.mp4").read_bytes() == PART0
assert resume.sidecar_path(ctx.save_dir).exists()
assert sidecar(ctx).exists()
part0_fetches_run1 = server.requests.count("/part0.bin")
DOWNLOAD_CANCELLED.clear()
@@ -130,7 +135,7 @@ def test_second_run_reuses_completed_segments(server, tmp_path):
assert ctx.save_path.read_bytes() == INIT + PART0 + PART1
assert server.requests.count("/part0.bin") == part0_fetches_run1
assert not resume.sidecar_path(ctx.save_dir).exists()
assert not sidecar(ctx).exists()
assert not ctx.save_dir.exists()