1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-11-26 10:24:33 +01:00

Added --all-format option from tweaked patch (fixes issue #102)

This commit is contained in:
Ricardo Garcia 2010-03-19 18:15:43 +01:00
parent 131bc7651a
commit 6ba562b0e4

View File

@ -593,6 +593,7 @@ class InfoExtractor(object):
title: Literal title. title: Literal title.
stitle: Simplified title. stitle: Simplified title.
ext: Video filename extension. ext: Video filename extension.
format: Video format.
Subclasses of this one should re-define the _real_initialize() and Subclasses of this one should re-define the _real_initialize() and
_real_extract() methods, as well as the suitable() static method. _real_extract() methods, as well as the suitable() static method.
@ -764,6 +765,7 @@ class YoutubeIE(InfoExtractor):
# Downloader parameters # Downloader parameters
best_quality = False best_quality = False
all_formats = False
format_param = None format_param = None
quality_index = 0 quality_index = 0
if self._downloader is not None: if self._downloader is not None:
@ -772,6 +774,9 @@ class YoutubeIE(InfoExtractor):
if format_param == '0': if format_param == '0':
format_param = self._available_formats[quality_index] format_param = self._available_formats[quality_index]
best_quality = True best_quality = True
elif format_param == '-1':
format_param = self._available_formats[quality_index]
all_formats = True
while True: while True:
# Extension # Extension
@ -838,20 +843,35 @@ class YoutubeIE(InfoExtractor):
'title': video_title, 'title': video_title,
'stitle': simple_title, 'stitle': simple_title,
'ext': video_extension.decode('utf-8'), 'ext': video_extension.decode('utf-8'),
'format': (format_param is None and u'NA' or format_param.decode('utf-8')),
}) })
if all_formats:
if quality_index == len(self._available_formats) - 1:
# None left to get
return
else:
quality_index += 1
format_param = self._available_formats[quality_index]
if format_param == None:
return
continue
return return
except UnavailableFormatError, err: except UnavailableFormatError, err:
if best_quality: if best_quality or all_formats:
if quality_index == len(self._available_formats) - 1: if quality_index == len(self._available_formats) - 1:
# I don't ever expect this to happen # I don't ever expect this to happen
self._downloader.trouble(u'ERROR: no known formats available for video') if not all_formats:
self._downloader.trouble(u'ERROR: no known formats available for video')
return return
else: else:
self.report_unavailable_format(video_id, format_param) self.report_unavailable_format(video_id, format_param)
quality_index += 1 quality_index += 1
format_param = self._available_formats[quality_index] format_param = self._available_formats[quality_index]
if format_param == None:
return
continue continue
else: else:
self._downloader.trouble('ERROR: format not available for video') self._downloader.trouble('ERROR: format not available for video')
@ -980,6 +1000,7 @@ class MetacafeIE(InfoExtractor):
'title': video_title, 'title': video_title,
'stitle': simple_title, 'stitle': simple_title,
'ext': video_extension.decode('utf-8'), 'ext': video_extension.decode('utf-8'),
'format': u'NA',
}) })
except UnavailableFormatError: except UnavailableFormatError:
self._downloader.trouble(u'ERROR: format not available for video') self._downloader.trouble(u'ERROR: format not available for video')
@ -1051,18 +1072,16 @@ class GoogleIE(InfoExtractor):
video_title = sanitize_title(video_title) video_title = sanitize_title(video_title)
simple_title = re.sub(ur'(?u)([^%s]+)' % simple_title_chars, ur'_', video_title) simple_title = re.sub(ur'(?u)([^%s]+)' % simple_title_chars, ur'_', video_title)
# Google Video doesn't show uploader nicknames?
video_uploader = 'NA'
try: try:
# Process video information # Process video information
self._downloader.process_info({ self._downloader.process_info({
'id': video_id.decode('utf-8'), 'id': video_id.decode('utf-8'),
'url': video_url.decode('utf-8'), 'url': video_url.decode('utf-8'),
'uploader': video_uploader.decode('utf-8'), 'uploader': u'NA',
'title': video_title, 'title': video_title,
'stitle': simple_title, 'stitle': simple_title,
'ext': video_extension.decode('utf-8'), 'ext': video_extension.decode('utf-8'),
'format': u'NA',
}) })
except UnavailableFormatError: except UnavailableFormatError:
self._downloader.trouble(u'ERROR: format not available for video') self._downloader.trouble(u'ERROR: format not available for video')
@ -1140,6 +1159,7 @@ class PhotobucketIE(InfoExtractor):
'title': video_title, 'title': video_title,
'stitle': simple_title, 'stitle': simple_title,
'ext': video_extension.decode('utf-8'), 'ext': video_extension.decode('utf-8'),
'format': u'NA',
}) })
except UnavailableFormatError: except UnavailableFormatError:
self._downloader.trouble(u'ERROR: format not available for video') self._downloader.trouble(u'ERROR: format not available for video')
@ -1234,6 +1254,7 @@ class GenericIE(InfoExtractor):
'title': video_title, 'title': video_title,
'stitle': simple_title, 'stitle': simple_title,
'ext': video_extension.decode('utf-8'), 'ext': video_extension.decode('utf-8'),
'format': u'NA',
}) })
except UnavailableFormatError: except UnavailableFormatError:
self._downloader.trouble(u'ERROR: format not available for video') self._downloader.trouble(u'ERROR: format not available for video')
@ -1555,6 +1576,8 @@ if __name__ == '__main__':
action='store_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', video_format.add_option('-d', '--high-def',
action='store_const', dest='format', help='alias for -f 22', const='22') action='store_const', dest='format', help='alias for -f 22', const='22')
video_format.add_option('--all-formats',
action='store_const', dest='format', help='download all available video formats', const='-1')
parser.add_option_group(video_format) parser.add_option_group(video_format)
verbosity = optparse.OptionGroup(parser, 'Verbosity / Simulation Options') verbosity = optparse.OptionGroup(parser, 'Verbosity / Simulation Options')
@ -1636,6 +1659,9 @@ if __name__ == '__main__':
'simulate': (opts.simulate or opts.geturl or opts.gettitle), 'simulate': (opts.simulate or opts.geturl or opts.gettitle),
'format': opts.format, 'format': opts.format,
'outtmpl': ((opts.outtmpl is not None and opts.outtmpl.decode(preferredencoding())) 'outtmpl': ((opts.outtmpl is not None and opts.outtmpl.decode(preferredencoding()))
or (opts.format == '-1' and opts.usetitle and u'%(stitle)s-%(id)s-%(format)s.%(ext)s')
or (opts.format == '-1' and opts.useliteral and u'%(title)s-%(id)s-%(format)s.%(ext)s')
or (opts.format == '-1' and u'%(id)s-%(format)s.%(ext)s')
or (opts.usetitle and u'%(stitle)s-%(id)s.%(ext)s') or (opts.usetitle and u'%(stitle)s-%(id)s.%(ext)s')
or (opts.useliteral and u'%(title)s-%(id)s.%(ext)s') or (opts.useliteral and u'%(title)s-%(id)s.%(ext)s')
or u'%(id)s.%(ext)s'), or u'%(id)s.%(ext)s'),