mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-19 07:25:11 +00:00
feat(api): report per-episode and per-track progress on download jobs
Adds title, current_title, incremental output_files, and track_progress to job status so clients can render live multi-episode progress.
This commit is contained in:
@@ -1987,6 +1987,17 @@ class dl:
|
|||||||
elif isinstance(title, Episode) and wanted and f"{title.season}x{title.number}" not in wanted:
|
elif isinstance(title, Episode) and wanted and f"{title.season}x{title.number}" not in wanted:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if progress_sink:
|
||||||
|
if isinstance(title, Episode):
|
||||||
|
progress_sink(
|
||||||
|
{
|
||||||
|
"title": title.title,
|
||||||
|
"current_title": f"S{title.season or 0:02}E{title.number or 0:02}",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
progress_sink({"title": getattr(title, "name", None) or str(title)})
|
||||||
|
|
||||||
title_rule = (
|
title_rule = (
|
||||||
f"Track {title.track:02}: {title.name}" if music_mode and isinstance(title, Song) else str(title)
|
f"Track {title.track:02}: {title.name}" if music_mode and isinstance(title, Song) else str(title)
|
||||||
)
|
)
|
||||||
@@ -3440,6 +3451,9 @@ class dl:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if progress_sink:
|
||||||
|
progress_sink({"output_files": [str(p) for p in self.completed_files]})
|
||||||
|
|
||||||
if not hasattr(service, "close"):
|
if not hasattr(service, "close"):
|
||||||
cookie_file = self.get_cookie_path(self.service, self.profile)
|
cookie_file = self.get_cookie_path(self.service, self.profile)
|
||||||
if cookie_file:
|
if cookie_file:
|
||||||
|
|||||||
@@ -101,9 +101,12 @@ class DownloadJob:
|
|||||||
|
|
||||||
# Current phase, track counts, and labels of the tracks downloading now.
|
# Current phase, track counts, and labels of the tracks downloading now.
|
||||||
phase: Optional[str] = None
|
phase: Optional[str] = None
|
||||||
|
title: Optional[str] = None
|
||||||
|
current_title: Optional[str] = None
|
||||||
completed_tracks: int = 0
|
completed_tracks: int = 0
|
||||||
total_tracks: int = 0
|
total_tracks: int = 0
|
||||||
active_tracks: List[str] = field(default_factory=list)
|
active_tracks: List[str] = field(default_factory=list)
|
||||||
|
track_progress: List[Dict[str, Any]] = field(default_factory=list)
|
||||||
# Segment counts and transfer speed of the track downloading now (granular display)
|
# Segment counts and transfer speed of the track downloading now (granular display)
|
||||||
segments_done: float = 0.0
|
segments_done: float = 0.0
|
||||||
segments_total: float = 0.0
|
segments_total: float = 0.0
|
||||||
@@ -124,11 +127,14 @@ class DownloadJob:
|
|||||||
"created_time": self.created_time.isoformat(),
|
"created_time": self.created_time.isoformat(),
|
||||||
"service": self.service,
|
"service": self.service,
|
||||||
"title_id": self.title_id,
|
"title_id": self.title_id,
|
||||||
|
"title": self.title,
|
||||||
"progress": self.progress,
|
"progress": self.progress,
|
||||||
"phase": self.phase,
|
"phase": self.phase,
|
||||||
|
"current_title": self.current_title,
|
||||||
"completed_tracks": self.completed_tracks,
|
"completed_tracks": self.completed_tracks,
|
||||||
"total_tracks": self.total_tracks,
|
"total_tracks": self.total_tracks,
|
||||||
"active_tracks": self.active_tracks,
|
"active_tracks": self.active_tracks,
|
||||||
|
"track_progress": self.track_progress,
|
||||||
"segments_done": self.segments_done,
|
"segments_done": self.segments_done,
|
||||||
"segments_total": self.segments_total,
|
"segments_total": self.segments_total,
|
||||||
"speed": self.speed,
|
"speed": self.speed,
|
||||||
@@ -734,12 +740,20 @@ class DownloadQueueManager:
|
|||||||
progress_data = json.load(handle)
|
progress_data = json.load(handle)
|
||||||
if progress_data.get("phase") and progress_data["phase"] != job.phase:
|
if progress_data.get("phase") and progress_data["phase"] != job.phase:
|
||||||
job.phase = progress_data["phase"]
|
job.phase = progress_data["phase"]
|
||||||
|
if progress_data.get("current_title"):
|
||||||
|
job.current_title = str(progress_data["current_title"])
|
||||||
|
if progress_data.get("title"):
|
||||||
|
job.title = str(progress_data["title"])
|
||||||
|
if progress_data.get("output_files"):
|
||||||
|
job.output_files = [str(f) for f in progress_data["output_files"]]
|
||||||
if progress_data.get("total_tracks"):
|
if progress_data.get("total_tracks"):
|
||||||
job.total_tracks = int(progress_data["total_tracks"])
|
job.total_tracks = int(progress_data["total_tracks"])
|
||||||
if progress_data.get("completed_tracks") is not None:
|
if progress_data.get("completed_tracks") is not None:
|
||||||
job.completed_tracks = int(progress_data["completed_tracks"])
|
job.completed_tracks = int(progress_data["completed_tracks"])
|
||||||
if "active_tracks" in progress_data:
|
if "active_tracks" in progress_data:
|
||||||
job.active_tracks = list(progress_data["active_tracks"])
|
job.active_tracks = list(progress_data["active_tracks"])
|
||||||
|
if "track_progress" in progress_data:
|
||||||
|
job.track_progress = list(progress_data["track_progress"])
|
||||||
for _sk in ("segments_done", "segments_total"):
|
for _sk in ("segments_done", "segments_total"):
|
||||||
if _sk in progress_data:
|
if _sk in progress_data:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -49,12 +49,16 @@ def main(argv: list[str]) -> int:
|
|||||||
|
|
||||||
log.info(f"Worker starting job {job_id} ({service}:{title_id})")
|
log.info(f"Worker starting job {job_id} ({service}:{title_id})")
|
||||||
|
|
||||||
|
# Merged so sparse keys (current_title, output_files) survive later writes.
|
||||||
|
progress_state: Dict[str, Any] = {}
|
||||||
|
|
||||||
def progress_callback(progress_data: Dict[str, Any]) -> None:
|
def progress_callback(progress_data: Dict[str, Any]) -> None:
|
||||||
"""Write progress updates to file for main process to read."""
|
"""Write progress updates to file for main process to read."""
|
||||||
if progress_path:
|
if progress_path:
|
||||||
try:
|
try:
|
||||||
|
progress_state.update(progress_data)
|
||||||
log.info(f"Writing progress update: {progress_data}")
|
log.info(f"Writing progress update: {progress_data}")
|
||||||
_write_result(progress_path, progress_data)
|
_write_result(progress_path, progress_state)
|
||||||
log.info(f"Progress update written to {progress_path}")
|
log.info(f"Progress update written to {progress_path}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error(f"Failed to write progress update: {e}")
|
log.error(f"Failed to write progress update: {e}")
|
||||||
|
|||||||
@@ -94,6 +94,11 @@ def build_job_progress_callables(
|
|||||||
"completed_tracks": completed,
|
"completed_tracks": completed,
|
||||||
"total_tracks": total,
|
"total_tracks": total,
|
||||||
"active_tracks": active,
|
"active_tracks": active,
|
||||||
|
"track_progress": [
|
||||||
|
{"label": labels[i], "progress": round(fractions[i] * 100, 1), "speed": speeds[i]}
|
||||||
|
for i in range(total)
|
||||||
|
if started[i] and not done[i]
|
||||||
|
],
|
||||||
"segments_done": seg_done[active_i] if active_i is not None else 0.0,
|
"segments_done": seg_done[active_i] if active_i is not None else 0.0,
|
||||||
"segments_total": seg_total[active_i] if active_i is not None else 0.0,
|
"segments_total": seg_total[active_i] if active_i is not None else 0.0,
|
||||||
"speed": speeds[active_i] if active_i is not None else None,
|
"speed": speeds[active_i] if active_i is not None else None,
|
||||||
|
|||||||
Reference in New Issue
Block a user