From 60073843ba7862f532c5d43bd25b8065514214da Mon Sep 17 00:00:00 2001 From: Pierre Mdawar Date: Mon, 17 Oct 2016 14:38:37 +0300 Subject: [PATCH 1/3] [utils] added YoutubeDLError superclass for all the exceptions --- youtube_dl/utils.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 0569d231c..215f10514 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -675,7 +675,12 @@ def bug_reports_message(): return msg -class ExtractorError(Exception): +class YoutubeDLError(Exception): + """Base exception for YoutubeDL errors.""" + pass + + +class ExtractorError(YoutubeDLError): """Error during info extraction.""" def __init__(self, msg, tb=None, expected=False, cause=None, video_id=None): @@ -716,7 +721,7 @@ class RegexNotFoundError(ExtractorError): pass -class DownloadError(Exception): +class DownloadError(YoutubeDLError): """Download Error exception. This exception may be thrown by FileDownloader objects if they are not @@ -730,7 +735,7 @@ class DownloadError(Exception): self.exc_info = exc_info -class SameFileError(Exception): +class SameFileError(YoutubeDLError): """Same File exception. This exception will be thrown by FileDownloader objects if they detect @@ -739,7 +744,7 @@ class SameFileError(Exception): pass -class PostProcessingError(Exception): +class PostProcessingError(YoutubeDLError): """Post Processing exception. This exception may be raised by PostProcessor's .run() method to @@ -750,12 +755,12 @@ class PostProcessingError(Exception): self.msg = msg -class MaxDownloadsReached(Exception): +class MaxDownloadsReached(YoutubeDLError): """ --max-downloads limit has been reached. """ pass -class UnavailableVideoError(Exception): +class UnavailableVideoError(YoutubeDLError): """Unavailable Format exception. This exception will be thrown when a video is requested @@ -764,7 +769,7 @@ class UnavailableVideoError(Exception): pass -class ContentTooShortError(Exception): +class ContentTooShortError(YoutubeDLError): """Content Too Short exception. This exception may be raised by FileDownloader objects when a file they @@ -778,7 +783,7 @@ class ContentTooShortError(Exception): self.expected = expected -class XAttrMetadataError(Exception): +class XAttrMetadataError(YoutubeDLError): def __init__(self, code=None, msg='Unknown error'): super(XAttrMetadataError, self).__init__(msg) self.code = code @@ -794,7 +799,7 @@ class XAttrMetadataError(Exception): self.reason = 'NOT_SUPPORTED' -class XAttrUnavailableError(Exception): +class XAttrUnavailableError(YoutubeDLError): pass From 9bf04c92d3b992bd54980abf68fa8331abfa3847 Mon Sep 17 00:00:00 2001 From: Pierre Mdawar Date: Mon, 17 Oct 2016 14:48:47 +0300 Subject: [PATCH 2/3] [utils] initialize exceptions properly by calling the superclass __init__ --- youtube_dl/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 215f10514..fe73cc11c 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -752,6 +752,7 @@ class PostProcessingError(YoutubeDLError): """ def __init__(self, msg): + super(PostProcessingError, self).__init__(msg) self.msg = msg @@ -778,6 +779,9 @@ class ContentTooShortError(YoutubeDLError): """ def __init__(self, downloaded, expected): + super(ContentTooShortError, self).__init__( + 'Downloaded {} bytes, expected {} bytes'.format(downloaded, expected) + ) # Both in bytes self.downloaded = downloaded self.expected = expected From 5cdff4dc2aa3825082640cfe72ce3e7b978734f3 Mon Sep 17 00:00:00 2001 From: Pierre Mdawar Date: Mon, 17 Oct 2016 19:18:29 +0300 Subject: [PATCH 3/3] [utils] added explicit string formatting indexes to support Python 2.6 --- youtube_dl/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index fe73cc11c..d7d614afc 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -780,7 +780,7 @@ class ContentTooShortError(YoutubeDLError): def __init__(self, downloaded, expected): super(ContentTooShortError, self).__init__( - 'Downloaded {} bytes, expected {} bytes'.format(downloaded, expected) + 'Downloaded {0} bytes, expected {1} bytes'.format(downloaded, expected) ) # Both in bytes self.downloaded = downloaded