aboutsummaryrefslogtreecommitdiffstats
path: root/yt_dlp/downloader/http.py
diff options
context:
space:
mode:
Diffstat (limited to 'yt_dlp/downloader/http.py')
-rw-r--r--yt_dlp/downloader/http.py14
1 files changed, 14 insertions, 0 deletions
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