X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=youtube-dl;h=f6e472445d8e0d9512805487a04afc88bcc68662;hb=781daeabdb6ffa2b63bf8f7dec715ac8835c558b;hp=08afab4f801e4d84c86e6285bada64a53c241d8e;hpb=43f35682e9cf509459097e6fdebe2f10c95094f1;p=youtube-dl.git diff --git a/youtube-dl b/youtube-dl index 08afab4f8..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. @@ -286,11 +302,15 @@ class FileDownloader(object): self._do_download(outstream, info_dict['url']) outstream.close() except (OSError, IOError), err: + outstream.close() os.remove(filename) raise UnavailableFormatError 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) @@ -364,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. @@ -996,7 +1016,7 @@ if __name__ == '__main__': # Parse command line parser = optparse.OptionParser( usage='Usage: %prog [options] url...', - version='2009.05.11', + version='INTERNAL', conflict_handler='resolve', ) @@ -1022,11 +1042,11 @@ if __name__ == '__main__': video_format.add_option('-f', '--format', action='append', dest='format', metavar='FMT', help='video format code') video_format.add_option('-b', '--best-quality', - action='append_const', dest='format', help='download the best quality video possible', const='0') + action='store_const', dest='format', help='download the best quality video possible', const='0') video_format.add_option('-m', '--mobile-version', - action='append_const', dest='format', help='alias for -f 17', const='17') + action='store_const', dest='format', help='alias for -f 17', const='17') video_format.add_option('-d', '--high-def', - action='append_const', dest='format', help='alias for -f 22', const='22') + action='store_const', dest='format', help='alias for -f 22', const='22') parser.add_option_group(video_format) verbosity = optparse.OptionGroup(parser, 'Verbosity / Simulation Options')