aboutsummaryrefslogtreecommitdiff
path: root/yt_dlp/downloader/external.py
diff options
context:
space:
mode:
authorpukkandan <pukkandan.ytdlp@gmail.com>2022-08-02 01:43:18 +0530
committerGitHub <noreply@github.com>2022-08-02 01:43:18 +0530
commitbe5c1ae86202be54225d376756f5d9f0bf8f392a (patch)
tree9084adbc9200a204db358f8eb46534d8a98056a9 /yt_dlp/downloader/external.py
parentbfd973ece3369c593b5e82a88cc16de80088a73e (diff)
Standardize retry mechanism (#1649)
* [utils] Create `RetryManager` * Migrate all retries to use the manager * [extractor] Add wrapper methods for convenience * Standardize console messages for retries * Add `--retry-sleep` for extractors
Diffstat (limited to 'yt_dlp/downloader/external.py')
-rw-r--r--yt_dlp/downloader/external.py22
1 files changed, 8 insertions, 14 deletions
diff --git a/yt_dlp/downloader/external.py b/yt_dlp/downloader/external.py
index f84a17f23..9859a7b33 100644
--- a/yt_dlp/downloader/external.py
+++ b/yt_dlp/downloader/external.py
@@ -10,6 +10,7 @@ from ..compat import functools
from ..postprocessor.ffmpeg import EXT_TO_OUT_FORMATS, FFmpegPostProcessor
from ..utils import (
Popen,
+ RetryManager,
_configuration_args,
check_executable,
classproperty,
@@ -134,29 +135,22 @@ class ExternalFD(FragmentFD):
self.to_stderr(stderr)
return returncode
- fragment_retries = self.params.get('fragment_retries', 0)
skip_unavailable_fragments = self.params.get('skip_unavailable_fragments', True)
- count = 0
- while count <= fragment_retries:
+ retry_manager = RetryManager(self.params.get('fragment_retries'), self.report_retry,
+ frag_index=None, fatal=not skip_unavailable_fragments)
+ for retry in retry_manager:
_, stderr, returncode = Popen.run(cmd, text=True, stderr=subprocess.PIPE)
if not returncode:
break
-
# TODO: Decide whether to retry based on error code
# https://aria2.github.io/manual/en/html/aria2c.html#exit-status
if stderr:
self.to_stderr(stderr)
- count += 1
- if count <= fragment_retries:
- self.to_screen(
- '[%s] Got error. Retrying fragments (attempt %d of %s)...'
- % (self.get_basename(), count, self.format_retries(fragment_retries)))
- self.sleep_retry('fragment', count)
- if count > fragment_retries:
- if not skip_unavailable_fragments:
- self.report_error('Giving up after %s fragment retries' % fragment_retries)
- return -1
+ retry.error = Exception()
+ continue
+ if not skip_unavailable_fragments and retry_manager.error:
+ return -1
decrypt_fragment = self.decrypter(info_dict)
dest, _ = self.sanitize_open(tmpfilename, 'wb')