mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Add a way to interrupt video downloads
This commit is contained in:
parent
55771217e0
commit
43ce9b09f2
1 changed files with 7 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue