From 991cdef3bac3d27069548a6dbeb6d761087257c0 Mon Sep 17 00:00:00 2001 From: "victormanuel.caverogracia" <> Date: Fri, 25 Sep 2026 20:39:21 +0200 Subject: [PATCH] perf(download): extract the video once per attempt, not twice ydl.download([url]) re-ran the whole extraction (player clients, API JSON, m3u8) that extract_info had just done: 4-9 s of round trips per attempt. The unprocessed info is now handed to process_ie_result. Same file (MD5) on a real 1080p video; falls back to ydl.download for playlists and anything without formats. Co-Authored-By: Claude Opus 5.5 --- main.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index ed38364..a4aeb7a 100644 --- a/main.py +++ b/main.py @@ -931,8 +931,11 @@ def download_youtube_video(url, output_dir="."): def _attempt(extractor_args, fmt, proxy, cookies=True): _dl_bytes["total"] = 0 _dl_bytes["partial"] = 0 + # Extracted ONCE, unprocessed, and handed to the download below: a + # plain ydl.download([url]) ran the whole extraction again (player + # clients, API JSON, m3u8), 4-9 s of round trips per attempt. with yt_dlp.YoutubeDL(_base_opts(extractor_args, proxy, cookies)) as ydl: - info = ydl.extract_info(url, download=False) + info = ydl.extract_info(url, download=False, process=False) sanitized = sanitize_filename(info.get('title', 'youtube_video')) expected = os.path.join(output_dir, f'{sanitized}.mp4') if os.path.exists(expected): @@ -945,7 +948,10 @@ def download_youtube_video(url, output_dir="."): 'progress_hooks': [_progress_hook], } with yt_dlp.YoutubeDL(dl_opts) as ydl: - ydl.download([url]) + if info.get('_type', 'video') == 'video' and info.get('formats'): + ydl.process_ie_result(info, download=True) + else: + ydl.download([url]) return sanitized # DIRECT_FIRST=1: try the server's own IP before spending proxy bandwidth.