aboutsummaryrefslogtreecommitdiffstats
path: root/yt_dlp/downloader
diff options
context:
space:
mode:
Diffstat (limited to 'yt_dlp/downloader')
-rw-r--r--yt_dlp/downloader/common.py13
-rw-r--r--yt_dlp/downloader/external.py26
-rw-r--r--yt_dlp/downloader/fragment.py10
-rw-r--r--yt_dlp/downloader/http.py8
-rw-r--r--yt_dlp/downloader/rtmp.py3
5 files changed, 30 insertions, 30 deletions
diff --git a/yt_dlp/downloader/common.py b/yt_dlp/downloader/common.py
index 9081794db..6cfbb6657 100644
--- a/yt_dlp/downloader/common.py
+++ b/yt_dlp/downloader/common.py
@@ -12,6 +12,7 @@ from ..utils import (
format_bytes,
shell_quote,
timeconvert,
+ timetuple_from_msec,
)
from ..minicurses import (
MultilineLogger,
@@ -75,14 +76,12 @@ class FileDownloader(object):
@staticmethod
def format_seconds(seconds):
- (mins, secs) = divmod(seconds, 60)
- (hours, mins) = divmod(mins, 60)
- if hours > 99:
+ time = timetuple_from_msec(seconds * 1000)
+ if time.hours > 99:
return '--:--:--'
- if hours == 0:
- return '%02d:%02d' % (mins, secs)
- else:
- return '%02d:%02d:%02d' % (hours, mins, secs)
+ if not time.hours:
+ return '%02d:%02d' % time[1:-1]
+ return '%02d:%02d:%02d' % time[:-1]
@staticmethod
def calc_percent(byte_counter, data_len):
diff --git a/yt_dlp/downloader/external.py b/yt_dlp/downloader/external.py
index 40b9dcfe3..ce3370fb7 100644
--- a/yt_dlp/downloader/external.py
+++ b/yt_dlp/downloader/external.py
@@ -22,7 +22,7 @@ from ..utils import (
handle_youtubedl_headers,
check_executable,
is_outdated_version,
- process_communicate_or_kill,
+ Popen,
sanitize_open,
)
@@ -116,9 +116,8 @@ class ExternalFD(FragmentFD):
self._debug_cmd(cmd)
if 'fragments' not in info_dict:
- p = subprocess.Popen(
- cmd, stderr=subprocess.PIPE)
- _, stderr = process_communicate_or_kill(p)
+ p = Popen(cmd, stderr=subprocess.PIPE)
+ _, stderr = p.communicate_or_kill()
if p.returncode != 0:
self.to_stderr(stderr.decode('utf-8', 'replace'))
return p.returncode
@@ -128,9 +127,8 @@ class ExternalFD(FragmentFD):
count = 0
while count <= fragment_retries:
- p = subprocess.Popen(
- cmd, stderr=subprocess.PIPE)
- _, stderr = process_communicate_or_kill(p)
+ p = Popen(cmd, stderr=subprocess.PIPE)
+ _, stderr = p.communicate_or_kill()
if p.returncode == 0:
break
# TODO: Decide whether to retry based on error code
@@ -152,11 +150,11 @@ class ExternalFD(FragmentFD):
fragment_filename = '%s-Frag%d' % (tmpfilename, frag_index)
try:
src, _ = sanitize_open(fragment_filename, 'rb')
- except IOError:
+ except IOError as err:
if skip_unavailable_fragments and frag_index > 1:
- self.to_screen('[%s] Skipping fragment %d ...' % (self.get_basename(), frag_index))
+ self.report_skip_fragment(frag_index, err)
continue
- self.report_error('Unable to open fragment %d' % frag_index)
+ self.report_error(f'Unable to open fragment {frag_index}; {err}')
return -1
dest.write(decrypt_fragment(fragment, src.read()))
src.close()
@@ -199,8 +197,8 @@ class CurlFD(ExternalFD):
self._debug_cmd(cmd)
# curl writes the progress to stderr so don't capture it.
- p = subprocess.Popen(cmd)
- process_communicate_or_kill(p)
+ p = Popen(cmd)
+ p.communicate_or_kill()
return p.returncode
@@ -476,7 +474,7 @@ class FFmpegFD(ExternalFD):
args.append(encodeFilename(ffpp._ffmpeg_filename_argument(tmpfilename), True))
self._debug_cmd(args)
- proc = subprocess.Popen(args, stdin=subprocess.PIPE, env=env)
+ proc = Popen(args, stdin=subprocess.PIPE, env=env)
if url in ('-', 'pipe:'):
self.on_process_started(proc, proc.stdin)
try:
@@ -488,7 +486,7 @@ class FFmpegFD(ExternalFD):
# streams). Note that Windows is not affected and produces playable
# files (see https://github.com/ytdl-org/youtube-dl/issues/8300).
if isinstance(e, KeyboardInterrupt) and sys.platform != 'win32' and url not in ('-', 'pipe:'):
- process_communicate_or_kill(proc, b'q')
+ proc.communicate_or_kill(b'q')
else:
proc.kill()
proc.wait()
diff --git a/yt_dlp/downloader/fragment.py b/yt_dlp/downloader/fragment.py
index d0eaede7e..c345f3148 100644
--- a/yt_dlp/downloader/fragment.py
+++ b/yt_dlp/downloader/fragment.py
@@ -72,8 +72,9 @@ class FragmentFD(FileDownloader):
'\r[download] Got server HTTP error: %s. Retrying fragment %d (attempt %d of %s) ...'
% (error_to_compat_str(err), frag_index, count, self.format_retries(retries)))
- def report_skip_fragment(self, frag_index):
- self.to_screen('[download] Skipping fragment %d ...' % frag_index)
+ def report_skip_fragment(self, frag_index, err=None):
+ err = f' {err};' if err else ''
+ self.to_screen(f'[download]{err} Skipping fragment {frag_index:d} ...')
def _prepare_url(self, info_dict, url):
headers = info_dict.get('http_headers')
@@ -355,8 +356,7 @@ class FragmentFD(FileDownloader):
# not what it decrypts to.
if self.params.get('test', False):
return frag_content
- padding_len = 16 - (len(frag_content) % 16)
- decrypted_data = aes_cbc_decrypt_bytes(frag_content + bytes([padding_len] * padding_len), decrypt_info['KEY'], iv)
+ decrypted_data = aes_cbc_decrypt_bytes(frag_content, decrypt_info['KEY'], iv)
return decrypted_data[:-decrypted_data[-1]]
return decrypt_fragment
@@ -444,7 +444,7 @@ class FragmentFD(FileDownloader):
def append_fragment(frag_content, frag_index, ctx):
if not frag_content:
if not is_fatal(frag_index - 1):
- self.report_skip_fragment(frag_index)
+ self.report_skip_fragment(frag_index, 'fragment not found')
return True
else:
ctx['dest_stream'].close()
diff --git a/yt_dlp/downloader/http.py b/yt_dlp/downloader/http.py
index 2e95bb9d1..6290884a8 100644
--- a/yt_dlp/downloader/http.py
+++ b/yt_dlp/downloader/http.py
@@ -191,11 +191,13 @@ class HttpFD(FileDownloader):
# Unexpected HTTP error
raise
raise RetryDownload(err)
+ except socket.timeout as err:
+ raise RetryDownload(err)
except socket.error as err:
- if err.errno != errno.ECONNRESET:
+ if err.errno in (errno.ECONNRESET, errno.ETIMEDOUT):
# Connection reset is no problem, just retry
- raise
- raise RetryDownload(err)
+ raise RetryDownload(err)
+ raise
def download():
nonlocal throttle_start
diff --git a/yt_dlp/downloader/rtmp.py b/yt_dlp/downloader/rtmp.py
index 6dca64725..90f1acfd4 100644
--- a/yt_dlp/downloader/rtmp.py
+++ b/yt_dlp/downloader/rtmp.py
@@ -12,6 +12,7 @@ from ..utils import (
encodeFilename,
encodeArgument,
get_exe_version,
+ Popen,
)
@@ -26,7 +27,7 @@ class RtmpFD(FileDownloader):
start = time.time()
resume_percent = None
resume_downloaded_data_len = None
- proc = subprocess.Popen(args, stderr=subprocess.PIPE)
+ proc = Popen(args, stderr=subprocess.PIPE)
cursor_in_new_line = True
proc_stderr_closed = False
try: