1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00

Add a way to interrupt video downloads

This commit is contained in:
Steffo 2019-04-14 20:02:17 +02:00
parent 55771217e0
commit 43ce9b09f2

View file

@ -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)