mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-10 09:07:58 +01:00
Handle "content too short" errors properly
This commit is contained in:
parent
488f619471
commit
d69a1c9189
1 changed files with 20 additions and 1 deletions
21
youtube-dl
21
youtube-dl
|
@ -58,6 +58,22 @@ class UnavailableFormatError(Exception):
|
||||||
This exception will be thrown when a video is requested
|
This exception will be thrown when a video is requested
|
||||||
in a format that is not available for that video.
|
in a format that is not available for that video.
|
||||||
"""
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
class ContentTooShortError(Exception):
|
||||||
|
"""Content Too Short exception.
|
||||||
|
|
||||||
|
This exception may be raised by FileDownloader objects when a file they
|
||||||
|
download is too small for what the server announced first, indicating
|
||||||
|
the connection was probably interrupted.
|
||||||
|
"""
|
||||||
|
# Both in bytes
|
||||||
|
downloaded = None
|
||||||
|
expected = None
|
||||||
|
|
||||||
|
def __init__(self, downloaded, expected):
|
||||||
|
self.downloaded = downloaded
|
||||||
|
self.expected = expected
|
||||||
|
|
||||||
class FileDownloader(object):
|
class FileDownloader(object):
|
||||||
"""File Downloader class.
|
"""File Downloader class.
|
||||||
|
@ -292,6 +308,9 @@ class FileDownloader(object):
|
||||||
except (urllib2.URLError, httplib.HTTPException, socket.error), err:
|
except (urllib2.URLError, httplib.HTTPException, socket.error), err:
|
||||||
self.trouble('ERROR: unable to download video data: %s' % str(err))
|
self.trouble('ERROR: unable to download video data: %s' % str(err))
|
||||||
return
|
return
|
||||||
|
except (ContentTooShortError, ), err:
|
||||||
|
self.trouble('ERROR: content too short (expected %s bytes and served %s)' % (err.expected, err.downloaded))
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.post_process(filename, info_dict)
|
self.post_process(filename, info_dict)
|
||||||
|
@ -365,7 +384,7 @@ class FileDownloader(object):
|
||||||
|
|
||||||
self.report_finish()
|
self.report_finish()
|
||||||
if data_len is not None and str(byte_counter) != data_len:
|
if data_len is not None and str(byte_counter) != data_len:
|
||||||
raise ValueError('Content too short: %s/%s bytes' % (byte_counter, data_len))
|
raise ContentTooShortError(byte_counter, long(data_len))
|
||||||
|
|
||||||
class InfoExtractor(object):
|
class InfoExtractor(object):
|
||||||
"""Information Extractor class.
|
"""Information Extractor class.
|
||||||
|
|
Loading…
Reference in a new issue