mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-18 06:55:07 +00:00
fix(dl): end a cancelled track by raising instead of returning short
This commit is contained in:
@@ -4,6 +4,16 @@ from typing import TypeVar, Union
|
||||
DOWNLOAD_CANCELLED = Event()
|
||||
DOWNLOAD_LICENCE_ONLY = Event()
|
||||
|
||||
|
||||
class DownloadCancelled(Exception):
|
||||
"""A track stopped because ``DOWNLOAD_CANCELLED`` was set, not because it itself failed.
|
||||
|
||||
The downloader raises this instead of returning short. A short return sends the track on
|
||||
to its merge or decrypt step, which then fails on the segments the cancel left behind.
|
||||
That fault hides the sibling failure that is the real error.
|
||||
"""
|
||||
|
||||
|
||||
DRM_SORT_MAP = ["ClearKey", "Widevine"]
|
||||
LANGUAGE_MAX_DISTANCE = 5 # this is max to be considered "same", e.g., en, en-US, en-AU
|
||||
LANGUAGE_EXACT_DISTANCE = 0 # exact match only, no variants
|
||||
|
||||
@@ -25,7 +25,7 @@ from requests import Session
|
||||
from requests.adapters import HTTPAdapter, Retry
|
||||
from rich import filesize
|
||||
|
||||
from unshackle.core.constants import DOWNLOAD_CANCELLED
|
||||
from unshackle.core.constants import DOWNLOAD_CANCELLED, DownloadCancelled
|
||||
from unshackle.core.utilities import get_debug_logger, get_extension
|
||||
|
||||
MAX_ATTEMPTS = 5
|
||||
@@ -1507,6 +1507,8 @@ def requests(
|
||||
processes=processes,
|
||||
debug_logger=debug_logger,
|
||||
)
|
||||
if DOWNLOAD_CANCELLED.is_set():
|
||||
raise DownloadCancelled()
|
||||
return
|
||||
if debug_logger:
|
||||
debug_logger.log(
|
||||
@@ -1903,6 +1905,9 @@ def requests(
|
||||
yield dict(advance=pending_advance)
|
||||
pending_advance = 0
|
||||
|
||||
if DOWNLOAD_CANCELLED.is_set():
|
||||
remaining.clear()
|
||||
|
||||
now = time.time()
|
||||
|
||||
target = max_workers
|
||||
@@ -2032,6 +2037,9 @@ def requests(
|
||||
download_speed = math.ceil(total_bytes / elapsed)
|
||||
yield dict(downloaded=f"{filesize.decimal(download_speed)}/s")
|
||||
|
||||
if DOWNLOAD_CANCELLED.is_set():
|
||||
raise DownloadCancelled()
|
||||
|
||||
if debug_logger:
|
||||
debug_logger.log(
|
||||
level="DEBUG",
|
||||
|
||||
@@ -21,7 +21,7 @@ from requests.adapters import HTTPAdapter, Retry
|
||||
from unshackle.core import binaries
|
||||
from unshackle.core.cdm.detect import is_playready_cdm, is_widevine_cdm
|
||||
from unshackle.core.config import config
|
||||
from unshackle.core.constants import DOWNLOAD_CANCELLED, DOWNLOAD_LICENCE_ONLY
|
||||
from unshackle.core.constants import DOWNLOAD_CANCELLED, DOWNLOAD_LICENCE_ONLY, DownloadCancelled
|
||||
from unshackle.core.downloaders import requests
|
||||
from unshackle.core.drm import DRM_T, ClearKeyCENC, PlayReady, Widevine
|
||||
from unshackle.core.events import events
|
||||
@@ -743,10 +743,19 @@ class Track:
|
||||
DOWNLOAD_CANCELLED.set()
|
||||
progress(downloaded="[yellow]CANCELLED")
|
||||
raise
|
||||
except DownloadCancelled:
|
||||
raise
|
||||
except Exception:
|
||||
DOWNLOAD_CANCELLED.set()
|
||||
progress(downloaded="[red]FAILED")
|
||||
raise
|
||||
except DownloadCancelled:
|
||||
try:
|
||||
cleanup()
|
||||
except OSError:
|
||||
pass
|
||||
progress(downloaded="[yellow]SKIPPED")
|
||||
return
|
||||
except (Exception, KeyboardInterrupt):
|
||||
if not DOWNLOAD_LICENCE_ONLY.is_set():
|
||||
cleanup()
|
||||
|
||||
Reference in New Issue
Block a user