Skip to content

Commit

Permalink
Apply Coletdev's patch!
Browse files Browse the repository at this point in the history
  • Loading branch information
gamer191 committed Feb 28, 2023
1 parent 8e9fe43 commit 30ae589
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions yt_dlp/downloader/http.py
Expand Up @@ -18,7 +18,7 @@
parse_http_range,
sanitized_Request,
try_call,
write_xattr,
write_xattr, update_url_query,
)

RESPONSE_READ_EXCEPTIONS = (
Expand Down Expand Up @@ -120,21 +120,23 @@ def establish_connection():
if try_call(lambda: range_end >= ctx.content_len):
range_end = ctx.content_len - 1

request = sanitized_Request(url, request_data, headers)
has_range = range_start is not None
if has_range:
request.add_header('Range', f'bytes={int(range_start)}-{int_or_none(range_end) or ""}')
request = sanitized_Request(url if not has_range else update_url_query(url, {'range': f'{int(range_start)}-{int_or_none(range_end) or ""}'}), request_data, headers)

# if has_range:
# request.add_header('Range', f'bytes={int(range_start)}-{int_or_none(range_end) or ""}')
# Establish connection
try:
total_length = int_or_none(self.ydl.urlopen(sanitized_Request(url, request_data, headers)).headers.get('Content-Length'))
ctx.data = self.ydl.urlopen(request)
# When trying to resume, Content-Range HTTP header of response has to be checked
# to match the value of requested Range HTTP header. This is due to a webservers
# that don't support resuming and serve a whole file with no Content-Range
# set in response despite of requested Range (see
# https://github.com/ytdl-org/youtube-dl/issues/6057#issuecomment-126129799)
if has_range:
content_range = ctx.data.headers.get('Content-Range')
content_range_start, content_range_end, content_len = parse_http_range(content_range)
# content_range = ctx.data.headers.get('Content-Range')
content_range_start, content_range_end, content_len = range_start, range_end, total_length
# Content-Range is present and matches requested Range, resume is possible
if range_start == content_range_start and (
# Non-chunked download
Expand Down

0 comments on commit 30ae589

Please sign in to comment.