aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/YoutubeDL.py
diff options
context:
space:
mode:
Diffstat (limited to 'youtube_dl/YoutubeDL.py')
-rw-r--r--youtube_dl/YoutubeDL.py32
1 files changed, 19 insertions, 13 deletions
diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py
index 313295839..7f73ea360 100644
--- a/youtube_dl/YoutubeDL.py
+++ b/youtube_dl/YoutubeDL.py
@@ -272,7 +272,7 @@ class YoutubeDL(object):
autonumber_size = 5
autonumber_templ = u'%0' + str(autonumber_size) + u'd'
template_dict['autonumber'] = autonumber_templ % self._num_downloads
- if template_dict['playlist_index'] is not None:
+ if template_dict.get('playlist_index') is not None:
template_dict['playlist_index'] = u'%05d' % template_dict['playlist_index']
sanitize = lambda k, v: sanitize_filename(
@@ -482,7 +482,7 @@ class YoutubeDL(object):
format['format'] = u'{id} - {res}{note}'.format(
id=format['format_id'],
res=self.format_resolution(format),
- note=u' ({})'.format(format['format_note']) if format.get('format_note') is not None else '',
+ note=u' ({0})'.format(format['format_note']) if format.get('format_note') is not None else '',
)
# Automatically determine file extension if missing
if 'ext' not in format:
@@ -759,6 +759,8 @@ class YoutubeDL(object):
@staticmethod
def format_resolution(format, default='unknown'):
+ if format.get('_resolution') is not None:
+ return format['_resolution']
if format.get('height') is not None:
if format.get('width') is not None:
res = u'%sx%s' % (format['width'], format['height'])
@@ -769,19 +771,23 @@ class YoutubeDL(object):
return res
def list_formats(self, info_dict):
- formats_s = []
- for format in info_dict.get('formats', [info_dict]):
- formats_s.append(u'%-15s%-7s %-15s%s' % (
+ def line(format):
+ return (u'%-15s%-10s%-12s%s' % (
format['format_id'],
format['ext'],
- format.get('format_note', ''),
self.format_resolution(format),
+ format.get('format_note', ''),
)
)
- if len(formats_s) != 1:
- formats_s[0] += ' (worst)'
- formats_s[-1] += ' (best)'
- formats_s = "\n".join(formats_s)
- self.to_screen(u'[info] Available formats for %s:\n'
- u'format code extension note resolution\n%s' % (
- info_dict['id'], formats_s))
+
+ formats = info_dict.get('formats', [info_dict])
+ formats_s = list(map(line, formats))
+ if len(formats) > 1:
+ formats_s[0] += (' ' if formats[0].get('format_note') else '') + '(worst)'
+ formats_s[-1] += (' ' if formats[-1].get('format_note') else '') + '(best)'
+
+ header_line = line({
+ 'format_id': u'format code', 'ext': u'extension',
+ '_resolution': u'resolution', 'format_note': u'note'})
+ self.to_screen(u'[info] Available formats for %s:\n%s\n%s' %
+ (info_dict['id'], header_line, u"\n".join(formats_s)))