diff options
Diffstat (limited to 'yt_dlp/downloader/http.py')
-rw-r--r-- | yt_dlp/downloader/http.py | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/yt_dlp/downloader/http.py b/yt_dlp/downloader/http.py index 27d147513..95c870ee8 100644 --- a/yt_dlp/downloader/http.py +++ b/yt_dlp/downloader/http.py @@ -9,6 +9,7 @@ import urllib.error from .common import FileDownloader from ..utils import ( ContentTooShortError, + RetryManager, ThrottledDownload, XAttrMetadataError, XAttrUnavailableError, @@ -72,9 +73,6 @@ class HttpFD(FileDownloader): ctx.is_resume = ctx.resume_len > 0 - count = 0 - retries = self.params.get('retries', 0) - class SucceedDownload(Exception): pass @@ -349,9 +347,7 @@ class HttpFD(FileDownloader): if data_len is not None and byte_counter != data_len: err = ContentTooShortError(byte_counter, int(data_len)) - if count <= retries: - retry(err) - raise err + retry(err) self.try_rename(ctx.tmpfilename, ctx.filename) @@ -370,24 +366,20 @@ class HttpFD(FileDownloader): return True - while count <= retries: + for retry in RetryManager(self.params.get('retries'), self.report_retry): try: establish_connection() return download() - except RetryDownload as e: - count += 1 - if count <= retries: - self.report_retry(e.source_error, count, retries) - else: - self.to_screen(f'[download] Got server HTTP error: {e.source_error}') + except RetryDownload as err: + retry.error = err.source_error continue except NextFragment: + retry.error = None + retry.attempt -= 1 continue except SucceedDownload: return True except: # noqa: E722 close_stream() raise - - self.report_error('giving up after %s retries' % retries) return False |