1
0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-12-23 08:26:50 +00:00

Nicer --list-formats output

This commit is contained in:
Philipp Hagemeister 2013-10-28 11:31:12 +01:00
parent c1002e96e9
commit 8abeeb9449

View File

@ -757,23 +757,23 @@ class YoutubeDL(object):
archive_file.write(vid_id + u'\n') archive_file.write(vid_id + u'\n')
@staticmethod @staticmethod
def format_resolution(format): def format_resolution(format, default='unknown'):
if format.get('height') is not None: if format.get('height') is not None:
if format.get('width') is not None: if format.get('width') is not None:
res = u'%sx%s' % (format['width'], format['height']) res = u'%sx%s' % (format['width'], format['height'])
else: else:
res = u'%sp' % format['height'] res = u'%sp' % format['height']
else: else:
res = '???' res = default
return res return res
def list_formats(self, info_dict): def list_formats(self, info_dict):
formats_s = [] formats_s = []
for format in info_dict.get('formats', [info_dict]): for format in info_dict.get('formats', [info_dict]):
formats_s.append(u'%-15s: %-5s %-15s[%s]' % ( formats_s.append(u'%-15s%-7s %-15s%s' % (
format['format_id'], format['format_id'],
format['ext'], format['ext'],
format.get('format_note') or '-', format.get('format_note', ''),
self.format_resolution(format), self.format_resolution(format),
) )
) )