aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Garcia <sarbalap+freshmeat@gmail.com>2009-05-21 20:59:02 +0200
committerRicardo Garcia <sarbalap+freshmeat@gmail.com>2010-10-31 11:24:19 +0100
commitd69a1c9189311997ef7c311296e71b4c8fbdab41 (patch)
treefd6111d8d7c0b4a69a2cfb27efb3015d56f82837
parent488f6194718cf882344d113052bc85662a638f54 (diff)
downloadyoutube-dl-d69a1c9189311997ef7c311296e71b4c8fbdab41.tar.xz
Handle "content too short" errors properly
-rwxr-xr-xyoutube-dl21
1 files changed, 20 insertions, 1 deletions
diff --git a/youtube-dl b/youtube-dl
index ec4c9b89c..f6e472445 100755
--- a/youtube-dl
+++ b/youtube-dl
@@ -58,6 +58,22 @@ class UnavailableFormatError(Exception):
This exception will be thrown when a video is requested
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):
"""File Downloader class.
@@ -292,6 +308,9 @@ class FileDownloader(object):
except (urllib2.URLError, httplib.HTTPException, socket.error), err:
self.trouble('ERROR: unable to download video data: %s' % str(err))
return
+ except (ContentTooShortError, ), err:
+ self.trouble('ERROR: content too short (expected %s bytes and served %s)' % (err.expected, err.downloaded))
+ return
try:
self.post_process(filename, info_dict)
@@ -365,7 +384,7 @@ class FileDownloader(object):
self.report_finish()
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):
"""Information Extractor class.