diff options
author | Jesús <heckyel@hyperbola.info> | 2021-12-29 19:12:28 -0500 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2021-12-29 19:12:28 -0500 |
commit | 5aac4e0267e32d98eb68692afedafda3b41ea629 (patch) | |
tree | c3b0f52d6a8cf4ad74e7f17f1ccd7653e1071471 /yt_dlp/downloader | |
parent | 4f0875462ee497cc13c02d0b852f52f4887b5cea (diff) | |
parent | 96f13f01a609add83555ca86fbf35d11441361d8 (diff) | |
download | hypervideo-pre-5aac4e0267e32d98eb68692afedafda3b41ea629.tar.lz hypervideo-pre-5aac4e0267e32d98eb68692afedafda3b41ea629.tar.xz hypervideo-pre-5aac4e0267e32d98eb68692afedafda3b41ea629.zip |
updated from upstream | 29/12/2021 at 19:12
Diffstat (limited to 'yt_dlp/downloader')
-rw-r--r-- | yt_dlp/downloader/common.py | 19 | ||||
-rw-r--r-- | yt_dlp/downloader/dash.py | 2 | ||||
-rw-r--r-- | yt_dlp/downloader/external.py | 8 | ||||
-rw-r--r-- | yt_dlp/downloader/fragment.py | 11 | ||||
-rw-r--r-- | yt_dlp/downloader/http.py | 3 |
5 files changed, 31 insertions, 12 deletions
diff --git a/yt_dlp/downloader/common.py b/yt_dlp/downloader/common.py index d0c9c223f..37321e34b 100644 --- a/yt_dlp/downloader/common.py +++ b/yt_dlp/downloader/common.py @@ -4,12 +4,14 @@ import os import re import time import random +import errno from ..utils import ( decodeArgument, encodeFilename, error_to_compat_str, format_bytes, + sanitize_open, shell_quote, timeconvert, timetuple_from_msec, @@ -39,6 +41,7 @@ class FileDownloader(object): 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 + file_access_retries: Number of times to retry on file access error buffersize: Size of download buffer in bytes. noresizebuffer: Do not automatically resize the download buffer. continuedl: Try to continue downloads if possible. @@ -207,6 +210,21 @@ class FileDownloader(object): def ytdl_filename(self, filename): return filename + '.ytdl' + def sanitize_open(self, filename, open_mode): + file_access_retries = self.params.get('file_access_retries', 10) + retry = 0 + while True: + try: + return sanitize_open(filename, open_mode) + except (IOError, OSError) as err: + retry = retry + 1 + if retry > file_access_retries or err.errno not in (errno.EACCES,): + raise + self.to_screen( + '[download] Got file access error. Retrying (attempt %d of %s) ...' + % (retry, self.format_retries(file_access_retries))) + time.sleep(0.01) + def try_rename(self, old_filename, new_filename): if old_filename == new_filename: return @@ -397,6 +415,7 @@ class FileDownloader(object): 'status': 'finished', 'total_bytes': os.path.getsize(encodeFilename(filename)), }, info_dict) + self._finish_multiline_status() return True, False if subtitle is False: diff --git a/yt_dlp/downloader/dash.py b/yt_dlp/downloader/dash.py index 4c23edd32..a845ee7d3 100644 --- a/yt_dlp/downloader/dash.py +++ b/yt_dlp/downloader/dash.py @@ -57,7 +57,7 @@ class DashSegmentsFD(FragmentFD): def _resolve_fragments(self, fragments, ctx): fragments = fragments(ctx) if callable(fragments) else fragments - return [next(fragments)] if self.params.get('test') else fragments + return [next(iter(fragments))] if self.params.get('test') else fragments def _get_fragments(self, fmt, ctx): fragment_base_url = fmt.get('fragment_base_url') diff --git a/yt_dlp/downloader/external.py b/yt_dlp/downloader/external.py index da69423f7..17be3c46f 100644 --- a/yt_dlp/downloader/external.py +++ b/yt_dlp/downloader/external.py @@ -22,7 +22,6 @@ from ..utils import ( handle_youtubedl_headers, check_executable, Popen, - sanitize_open, ) @@ -144,11 +143,11 @@ class ExternalFD(FragmentFD): return -1 decrypt_fragment = self.decrypter(info_dict) - dest, _ = sanitize_open(tmpfilename, 'wb') + dest, _ = self.sanitize_open(tmpfilename, 'wb') for frag_index, fragment in enumerate(info_dict['fragments']): fragment_filename = '%s-Frag%d' % (tmpfilename, frag_index) try: - src, _ = sanitize_open(fragment_filename, 'rb') + src, _ = self.sanitize_open(fragment_filename, 'rb') except IOError as err: if skip_unavailable_fragments and frag_index > 1: self.report_skip_fragment(frag_index, err) @@ -266,6 +265,7 @@ class Aria2cFD(ExternalFD): cmd += self._option('--all-proxy', 'proxy') cmd += self._bool_option('--check-certificate', 'nocheckcertificate', 'false', 'true', '=') cmd += self._bool_option('--remote-time', 'updatetime', 'true', 'false', '=') + cmd += self._bool_option('--show-console-readout', 'noprogress', 'false', 'true', '=') cmd += self._configuration_args() # aria2c strips out spaces from the beginning/end of filenames and paths. @@ -290,7 +290,7 @@ class Aria2cFD(ExternalFD): for frag_index, fragment in enumerate(info_dict['fragments']): fragment_filename = '%s-Frag%d' % (os.path.basename(tmpfilename), frag_index) url_list.append('%s\n\tout=%s' % (fragment['url'], fragment_filename)) - stream, _ = sanitize_open(url_list_file, 'wb') + stream, _ = self.sanitize_open(url_list_file, 'wb') stream.write('\n'.join(url_list).encode('utf-8')) stream.close() cmd += ['-i', url_list_file] diff --git a/yt_dlp/downloader/fragment.py b/yt_dlp/downloader/fragment.py index 79c6561c7..d4f112b0f 100644 --- a/yt_dlp/downloader/fragment.py +++ b/yt_dlp/downloader/fragment.py @@ -24,7 +24,6 @@ from ..utils import ( DownloadError, error_to_compat_str, encodeFilename, - sanitize_open, sanitized_Request, ) @@ -96,7 +95,7 @@ class FragmentFD(FileDownloader): def _read_ytdl_file(self, ctx): assert 'ytdl_corrupt' not in ctx - stream, _ = sanitize_open(self.ytdl_filename(ctx['filename']), 'r') + stream, _ = self.sanitize_open(self.ytdl_filename(ctx['filename']), 'r') try: ytdl_data = json.loads(stream.read()) ctx['fragment_index'] = ytdl_data['downloader']['current_fragment']['index'] @@ -108,7 +107,7 @@ class FragmentFD(FileDownloader): stream.close() def _write_ytdl_file(self, ctx): - frag_index_stream, _ = sanitize_open(self.ytdl_filename(ctx['filename']), 'w') + frag_index_stream, _ = self.sanitize_open(self.ytdl_filename(ctx['filename']), 'w') try: downloader = { 'current_fragment': { @@ -140,7 +139,7 @@ class FragmentFD(FileDownloader): return True, self._read_fragment(ctx) def _read_fragment(self, ctx): - down, frag_sanitized = sanitize_open(ctx['fragment_filename_sanitized'], 'rb') + down, frag_sanitized = self.sanitize_open(ctx['fragment_filename_sanitized'], 'rb') ctx['fragment_filename_sanitized'] = frag_sanitized frag_content = down.read() down.close() @@ -216,7 +215,7 @@ class FragmentFD(FileDownloader): self._write_ytdl_file(ctx) assert ctx['fragment_index'] == 0 - dest_stream, tmpfilename = sanitize_open(tmpfilename, open_mode) + dest_stream, tmpfilename = self.sanitize_open(tmpfilename, open_mode) ctx.update({ 'dl': dl, @@ -434,6 +433,7 @@ class FragmentFD(FileDownloader): def download_fragment(fragment, ctx): frag_index = ctx['fragment_index'] = fragment['frag_index'] + ctx['last_error'] = None if not interrupt_trigger[0]: return False, frag_index headers = info_dict.get('http_headers', {}).copy() @@ -456,6 +456,7 @@ class FragmentFD(FileDownloader): # See https://github.com/ytdl-org/youtube-dl/issues/10165, # https://github.com/ytdl-org/youtube-dl/issues/10448). count += 1 + ctx['last_error'] = err if count <= fragment_retries: self.report_retry_fragment(err, frag_index, count, fragment_retries) except DownloadError: diff --git a/yt_dlp/downloader/http.py b/yt_dlp/downloader/http.py index 6290884a8..34a1eb59b 100644 --- a/yt_dlp/downloader/http.py +++ b/yt_dlp/downloader/http.py @@ -16,7 +16,6 @@ from ..utils import ( ContentTooShortError, encodeFilename, int_or_none, - sanitize_open, sanitized_Request, ThrottledDownload, write_xattr, @@ -263,7 +262,7 @@ class HttpFD(FileDownloader): # Open destination file just in time if ctx.stream is None: try: - ctx.stream, ctx.tmpfilename = sanitize_open( + ctx.stream, ctx.tmpfilename = self.sanitize_open( ctx.tmpfilename, ctx.open_mode) assert ctx.stream is not None ctx.filename = self.undo_temp_name(ctx.tmpfilename) |