From e8e3d4a90fce89baf6e3504d1a748a63f93f5b6a Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Tue, 9 Jan 2024 13:00:39 +0000 Subject: [PATCH] Remove 5-attempt loop from DASH and HLS Downloads These are unnecessary now as all downloaders have retry functionality built-in. --- devine/core/manifests/dash.py | 40 ++++++++++++------------------ devine/core/manifests/hls.py | 46 +++++++++++++++-------------------- 2 files changed, 35 insertions(+), 51 deletions(-) diff --git a/devine/core/manifests/dash.py b/devine/core/manifests/dash.py index 07417e5..adc2f01 100644 --- a/devine/core/manifests/dash.py +++ b/devine/core/manifests/dash.py @@ -519,30 +519,22 @@ class DASH: if DOWNLOAD_CANCELLED.is_set(): raise KeyboardInterrupt() - attempts = 1 - while True: - try: - if bytes_range: - # aria2(c) doesn't support byte ranges, use python-requests - downloader_ = requests_downloader - headers_ = dict(**headers, Range=f"bytes={bytes_range}") - else: - downloader_ = downloader - headers_ = headers - downloader_( - uri=url, - out=out_path, - headers=headers_, - cookies=cookies, - proxy=proxy, - segmented=True - ) - break - except Exception as e: - if DOWNLOAD_CANCELLED.is_set() or attempts == 5: - raise e - time.sleep(2) - attempts += 1 + if bytes_range: + # aria2(c) doesn't support byte ranges, use python-requests + downloader_ = requests_downloader + headers_ = dict(**headers, Range=f"bytes={bytes_range}") + else: + downloader_ = downloader + headers_ = headers + + downloader_( + uri=url, + out=out_path, + headers=headers_, + cookies=cookies, + proxy=proxy, + segmented=True + ) # fix audio decryption on ATVP by fixing the sample description index # TODO: Should this be done in the video data or the init data? diff --git a/devine/core/manifests/hls.py b/devine/core/manifests/hls.py index 70960d2..6ba9b2c 100644 --- a/devine/core/manifests/hls.py +++ b/devine/core/manifests/hls.py @@ -422,33 +422,25 @@ class HLS: if DOWNLOAD_LICENCE_ONLY.is_set(): return -1 - attempts = 1 - while True: - try: - headers_ = session.headers - if segment.byterange: - # aria2(c) doesn't support byte ranges, use python-requests - downloader_ = requests_downloader - previous_range_offset = range_offset.get() - byte_range = HLS.calculate_byte_range(segment.byterange, previous_range_offset) - range_offset.put(byte_range.split("-")[0]) - headers_["Range"] = f"bytes={byte_range}" - else: - downloader_ = downloader - downloader_( - uri=urljoin(segment.base_uri, segment.uri), - out=out_path, - headers=headers_, - cookies=session.cookies, - proxy=proxy, - segmented=True - ) - break - except Exception as e: - if DOWNLOAD_CANCELLED.is_set() or attempts == 5: - raise e - time.sleep(2) - attempts += 1 + headers_ = session.headers + if segment.byterange: + # aria2(c) doesn't support byte ranges, use python-requests + downloader_ = requests_downloader + previous_range_offset = range_offset.get() + byte_range = HLS.calculate_byte_range(segment.byterange, previous_range_offset) + range_offset.put(byte_range.split("-")[0]) + headers_["Range"] = f"bytes={byte_range}" + else: + downloader_ = downloader + + downloader_( + uri=urljoin(segment.base_uri, segment.uri), + out=out_path, + headers=headers_, + cookies=session.cookies, + proxy=proxy, + segmented=True + ) download_size = out_path.stat().st_size