From 1b8833fbd3ca9f2cb570fa38f03748c270de3728 Mon Sep 17 00:00:00 2001 From: dev Date: Sun, 26 Apr 2026 12:48:29 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20t=C3=A9l=C3=A9chargement=20et=20progress?= =?UTF-8?q?ion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- downloader.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/downloader.py b/downloader.py index ccbaa2b..7bf45e0 100644 --- a/downloader.py +++ b/downloader.py @@ -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,