aboutsummaryrefslogtreecommitdiffstats
path: root/yt_dlp/downloader
diff options
context:
space:
mode:
authorpukkandan <pukkandan.ytdlp@gmail.com>2021-06-23 04:41:09 +0530
committerpukkandan <pukkandan.ytdlp@gmail.com>2021-06-23 05:29:58 +0530
commit51d9739f8031fb37d8e25b0e9f1abea561e3d2e3 (patch)
tree4f28a3ed33c65d467535b502125b815650fcd8d9 /yt_dlp/downloader
parent4c7853de1495619e0ace5ba24503600d9e4f49a1 (diff)
downloadhypervideo-pre-51d9739f8031fb37d8e25b0e9f1abea561e3d2e3.tar.lz
hypervideo-pre-51d9739f8031fb37d8e25b0e9f1abea561e3d2e3.tar.xz
hypervideo-pre-51d9739f8031fb37d8e25b0e9f1abea561e3d2e3.zip
Add option `--throttled-rate` below which video data is re-extracted
Currently only for HTTP downloads Closes #430, workaround for https://github.com/ytdl-org/youtube-dl/issues/29326
Diffstat (limited to 'yt_dlp/downloader')
-rw-r--r--yt_dlp/downloader/common.py6
-rw-r--r--yt_dlp/downloader/http.py14
2 files changed, 18 insertions, 2 deletions
diff --git a/yt_dlp/downloader/common.py b/yt_dlp/downloader/common.py
index 66e9677ed..65751bb3b 100644
--- a/yt_dlp/downloader/common.py
+++ b/yt_dlp/downloader/common.py
@@ -14,6 +14,7 @@ from ..utils import (
format_bytes,
shell_quote,
timeconvert,
+ ThrottledDownload,
)
@@ -32,6 +33,7 @@ class FileDownloader(object):
verbose: Print additional info to stdout.
quiet: Do not print messages to stdout.
ratelimit: Download speed limit, in bytes/sec.
+ throttledratelimit: Assume the download is being throttled below this speed (bytes/sec)
retries: Number of times to retry for HTTP error 5xx
buffersize: Size of download buffer in bytes.
noresizebuffer: Do not automatically resize the download buffer.
@@ -170,7 +172,7 @@ class FileDownloader(object):
def slow_down(self, start_time, now, byte_counter):
"""Sleep if the download speed is over the rate limit."""
rate_limit = self.params.get('ratelimit')
- if rate_limit is None or byte_counter == 0:
+ if byte_counter == 0:
return
if now is None:
now = time.time()
@@ -178,7 +180,7 @@ class FileDownloader(object):
if elapsed <= 0.0:
return
speed = float(byte_counter) / elapsed
- if speed > rate_limit:
+ if rate_limit is not None and speed > rate_limit:
sleep_time = float(byte_counter) / rate_limit - elapsed
if sleep_time > 0:
time.sleep(sleep_time)
diff --git a/yt_dlp/downloader/http.py b/yt_dlp/downloader/http.py
index bf77f4427..15eb54aab 100644
--- a/yt_dlp/downloader/http.py
+++ b/yt_dlp/downloader/http.py
@@ -18,6 +18,7 @@ from ..utils import (
int_or_none,
sanitize_open,
sanitized_Request,
+ ThrottledDownload,
write_xattr,
XAttrMetadataError,
XAttrUnavailableError,
@@ -223,6 +224,7 @@ class HttpFD(FileDownloader):
# measure time over whole while-loop, so slow_down() and best_block_size() work together properly
now = None # needed for slow_down() in the first loop run
before = start # start measuring
+ throttle_start = None
def retry(e):
to_stdout = ctx.tmpfilename == '-'
@@ -313,6 +315,18 @@ class HttpFD(FileDownloader):
if data_len is not None and byte_counter == data_len:
break
+ if speed and speed < (self.params.get('throttledratelimit') or 0):
+ # The speed must stay below the limit for 3 seconds
+ # This prevents raising error when the speed temporarily goes down
+ if throttle_start is None:
+ throttle_start = now
+ elif now - throttle_start > 3:
+ if ctx.stream is not None and ctx.tmpfilename != '-':
+ ctx.stream.close()
+ raise ThrottledDownload()
+ else:
+ throttle_start = None
+
if not is_test and ctx.chunk_size and ctx.data_len is not None and byte_counter < ctx.data_len:
ctx.resume_len = byte_counter
# ctx.block_size = block_size