fix: téléchargement et progression
Docker / docker (push) Successful in 1m16s

- Format yt-dlp corrigé : Arte sert l'audio en mp4 pas m4a, l'ancien
  sélecteur échouait immédiatement avec ExtractorError
- Progression basée sur downloaded_bytes/total_bytes_estimate (plus
  fiable pour HLS que _percent_str)
- finished_once : empêche le flux audio de remettre la progression à 0%
  après que le flux vidéo soit terminé

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
dev
2026-04-26 12:48:29 +02:00
parent ca3ab37f19
commit 1b8833fbd3
+12 -8
View File
@@ -86,26 +86,30 @@ class DownloadManager:
with _db() as conn:
conn.execute("UPDATE downloads SET state='downloading' WHERE id=?", (dl_id,))
# For HLS, yt-dlp downloads video then audio separately.
# After the first stream finishes, stay in "processing" — don't reset
# to "downloading" when the audio stream starts.
finished_once = [False]
def hook(d):
if d["status"] == "downloading":
raw = d.get("_percent_str", "0%").strip().rstrip("%")
try:
pct = float(raw)
except ValueError:
pct = 0.0
if d["status"] == "downloading" and not finished_once[0]:
dl = d.get("downloaded_bytes") or 0
total = d.get("total_bytes") or d.get("total_bytes_estimate") or 0
pct = min(dl / total * 100, 99.0) if total > 0 else 0.0
self._set(
dl_id,
state="downloading",
progress=pct,
progress=round(pct, 1),
speed=d.get("_speed_str", ""),
eta=d.get("eta"),
)
elif d["status"] == "finished":
finished_once[0] = True
self._set(dl_id, state="processing", progress=100)
ydl_opts = {
"outtmpl": f"{OUTPUT_DIR}/%(title)s.%(ext)s",
"format": "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best",
"format": "bestvideo[vcodec^=avc1]+bestaudio/bestvideo+bestaudio/best",
"merge_output_format": "mp4",
"progress_hooks": [hook],
"quiet": True,