mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-29 12:35:13 +00:00
refactor(tracks): fold segment resume into one segment store module
This commit is contained in:
@@ -19,7 +19,8 @@ import requests
|
||||
from unshackle.core.config import config
|
||||
from unshackle.core.constants import DOWNLOAD_CANCELLED
|
||||
from unshackle.core.manifests import HLS
|
||||
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
|
||||
|
||||
PART0 = bytes([0xA0]) * 300
|
||||
@@ -95,6 +96,10 @@ def make_track(srv):
|
||||
return HLS.from_text(MASTER, url=f"{base(srv)}master.m3u8").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",
|
||||
@@ -114,7 +119,7 @@ def test_hls_second_run_reuses_completed_segments(server, tmp_path):
|
||||
HLS.download_track(make_track(server), ctx)
|
||||
|
||||
assert (ctx.save_dir / "segments" / "0.bin").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()
|
||||
@@ -123,7 +128,7 @@ def test_hls_second_run_reuses_completed_segments(server, tmp_path):
|
||||
|
||||
assert ctx.save_path.read_bytes() == 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()
|
||||
|
||||
|
||||
def test_hls_aes128_content_never_writes_sidecar(server, tmp_path):
|
||||
@@ -137,4 +142,4 @@ def test_hls_aes128_content_never_writes_sidecar(server, tmp_path):
|
||||
with pytest.raises(requests.HTTPError):
|
||||
HLS.download_track(make_track(server), ctx)
|
||||
|
||||
assert not resume.sidecar_path(ctx.save_dir).exists()
|
||||
assert not sidecar(ctx).exists()
|
||||
|
||||
Reference in New Issue
Block a user