From 43ce9b09f228db79e8b14e2e8c81eb23e271b3d0 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 14 Apr 2019 20:02:17 +0200 Subject: [PATCH] Add a way to interrupt video downloads --- royalnet/audio/youtubedl.py | 7 +++++++ 1 file changed, 7 insertions(+) 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)