Support CTRL+C on URL downloads, use FAILED/STOPPED messages

This commit is contained in:
rlaphoenix 2023-03-01 09:31:58 +00:00
parent 6a65617179
commit 3a98c93f03

View File

@ -8,6 +8,7 @@ import re
import shutil import shutil
import sys import sys
import time import time
import traceback
from concurrent import futures from concurrent import futures
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from copy import deepcopy from copy import deepcopy
@ -756,34 +757,45 @@ class dl:
) )
# no else-if as DASH may convert the track to URL descriptor # no else-if as DASH may convert the track to URL descriptor
if track.descriptor == track.Descriptor.URL: if track.descriptor == track.Descriptor.URL:
if not track.drm and isinstance(track, (Video, Audio)): try:
# the service might not have explicitly defined the `drm` property if not track.drm and isinstance(track, (Video, Audio)):
# try find widevine DRM information from the init data of URL # the service might not have explicitly defined the `drm` property
try: # try find widevine DRM information from the init data of URL
drm = Widevine.from_track(track, service.session) try:
except Widevine.Exceptions.PSSHNotFound: drm = Widevine.from_track(track, service.session)
# it might not have Widevine DRM, or might not have found the PSSH except Widevine.Exceptions.PSSHNotFound:
self.log.warning("No Widevine PSSH was found for this track, is it DRM free?") # it might not have Widevine DRM, or might not have found the PSSH
else: self.log.warning("No Widevine PSSH was found for this track, is it DRM free?")
prepare_drm(drm) else:
track.drm = [drm] prepare_drm(drm)
track.drm = [drm]
aria2c( aria2c(
uri=track.url, uri=track.url,
out=save_path, out=save_path,
headers=service.session.headers, headers=service.session.headers,
proxy=proxy if track.needs_proxy else None, proxy=proxy if track.needs_proxy else None,
progress=progress progress=progress
) )
track.path = save_path track.path = save_path
if track.drm: if track.drm:
drm = track.drm[0] # just use the first supported DRM system for now drm = track.drm[0] # just use the first supported DRM system for now
drm.decrypt(save_path) drm.decrypt(save_path)
track.drm = None track.drm = None
if callable(track.OnDecrypted): if callable(track.OnDecrypted):
track.OnDecrypted(track) track.OnDecrypted(track)
except KeyboardInterrupt:
progress(downloaded="[yellow]STOPPED")
except Exception as e:
progress(downloaded="[red]FAILED")
traceback.print_exception(e)
self.log.error(f"URL Download worker threw an unhandled exception: {e!r}")
finally:
self.DL_POOL_STOP.set()
save_path.unlink(missing_ok=True)
save_path.with_suffix(f"{save_path.suffix}.aria2").unlink(missing_ok=True)
if self.DL_POOL_STOP.is_set(): if self.DL_POOL_STOP.is_set():
# we stopped during the download, let's exit # we stopped during the download, let's exit