Clarify video/audio-only formats in -F

Related: #1759
This commit is contained in:
pukkandan 2021-11-23 20:38:30 +05:30
parent 57dbe8077f
commit ff51ed588f
No known key found for this signature in database
GPG Key ID: 0F00D95A001F4698

View File

@ -847,6 +847,7 @@ class YoutubeDL(object):
DELIM = 'blue'
ERROR = 'red'
WARNING = 'yellow'
SUPPRESS = 'light black'
def __format_text(self, out, text, f, fallback=None, *, test_encoding=False):
assert out in ('screen', 'err')
@ -3149,22 +3150,17 @@ class YoutubeDL(object):
@staticmethod
def format_resolution(format, default='unknown'):
is_images = format.get('vcodec') == 'none' and format.get('acodec') == 'none'
if format.get('vcodec') == 'none' and format.get('acodec') != 'none':
return 'audio only'
if format.get('resolution') is not None:
return format['resolution']
if format.get('width') and format.get('height'):
res = '%dx%d' % (format['width'], format['height'])
return '%dx%d' % (format['width'], format['height'])
elif format.get('height'):
res = '%sp' % format['height']
return '%sp' % format['height']
elif format.get('width'):
res = '%dx?' % format['width']
elif is_images:
return 'images'
else:
return '%dx?' % format['width']
return default
return f'img {res}' if is_images else res
def _format_note(self, fdict):
res = ''
@ -3236,7 +3232,7 @@ class YoutubeDL(object):
[
self._format_screen(format_field(f, 'format_id'), self.Styles.ID),
format_field(f, 'ext'),
self.format_resolution(f),
format_field(f, func=self.format_resolution, ignore=('audio only', 'images')),
format_field(f, 'fps', '\t%d'),
format_field(f, 'dynamic_range', '%s', ignore=(None, 'SDR')).replace('HDR', ''),
delim,
@ -3244,9 +3240,15 @@ class YoutubeDL(object):
format_field(f, 'tbr', '\t%dk'),
shorten_protocol_name(f.get('protocol', '').replace('native', 'n')),
delim,
format_field(f, 'vcodec', default='unknown').replace('none', ''),
format_field(f, 'vcodec', default='unknown').replace(
'none',
'images' if f.get('acodec') == 'none'
else self._format_screen('audio only', self.Styles.SUPPRESS)),
format_field(f, 'vbr', '\t%dk'),
format_field(f, 'acodec', default='unknown').replace('none', ''),
format_field(f, 'acodec', default='unknown').replace(
'none',
'' if f.get('vcodec') == 'none'
else self._format_screen('video only', self.Styles.SUPPRESS)),
format_field(f, 'abr', '\t%dk'),
format_field(f, 'asr', '\t%dHz'),
join_nonempty(