diff --git a/royalnet/audio/youtubedl.py b/royalnet/audio/youtubedl.py index 3d371a1b..bb029886 100644 --- a/royalnet/audio/youtubedl.py +++ b/royalnet/audio/youtubedl.py @@ -10,6 +10,10 @@ class DownloaderError(Exception): pass +class InterruptDownload(DownloaderError): + """Raised from a progress_hook to interrupt the video download.""" + + class YtdlFile: """A wrapper around a youtube_dl downloaded file.""" def __init__(self, info: "YtdlInfo", outtmpl="%(title)s-%(id)s.%(ext)s", progress_hooks=None, **ytdl_args): @@ -44,6 +48,9 @@ class YtdlFile: self.downloaded_bytes = data.get("downloaded_bytes") self.elapsed = data.get("elapsed") + def _stop_download(self): + raise InterruptDownload() + @staticmethod def create_from_url(url, outtmpl="%(title)s-%(id)s.%(ext)s", progress_hooks=None, **ytdl_args) -> typing.List["YtdlFile"]: info_list = YtdlInfo.create_from_url(url)