mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-21 20:46:36 -05:00
[utils] restart download if server does not support byte ranges
This commit is contained in:
parent
25a4c5a9ed
commit
d7d2a9a3db
1 changed files with 14 additions and 0 deletions
|
@ -57,6 +57,20 @@ def real_download(self, filename, info_dict):
|
|||
# Establish connection
|
||||
try:
|
||||
data = self.ydl.urlopen(request)
|
||||
|
||||
if resume_len > 0:
|
||||
content_range = data.headers.get('Content-Range')
|
||||
if content_range:
|
||||
content_range_m = re.search(r'bytes (\d+)-', content_range)
|
||||
if content_range_m:
|
||||
# Content-Range is correct - go on
|
||||
if resume_len == int(content_range_m.group(1)):
|
||||
break
|
||||
|
||||
# Content-Range is invalid - wipe the file and do entire redownload
|
||||
resume_len = 0
|
||||
open_mode = 'wb'
|
||||
|
||||
break
|
||||
except (compat_urllib_error.HTTPError, ) as err:
|
||||
if (err.code < 500 or err.code >= 600) and err.code != 416:
|
||||
|
|
Loading…
Reference in a new issue