mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-30 12:01:28 +00:00
[utils] Create DownloadCancelled
exception
as super-class of ExistingVideoReached, RejectedVideoReached, MaxDownloadsReached Third parties can also sub-class this to cancel the download queue from a hook
This commit is contained in:
parent
abad800058
commit
48f796874d
|
@ -56,6 +56,7 @@
|
||||||
DEFAULT_OUTTMPL,
|
DEFAULT_OUTTMPL,
|
||||||
determine_ext,
|
determine_ext,
|
||||||
determine_protocol,
|
determine_protocol,
|
||||||
|
DownloadCancelled,
|
||||||
DownloadError,
|
DownloadError,
|
||||||
encode_compat_str,
|
encode_compat_str,
|
||||||
encodeFilename,
|
encodeFilename,
|
||||||
|
@ -1320,7 +1321,7 @@ def wrapper(self, *args, **kwargs):
|
||||||
self.to_stderr('\r')
|
self.to_stderr('\r')
|
||||||
self.report_warning('The download speed is below throttle limit. Re-extracting data')
|
self.report_warning('The download speed is below throttle limit. Re-extracting data')
|
||||||
return wrapper(self, *args, **kwargs)
|
return wrapper(self, *args, **kwargs)
|
||||||
except (MaxDownloadsReached, ExistingVideoReached, RejectedVideoReached, LazyList.IndexError):
|
except (DownloadCancelled, LazyList.IndexError):
|
||||||
raise
|
raise
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if self.params.get('ignoreerrors'):
|
if self.params.get('ignoreerrors'):
|
||||||
|
@ -2949,14 +2950,8 @@ def download(self, url_list):
|
||||||
url, force_generic_extractor=self.params.get('force_generic_extractor', False))
|
url, force_generic_extractor=self.params.get('force_generic_extractor', False))
|
||||||
except UnavailableVideoError:
|
except UnavailableVideoError:
|
||||||
self.report_error('unable to download video')
|
self.report_error('unable to download video')
|
||||||
except MaxDownloadsReached:
|
except DownloadCancelled as e:
|
||||||
self.to_screen('[info] Maximum number of downloads reached')
|
self.to_screen(f'[info] {e.msg}')
|
||||||
raise
|
|
||||||
except ExistingVideoReached:
|
|
||||||
self.to_screen('[info] Encountered a video that is already in the archive, stopping due to --break-on-existing')
|
|
||||||
raise
|
|
||||||
except RejectedVideoReached:
|
|
||||||
self.to_screen('[info] Encountered a video that did not match filter, stopping due to --break-on-reject')
|
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
if self.params.get('dump_single_json', False):
|
if self.params.get('dump_single_json', False):
|
||||||
|
|
|
@ -2542,14 +2542,29 @@ def __init__(self, msg):
|
||||||
self.msg = msg
|
self.msg = msg
|
||||||
|
|
||||||
|
|
||||||
class ExistingVideoReached(YoutubeDLError):
|
class DownloadCancelled(YoutubeDLError):
|
||||||
""" --max-downloads limit has been reached. """
|
""" Exception raised when the download queue should be interrupted """
|
||||||
pass
|
msg = 'The download was cancelled'
|
||||||
|
|
||||||
|
def __init__(self, msg=None):
|
||||||
|
if msg is not None:
|
||||||
|
self.msg = msg
|
||||||
|
YoutubeDLError.__init__(self, self.msg)
|
||||||
|
|
||||||
|
|
||||||
class RejectedVideoReached(YoutubeDLError):
|
class ExistingVideoReached(DownloadCancelled):
|
||||||
|
""" --break-on-existing triggered """
|
||||||
|
msg = 'Encountered a video that is already in the archive, stopping due to --break-on-existing'
|
||||||
|
|
||||||
|
|
||||||
|
class RejectedVideoReached(DownloadCancelled):
|
||||||
|
""" --break-on-reject triggered """
|
||||||
|
msg = 'Encountered a video that did not match filter, stopping due to --break-on-reject'
|
||||||
|
|
||||||
|
|
||||||
|
class MaxDownloadsReached(DownloadCancelled):
|
||||||
""" --max-downloads limit has been reached. """
|
""" --max-downloads limit has been reached. """
|
||||||
pass
|
msg = 'Maximum number of downloads reached, stopping due to --max-downloads'
|
||||||
|
|
||||||
|
|
||||||
class ThrottledDownload(YoutubeDLError):
|
class ThrottledDownload(YoutubeDLError):
|
||||||
|
@ -2557,11 +2572,6 @@ class ThrottledDownload(YoutubeDLError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class MaxDownloadsReached(YoutubeDLError):
|
|
||||||
""" --max-downloads limit has been reached. """
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class UnavailableVideoError(YoutubeDLError):
|
class UnavailableVideoError(YoutubeDLError):
|
||||||
"""Unavailable Format exception.
|
"""Unavailable Format exception.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue