Add a 5-attempt retry system to DASH & HLS downloads

This commit is contained in:
rlaphoenix 2023-03-11 19:26:51 +00:00
parent 111dac9264
commit 055bc927f5
2 changed files with 59 additions and 41 deletions

View File

@ -455,6 +455,9 @@ class DASH:
segment_uri, segment_range = segment
attempts = 1
while True:
try:
if segment_range:
# aria2(c) doesn't support byte ranges, let's use python-requests (likely slower)
r = session.get(
@ -474,6 +477,12 @@ class DASH:
proxy=proxy,
segmented=True
))
break
except Exception as ee:
if stop_event.is_set() or attempts == 5:
raise ee
time.sleep(2)
attempts += 1
data_size = segment_save_path.stat().st_size

View File

@ -283,6 +283,9 @@ class HLS:
if not segment.uri.startswith(segment.base_uri):
segment.uri = segment.base_uri + segment.uri
attempts = 1
while True:
try:
if segment.byterange:
# aria2(c) doesn't support byte ranges, let's use python-requests (likely slower)
previous_range_offset = range_offset.get()
@ -307,6 +310,12 @@ class HLS:
proxy=proxy,
segmented=True
))
break
except Exception as ee:
if stop_event.is_set() or attempts == 5:
raise ee
time.sleep(2)
attempts += 1
data_size = segment_save_path.stat().st_size