Remove 5-attempt loop from DASH and HLS Downloads

These are unnecessary now as all downloaders have retry functionality built-in.
This commit is contained in:
rlaphoenix 2024-01-09 13:00:39 +00:00
parent cc4900a2ed
commit e8e3d4a90f
2 changed files with 35 additions and 51 deletions

View File

@ -519,30 +519,22 @@ class DASH:
if DOWNLOAD_CANCELLED.is_set(): if DOWNLOAD_CANCELLED.is_set():
raise KeyboardInterrupt() raise KeyboardInterrupt()
attempts = 1 if bytes_range:
while True: # aria2(c) doesn't support byte ranges, use python-requests
try: downloader_ = requests_downloader
if bytes_range: headers_ = dict(**headers, Range=f"bytes={bytes_range}")
# aria2(c) doesn't support byte ranges, use python-requests else:
downloader_ = requests_downloader downloader_ = downloader
headers_ = dict(**headers, Range=f"bytes={bytes_range}") headers_ = headers
else:
downloader_ = downloader downloader_(
headers_ = headers uri=url,
downloader_( out=out_path,
uri=url, headers=headers_,
out=out_path, cookies=cookies,
headers=headers_, proxy=proxy,
cookies=cookies, segmented=True
proxy=proxy, )
segmented=True
)
break
except Exception as e:
if DOWNLOAD_CANCELLED.is_set() or attempts == 5:
raise e
time.sleep(2)
attempts += 1
# fix audio decryption on ATVP by fixing the sample description index # fix audio decryption on ATVP by fixing the sample description index
# TODO: Should this be done in the video data or the init data? # TODO: Should this be done in the video data or the init data?

View File

@ -422,33 +422,25 @@ class HLS:
if DOWNLOAD_LICENCE_ONLY.is_set(): if DOWNLOAD_LICENCE_ONLY.is_set():
return -1 return -1
attempts = 1 headers_ = session.headers
while True: if segment.byterange:
try: # aria2(c) doesn't support byte ranges, use python-requests
headers_ = session.headers downloader_ = requests_downloader
if segment.byterange: previous_range_offset = range_offset.get()
# aria2(c) doesn't support byte ranges, use python-requests byte_range = HLS.calculate_byte_range(segment.byterange, previous_range_offset)
downloader_ = requests_downloader range_offset.put(byte_range.split("-")[0])
previous_range_offset = range_offset.get() headers_["Range"] = f"bytes={byte_range}"
byte_range = HLS.calculate_byte_range(segment.byterange, previous_range_offset) else:
range_offset.put(byte_range.split("-")[0]) downloader_ = downloader
headers_["Range"] = f"bytes={byte_range}"
else: downloader_(
downloader_ = downloader uri=urljoin(segment.base_uri, segment.uri),
downloader_( out=out_path,
uri=urljoin(segment.base_uri, segment.uri), headers=headers_,
out=out_path, cookies=session.cookies,
headers=headers_, proxy=proxy,
cookies=session.cookies, segmented=True
proxy=proxy, )
segmented=True
)
break
except Exception as e:
if DOWNLOAD_CANCELLED.is_set() or attempts == 5:
raise e
time.sleep(2)
attempts += 1
download_size = out_path.stat().st_size download_size = out_path.stat().st_size