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