fix(downloads): address code-review findings on the R2.5 mini-epic
- redownload: never clobber a co-held (deduped) asset. Drop the force-reset-to-pending; _release_asset already deletes+recreates a solo asset (genuine re-fetch), while a shared ready asset is left intact and the re-queued job re-points to it via _finish_from_cache — so one user's re-download can't delete another's file mid-serve (finding #1). - redownload: reset queue_pos to the tail so a re-download doesn't front-run newer queued jobs on the worker's `ORDER BY queue_pos` claim (finding #3). Made service.next_queue_pos public. - formats: video-only mp4 selector prefers every video-only option before any progressive `best`, so a "Video only" download stays audio-free whenever a video-only stream exists (#2). - titles: a title that is only the engagement prefix no longer resurrects the stripped stats (return the stripped text / empty, not the raw) (#4). - worker: probe the file's duration when yt-dlp gave none, so a long re-encode shows real progress instead of a frozen 0% (#5); tighten the ensure_browser_playable docstring to its actual mp4-profile scope (#6).
This commit is contained in:
@@ -303,6 +303,20 @@ def probe_codecs(path: Path) -> tuple[str | None, str | None]:
|
||||
return vcodec, acodec
|
||||
|
||||
|
||||
def probe_duration(path: Path) -> int:
|
||||
"""Media duration in whole seconds via ffprobe, or 0 if unknown — a progress denominator for a
|
||||
re-encode when the yt-dlp info dict carried no `duration` (some URL/live extractions)."""
|
||||
try:
|
||||
out = subprocess.run(
|
||||
["ffprobe", "-v", "error", "-show_entries", "format=duration",
|
||||
"-of", "default=nw=1:nk=1", str(path)],
|
||||
capture_output=True, text=True, timeout=30, check=True,
|
||||
).stdout.strip()
|
||||
return int(float(out)) if out else 0
|
||||
except (subprocess.TimeoutExpired, subprocess.CalledProcessError, OSError, ValueError):
|
||||
return 0
|
||||
|
||||
|
||||
def browser_transcode_flags(vcodec: str | None, acodec: str | None, is_mp4: bool) -> tuple[bool, bool, bool]:
|
||||
"""Decide what (if anything) makes a file universally browser-playable. Returns
|
||||
(needs_change, reencode_video, reencode_audio). needs_change=False => already H.264 + AAC/MP3
|
||||
|
||||
Reference in New Issue
Block a user