From f4ad7a2e6cb44824423eefc44f5bfd0f5b3c709b Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Tue, 28 Feb 2023 18:14:03 +0000 Subject: [PATCH] Mark track as stopping when skipping segments --- devine/core/manifests/dash.py | 37 ++++++++++++++++++----------------- devine/core/manifests/hls.py | 37 ++++++++++++++++++----------------- 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/devine/core/manifests/dash.py b/devine/core/manifests/dash.py index 57edcfe..5295d97 100644 --- a/devine/core/manifests/dash.py +++ b/devine/core/manifests/dash.py @@ -524,9 +524,6 @@ class DASH: download_size = download.result() except KeyboardInterrupt: stop_event.set() - if not has_stopped: - has_stopped = True - progress(downloaded="[orange]STOPPING") except Exception as e: stop_event.set() if has_stopped: @@ -537,24 +534,28 @@ class DASH: progress(downloaded="[red]FAILING") traceback.print_exception(e) log.error(f"Segment Download worker threw an unhandled exception: {e!r}") - else: - if stop_event.is_set(): - # skipped - continue - progress(advance=1) + continue - now = time.time() - time_since = now - last_speed_refresh + if stop_event.is_set(): + if not has_stopped: + has_stopped = True + progress(downloaded="[orange]STOPPING") + continue - if download_size: # no size == skipped dl - download_sizes.append(download_size) + progress(advance=1) - if time_since > 5 or finished_threads == len(segments): - data_size = sum(download_sizes) - download_speed = data_size / time_since - progress(downloaded=f"DASH {filesize.decimal(download_speed)}/s") - last_speed_refresh = now - download_sizes.clear() + now = time.time() + time_since = now - last_speed_refresh + + if download_size: # no size == skipped dl + download_sizes.append(download_size) + + if time_since > 5 or finished_threads == len(segments): + data_size = sum(download_sizes) + download_speed = data_size / time_since + progress(downloaded=f"DASH {filesize.decimal(download_speed)}/s") + last_speed_refresh = now + download_sizes.clear() if has_failed: progress(downloaded="[red]FAILED") if has_stopped: diff --git a/devine/core/manifests/hls.py b/devine/core/manifests/hls.py index b38beee..6d8eeaf 100644 --- a/devine/core/manifests/hls.py +++ b/devine/core/manifests/hls.py @@ -364,9 +364,6 @@ class HLS: download_size = download.result() except KeyboardInterrupt: stop_event.set() - if not has_stopped: - has_stopped = True - progress(downloaded="[orange]STOPPING") except Exception as e: stop_event.set() if has_stopped: @@ -377,24 +374,28 @@ class HLS: progress(downloaded="[red]FAILING") traceback.print_exception(e) log.error(f"Segment Download worker threw an unhandled exception: {e!r}") - else: - if stop_event.is_set(): - # skipped - continue - progress(advance=1) + continue - now = time.time() - time_since = now - last_speed_refresh + if stop_event.is_set(): + if not has_stopped: + has_stopped = True + progress(downloaded="[orange]STOPPING") + continue - if download_size: # no size == skipped dl - download_sizes.append(download_size) + progress(advance=1) - if time_since > 5 or finished_threads == len(master.segments): - data_size = sum(download_sizes) - download_speed = data_size / time_since - progress(downloaded=f"HLS {filesize.decimal(download_speed)}/s") - last_speed_refresh = now - download_sizes.clear() + now = time.time() + time_since = now - last_speed_refresh + + if download_size: # no size == skipped dl + download_sizes.append(download_size) + + if time_since > 5 or finished_threads == len(master.segments): + data_size = sum(download_sizes) + download_speed = data_size / time_since + progress(downloaded=f"HLS {filesize.decimal(download_speed)}/s") + last_speed_refresh = now + download_sizes.clear() if has_failed: progress(downloaded="[red]FAILED") if has_stopped: