[core] Re-work format_note display in format list with abbreviated codec name

master
dirkf 1 week ago
parent d0283f5385
commit d5f561166b

@ -2404,60 +2404,52 @@ class YoutubeDL(object):
return res return res
def _format_note(self, fdict): def _format_note(self, fdict):
res = ''
if fdict.get('ext') in ['f4f', 'f4m']: def simplified_codec(f, field):
res += '(unsupported) ' assert field in ('acodec', 'vcodec')
if fdict.get('language'): codec = f.get(field)
if res: return (
res += ' ' 'unknown' if not codec
res += '[%s] ' % fdict['language'] else '.'.join(codec.split('.')[:4]) if codec != 'none'
if fdict.get('format_note') is not None: else 'images' if field == 'vcodec' and f.get('acodec') == 'none'
res += fdict['format_note'] + ' ' else None if field == 'acodec' and f.get('vcodec') == 'none'
if fdict.get('tbr') is not None: else 'audio only' if field == 'vcodec'
res += '%4dk ' % fdict['tbr'] else 'video only')
res = join_nonempty(
fdict.get('ext') in ('f4f', 'f4m') and '(unsupported)',
fdict.get('language') and ('[%s]' % (fdict['language'],)),
fdict.get('format_note') is not None and fdict['format_note'],
fdict.get('tbr') is not None and ('%4dk' % fdict['tbr']),
delim=' ')
res = [res] if res else []
if fdict.get('container') is not None: if fdict.get('container') is not None:
if res: res.append('%s container' % (fdict['container'],))
res += ', ' if fdict.get('vcodec') not in (None, 'none'):
res += '%s container' % fdict['container'] codec = simplified_codec(fdict, 'vcodec')
if (fdict.get('vcodec') is not None if codec and fdict.get('vbr') is not None:
and fdict.get('vcodec') != 'none'): codec += '@'
if res:
res += ', '
res += fdict['vcodec']
if fdict.get('vbr') is not None:
res += '@'
elif fdict.get('vbr') is not None and fdict.get('abr') is not None: elif fdict.get('vbr') is not None and fdict.get('abr') is not None:
res += 'video@' codec = 'video@'
if fdict.get('vbr') is not None: else:
res += '%4dk' % fdict['vbr'] codec = None
codec = join_nonempty(codec, fdict.get('vbr') is not None and ('%4dk' % fdict['vbr']))
if codec:
res.append(codec)
if fdict.get('fps') is not None: if fdict.get('fps') is not None:
if res: res.append('%sfps' % (fdict['fps'],))
res += ', ' codec = (
res += '%sfps' % fdict['fps'] simplified_codec(fdict, 'acodec') if fdict.get('acodec') is not None
if fdict.get('acodec') is not None: else 'audio' if fdict.get('abr') is not None else None)
if res: if codec:
res += ', ' res.append(join_nonempty(
if fdict['acodec'] == 'none': '%-4s' % (codec + (('@%3dk' % fdict['abr']) if fdict.get('abr') else ''),),
res += 'video only' fdict.get('asr') and '(%5dHz)' % fdict['asr'], delim=' '))
else:
res += '%-5s' % fdict['acodec']
elif fdict.get('abr') is not None:
if res:
res += ', '
res += 'audio'
if fdict.get('abr') is not None:
res += '@%3dk' % fdict['abr']
if fdict.get('asr') is not None:
res += ' (%5dHz)' % fdict['asr']
if fdict.get('filesize') is not None: if fdict.get('filesize') is not None:
if res: res.append(format_bytes(fdict['filesize']))
res += ', '
res += format_bytes(fdict['filesize'])
elif fdict.get('filesize_approx') is not None: elif fdict.get('filesize_approx') is not None:
if res: res.append('~' + format_bytes(fdict['filesize_approx']))
res += ', ' return ', '.join(res)
res += '~' + format_bytes(fdict['filesize_approx'])
return res
def list_formats(self, info_dict): def list_formats(self, info_dict):
formats = info_dict.get('formats', [info_dict]) formats = info_dict.get('formats', [info_dict])

@ -1669,10 +1669,12 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'_rtmp': {'protocol': 'rtmp'}, '_rtmp': {'protocol': 'rtmp'},
# av01 video only formats sometimes served with "unknown" codecs # av01 video only formats sometimes served with "unknown" codecs
'394': {'acodec': 'none', 'vcodec': 'av01.0.05M.08'}, '394': {'acodec': 'none', 'vcodec': 'av01.0.00M.08'},
'395': {'acodec': 'none', 'vcodec': 'av01.0.05M.08'}, '395': {'acodec': 'none', 'vcodec': 'av01.0.00M.08'},
'396': {'acodec': 'none', 'vcodec': 'av01.0.05M.08'}, '396': {'acodec': 'none', 'vcodec': 'av01.0.01M.08'},
'397': {'acodec': 'none', 'vcodec': 'av01.0.05M.08'}, '397': {'acodec': 'none', 'vcodec': 'av01.0.04M.08'},
'398': {'acodec': 'none', 'vcodec': 'av01.0.05M.08'},
'399': {'acodec': 'none', 'vcodec': 'av01.0.08M.08'},
} }
_PLAYER_JS_VARIANT_MAP = ( _PLAYER_JS_VARIANT_MAP = (

Loading…
Cancel
Save