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,6 +757,7 @@ 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:
try:
if not track.drm and isinstance(track, (Video, Audio)): if not track.drm and isinstance(track, (Video, Audio)):
# the service might not have explicitly defined the `drm` property # the service might not have explicitly defined the `drm` property
# try find widevine DRM information from the init data of URL # try find widevine DRM information from the init data of URL
@ -784,6 +786,16 @@ class dl:
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