mirror of
https://github.com/ytdl-org/youtube-dl
synced 2025-12-04 10:33:48 +00:00
[core] Re-work format_note display in format list with abbreviated codec name
This commit is contained in:
parent
d0283f5385
commit
d5f561166b
@ -2404,60 +2404,52 @@ class YoutubeDL(object):
|
||||
return res
|
||||
|
||||
def _format_note(self, fdict):
|
||||
res = ''
|
||||
if fdict.get('ext') in ['f4f', 'f4m']:
|
||||
res += '(unsupported) '
|
||||
if fdict.get('language'):
|
||||
if res:
|
||||
res += ' '
|
||||
res += '[%s] ' % fdict['language']
|
||||
if fdict.get('format_note') is not None:
|
||||
res += fdict['format_note'] + ' '
|
||||
if fdict.get('tbr') is not None:
|
||||
res += '%4dk ' % fdict['tbr']
|
||||
|
||||
def simplified_codec(f, field):
|
||||
assert field in ('acodec', 'vcodec')
|
||||
codec = f.get(field)
|
||||
return (
|
||||
'unknown' if not codec
|
||||
else '.'.join(codec.split('.')[:4]) if codec != 'none'
|
||||
else 'images' if field == 'vcodec' and f.get('acodec') == 'none'
|
||||
else None if field == 'acodec' and f.get('vcodec') == 'none'
|
||||
else 'audio only' if field == 'vcodec'
|
||||
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 res:
|
||||
res += ', '
|
||||
res += '%s container' % fdict['container']
|
||||
if (fdict.get('vcodec') is not None
|
||||
and fdict.get('vcodec') != 'none'):
|
||||
if res:
|
||||
res += ', '
|
||||
res += fdict['vcodec']
|
||||
if fdict.get('vbr') is not None:
|
||||
res += '@'
|
||||
res.append('%s container' % (fdict['container'],))
|
||||
if fdict.get('vcodec') not in (None, 'none'):
|
||||
codec = simplified_codec(fdict, 'vcodec')
|
||||
if codec and fdict.get('vbr') is not None:
|
||||
codec += '@'
|
||||
elif fdict.get('vbr') is not None and fdict.get('abr') is not None:
|
||||
res += 'video@'
|
||||
if fdict.get('vbr') is not None:
|
||||
res += '%4dk' % fdict['vbr']
|
||||
codec = 'video@'
|
||||
else:
|
||||
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 res:
|
||||
res += ', '
|
||||
res += '%sfps' % fdict['fps']
|
||||
if fdict.get('acodec') is not None:
|
||||
if res:
|
||||
res += ', '
|
||||
if fdict['acodec'] == 'none':
|
||||
res += 'video only'
|
||||
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']
|
||||
res.append('%sfps' % (fdict['fps'],))
|
||||
codec = (
|
||||
simplified_codec(fdict, 'acodec') if fdict.get('acodec') is not None
|
||||
else 'audio' if fdict.get('abr') is not None else None)
|
||||
if codec:
|
||||
res.append(join_nonempty(
|
||||
'%-4s' % (codec + (('@%3dk' % fdict['abr']) if fdict.get('abr') else ''),),
|
||||
fdict.get('asr') and '(%5dHz)' % fdict['asr'], delim=' '))
|
||||
if fdict.get('filesize') is not None:
|
||||
if res:
|
||||
res += ', '
|
||||
res += format_bytes(fdict['filesize'])
|
||||
res.append(format_bytes(fdict['filesize']))
|
||||
elif fdict.get('filesize_approx') is not None:
|
||||
if res:
|
||||
res += ', '
|
||||
res += '~' + format_bytes(fdict['filesize_approx'])
|
||||
return res
|
||||
res.append('~' + format_bytes(fdict['filesize_approx']))
|
||||
return ', '.join(res)
|
||||
|
||||
def list_formats(self, info_dict):
|
||||
formats = info_dict.get('formats', [info_dict])
|
||||
|
||||
@ -1669,10 +1669,12 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
||||
'_rtmp': {'protocol': 'rtmp'},
|
||||
|
||||
# av01 video only formats sometimes served with "unknown" codecs
|
||||
'394': {'acodec': 'none', 'vcodec': 'av01.0.05M.08'},
|
||||
'395': {'acodec': 'none', 'vcodec': 'av01.0.05M.08'},
|
||||
'396': {'acodec': 'none', 'vcodec': 'av01.0.05M.08'},
|
||||
'397': {'acodec': 'none', 'vcodec': 'av01.0.05M.08'},
|
||||
'394': {'acodec': 'none', 'vcodec': 'av01.0.00M.08'},
|
||||
'395': {'acodec': 'none', 'vcodec': 'av01.0.00M.08'},
|
||||
'396': {'acodec': 'none', 'vcodec': 'av01.0.01M.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 = (
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user