[downloader/fragment] Fix bugs around resuming with Range (#2901)

Authored by: Lesmiscore
This commit is contained in:
Lesmiscore (Naoya Ozaki) 2022-02-28 13:10:54 +09:00 committed by GitHub
parent 195c22840c
commit 93c8410d33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 19 deletions

View file

@ -5252,6 +5252,16 @@ def join_nonempty(*values, delim='-', from_dict=None):
return delim.join(map(str, filter(None, values)))
def parse_http_range(range):
""" Parse value of "Range" or "Content-Range" HTTP header into tuple. """
if not range:
return None, None, None
crg = re.search(r'bytes[ =](\d+)-(\d+)?(?:/(\d+))?', range)
if not crg:
return None, None, None
return int(crg.group(1)), int_or_none(crg.group(2)), int_or_none(crg.group(3))
class Config:
own_args = None
filename = None