From 7103f9446f7b5e5463b99d6da09121826c94397e Mon Sep 17 00:00:00 2001 From: victorcavero14 Date: Sat, 26 Sep 2026 00:57:36 +0200 Subject: [PATCH] fix(download): range-fetch only sources far longer than the cap The ranged fetch runs through ffmpeg at ~1-2.5x realtime; a source just over the cap downloads natively in seconds. A 21-min video on a 19-min cap took 8 min ranged. Now ranged only with no known duration or when the source is over 3x the cap and 45+ min longer (finished livestreams). Co-Authored-By: Claude Opus 5.5 --- main.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 9d53c2c..d4cbf1c 100644 --- a/main.py +++ b/main.py @@ -983,10 +983,15 @@ def download_youtube_video(url, output_dir=".", on_audio=None): with yt_dlp.YoutubeDL(_base_opts(extractor_args, proxy, cookies)) as ydl: info = ydl.extract_info(url, download=False, process=False) sanitized = sanitize_filename(info.get('title', 'youtube_video')) + # Only when the whole source is far bigger than what was paid for: a + # ranged fetch goes through ffmpeg at ~1-2.5x realtime, while a native + # download of a source a bit over the cap takes seconds. A 21-min video + # on a 19-min cap took 8 min ranged against ~30 s whole (prod, + # 25-sep-2026); a finished 6.7 h livestream is ~13 GB whole. ranged = False if _range_cap: _dur = info.get('duration') - ranged = not _dur or float(_dur) > _range_cap + ranged = not _dur or float(_dur) > max(3 * _range_cap, _range_cap + 2700) # Once per download, and not on the per-GB proxy (that is paid bytes, # and it is the last resort anyway). Not for a ranged download either: # the early audio would be the whole source.