feat(api): aggregate REST download progress with weighting, track labels and mux stage

Replace the class-level Track.download monkeypatch with a per-job progress sink threaded through dl.result(). The API now reports a single aggregate signal instead of each track's bouncing 0-100%:

- bitrate-weighted completion so video/audio dominate subtitles
- completed_tracks/total_tracks counts and active_tracks labels (e.g. "video 2160p DV", "audio en-US 5.1")
- downloads fill 0-90%; repackaging (when needed) and a "muxing" stage carry it to 100% so post-download work is no longer frozen at 100%
- monotonic throughout (handles the download->decrypt callable reuse)

Also:
- accept "HDR10P" as the canonical API range value ("HDR10+" still works)
- declare AUTH_METHODS opt-in on the Service base
- raise typed APIError (WORKER_ERROR/DOWNLOAD_ERROR) from the worker path
- move the progress helpers to unshackle/core/api/progress.py
This commit is contained in:
imSp4rky
2026-06-08 15:37:40 -06:00
parent 1a3cd09fc8
commit 2f35a4d468
8 changed files with 333 additions and 76 deletions
+12
View File
@@ -1143,6 +1143,7 @@ class dl:
split_audio: Optional[bool] = None,
real_video_bitrate: bool = False,
real_audio_bitrate: bool = False,
progress_sink: Optional[Callable[[dict[str, Any]], None]] = None,
*_: Any,
**__: Any,
) -> None:
@@ -2214,6 +2215,13 @@ class dl:
selected_tracks, tracks_progress_callables = title.tracks.tree(add_progress=True)
if progress_sink is not None:
from unshackle.core.api.progress import build_job_progress_callables
tracks_progress_callables = build_job_progress_callables(
list(title.tracks), tracks_progress_callables, progress_sink
)
for track in title.tracks:
if hasattr(track, "needs_drm_loading") and track.needs_drm_loading:
track.load_drm_if_needed(service)
@@ -2470,6 +2478,8 @@ class dl:
break
# Now repack the decrypted tracks
if progress_sink and any(getattr(t, "needs_repack", False) for t in title.tracks):
progress_sink({"phase": "repackaging", "progress": 92.0, "status": "downloading", "active_tracks": []})
with console.status("Repackaging tracks with FFMPEG..."):
has_repacked = False
for track in title.tracks:
@@ -2636,6 +2646,8 @@ class dl:
for video_track in title.tracks.videos or [None]:
mux_video_standalone(video_track)
if progress_sink:
progress_sink({"phase": "muxing", "progress": 96.0, "status": "downloading", "active_tracks": []})
try:
with Live(Padding(progress, (0, 5, 1, 5)), console=console):
mux_index = 0