- 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:
+12
-8
@@ -86,26 +86,30 @@ class DownloadManager:
|
|||||||
with _db() as conn:
|
with _db() as conn:
|
||||||
conn.execute("UPDATE downloads SET state='downloading' WHERE id=?", (dl_id,))
|
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):
|
def hook(d):
|
||||||
if d["status"] == "downloading":
|
if d["status"] == "downloading" and not finished_once[0]:
|
||||||
raw = d.get("_percent_str", "0%").strip().rstrip("%")
|
dl = d.get("downloaded_bytes") or 0
|
||||||
try:
|
total = d.get("total_bytes") or d.get("total_bytes_estimate") or 0
|
||||||
pct = float(raw)
|
pct = min(dl / total * 100, 99.0) if total > 0 else 0.0
|
||||||
except ValueError:
|
|
||||||
pct = 0.0
|
|
||||||
self._set(
|
self._set(
|
||||||
dl_id,
|
dl_id,
|
||||||
state="downloading",
|
state="downloading",
|
||||||
progress=pct,
|
progress=round(pct, 1),
|
||||||
speed=d.get("_speed_str", ""),
|
speed=d.get("_speed_str", ""),
|
||||||
eta=d.get("eta"),
|
eta=d.get("eta"),
|
||||||
)
|
)
|
||||||
elif d["status"] == "finished":
|
elif d["status"] == "finished":
|
||||||
|
finished_once[0] = True
|
||||||
self._set(dl_id, state="processing", progress=100)
|
self._set(dl_id, state="processing", progress=100)
|
||||||
|
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
"outtmpl": f"{OUTPUT_DIR}/%(title)s.%(ext)s",
|
"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",
|
"merge_output_format": "mp4",
|
||||||
"progress_hooks": [hook],
|
"progress_hooks": [hook],
|
||||||
"quiet": True,
|
"quiet": True,
|
||||||
|
|||||||
Reference in New Issue
Block a user