mirror of
https://github.com/l1ving/youtube-dl
synced 2025-02-13 06:32:51 +08:00
Split 'has_video' and 'has_audio' from 'preference'
And remove "_preference" from the field names
This commit is contained in:
parent
3cf88b02e9
commit
f0300b7661
@ -1368,16 +1368,15 @@ class InfoExtractor(object):
|
|||||||
|
|
||||||
return (tuple()
|
return (tuple()
|
||||||
if self._downloader.params.get('format_sort_force')
|
if self._downloader.params.get('format_sort_force')
|
||||||
else ('preference', 'language_preference')) + \
|
else ('avoid_bad', 'has_video', 'has_audio', 'extractor', 'language')) + \
|
||||||
tuple(sort) + \
|
tuple(sort) + \
|
||||||
(tuple(field_preference)
|
(tuple(field_preference)
|
||||||
if isinstance(field_preference, (list, tuple))
|
if isinstance(field_preference, (list, tuple))
|
||||||
else tuple()) + \
|
else tuple()) + \
|
||||||
('preference', 'language_preference', 'quality', # default order
|
('avoid_bad', 'has_video', 'has_audio', 'extractor', 'language', 'quality', # default order
|
||||||
'tbr', 'filesize', 'vbr', 'height', 'width',
|
'tbr', 'filesize', 'vbr', 'height', 'width',
|
||||||
'proto_preference', 'ext_preference', 'codec_preference',
|
'proto', 'ext', 'codec', 'abr', 'audio_ext', 'audio_codec',
|
||||||
'abr', 'audio_ext_preference', 'audio_codec_preference',
|
'fps', 'filesize_approx', 'source', 'format_id')
|
||||||
'fps', 'filesize_approx', 'source_preference', 'format_id')
|
|
||||||
|
|
||||||
sort = {}
|
sort = {}
|
||||||
for item in _get_sort_list():
|
for item in _get_sort_list():
|
||||||
@ -1403,17 +1402,22 @@ class InfoExtractor(object):
|
|||||||
if not f.get('ext') and 'url' in f:
|
if not f.get('ext') and 'url' in f:
|
||||||
f['ext'] = determine_ext(f['url'])
|
f['ext'] = determine_ext(f['url'])
|
||||||
|
|
||||||
|
has_audio_preference = 0
|
||||||
|
has_video_preference = 0
|
||||||
|
avoid_bad_preference = 0
|
||||||
preference = f.get('preference')
|
preference = f.get('preference')
|
||||||
if preference is None:
|
if preference is None:
|
||||||
preference = 0
|
preference = 0
|
||||||
if f.get('ext') in ['f4f', 'f4m']: # Not yet supported
|
if f.get('ext') in ['f4f', 'f4m']: # Not yet supported
|
||||||
preference -= 0.5
|
preference -= 0.5
|
||||||
|
elif preference <= -40:
|
||||||
|
avoid_bad_preference = preference
|
||||||
|
|
||||||
protocol = f.get('protocol') or determine_protocol(f)
|
protocol = f.get('protocol') or determine_protocol(f)
|
||||||
proto_preference = 0 if protocol in ['http', 'https'] else (-0.5 if protocol == 'rtsp' else -0.1)
|
proto_preference = 0 if protocol in ['http', 'https'] else (-0.5 if protocol == 'rtsp' else -0.1)
|
||||||
|
|
||||||
if f.get('vcodec') == 'none': # audio only
|
if f.get('vcodec') == 'none': # audio only
|
||||||
preference -= 50
|
has_video_preference = -50
|
||||||
if self._downloader.params.get('prefer_free_formats'):
|
if self._downloader.params.get('prefer_free_formats'):
|
||||||
ORDER = ['aac', 'mp3', 'm4a', 'webm', 'ogg', 'opus']
|
ORDER = ['aac', 'mp3', 'm4a', 'webm', 'ogg', 'opus']
|
||||||
else:
|
else:
|
||||||
@ -1425,7 +1429,7 @@ class InfoExtractor(object):
|
|||||||
audio_ext_preference = -1
|
audio_ext_preference = -1
|
||||||
else:
|
else:
|
||||||
if f.get('acodec') == 'none': # video only
|
if f.get('acodec') == 'none': # video only
|
||||||
preference -= 40
|
has_audio_preference = -40
|
||||||
if self._downloader.params.get('prefer_free_formats'):
|
if self._downloader.params.get('prefer_free_formats'):
|
||||||
ORDER = ['flv', 'mp4', 'webm']
|
ORDER = ['flv', 'mp4', 'webm']
|
||||||
else:
|
else:
|
||||||
@ -1462,15 +1466,18 @@ class InfoExtractor(object):
|
|||||||
else:
|
else:
|
||||||
audio_codec_preference -= 1
|
audio_codec_preference -= 1
|
||||||
|
|
||||||
prefVars = {'preference': preference,
|
prefVars = {'extractor': preference,
|
||||||
'proto_preference': proto_preference,
|
'avoid_bad': avoid_bad_preference,
|
||||||
'ext_preference': ext_preference,
|
'proto': proto_preference,
|
||||||
'audio_ext_preference': audio_ext_preference,
|
'has_audio': has_audio_preference,
|
||||||
'codec_preference': codec_preference,
|
'has_video': has_video_preference,
|
||||||
'audio_codec_preference': audio_codec_preference }
|
'ext': ext_preference,
|
||||||
|
'audio_ext': audio_ext_preference,
|
||||||
|
'codec': codec_preference,
|
||||||
|
'audio_codec': audio_codec_preference }
|
||||||
|
|
||||||
def format_get_val(field):
|
def format_get_val(field):
|
||||||
return f.get(field) if prefVars.get(field) is None else prefVars.get(field)
|
return (f.get(field + '_preference') if f.get(field) is None else f.get(field)) if prefVars.get(field) is None else prefVars.get(field)
|
||||||
|
|
||||||
def format_get_preference(field):
|
def format_get_preference(field):
|
||||||
val = format_get_val(field)
|
val = format_get_val(field)
|
||||||
|
@ -399,27 +399,29 @@ def parseOpts(overrideArguments=None):
|
|||||||
action='store', dest='format_sort', metavar='FORMAT', default=None,
|
action='store', dest='format_sort', metavar='FORMAT', default=None,
|
||||||
help=(
|
help=(
|
||||||
'Sort the formats by the fields given. '
|
'Sort the formats by the fields given. '
|
||||||
'Default order: preference, language_preference, quality, '
|
'Default order: avoid_bad, has_video, has_audio, extractor, '
|
||||||
'tbr, filesize, vbr, height, width, '
|
'language, quality, tbr, filesize, vbr, height, width, '
|
||||||
'proto_preference, ext_preference, codec_preference, '
|
'proto, ext, codec, abr, audio_ext, audio_codec, '
|
||||||
'abr, audio_ext_preference, audio_codec_preference, '
|
'fps, filesize_approx, source, format_id. '
|
||||||
'fps, filesize_approx, source_preference, format_id. '
|
'Prefix the field (except format_id) by a + to '
|
||||||
'Prefix the field (except format_id) by a + to sort it in reverse. '
|
'perform the sort in reverse. Suffix the field with '
|
||||||
'Suffix the field with :value to give highest preference to "value". '
|
':NUMBER to give highest preference to "NUMBER". '
|
||||||
'preference and language_preference will always have the highest priority '
|
'Examples: 1) '
|
||||||
'unless --format-sort-force is given. '
|
'"-f bestvideo --format-sort +height:720,fps,+filesize" '
|
||||||
'Examples: 1) "-f bestvideo --format-sort +height:720,fps,+filesize" gets the video with '
|
'gets the video with the smallest filesize with the '
|
||||||
'the smallest filesize with largest fps with '
|
'largest fps with the smallest height>=720 (or '
|
||||||
'the smallest height>=720 (or largest height available if there is no such format). '
|
'largest height available if there is no such format). '
|
||||||
'2) "-f bestvideo --format-sort height:720,proto_preference,tbr" gets the video with '
|
'2) "-f bestvideo --format-sort height:720,tbr" gets the '
|
||||||
'largest bitrate with best protocol with '
|
'video with largest bitrate with the largest height<=720 '
|
||||||
'the largest height<=720 (or smallest height available if there is no such format)'))
|
'(or smallest height available if there is no such format)'))
|
||||||
video_format.add_option(
|
video_format.add_option(
|
||||||
'--format-sort-force',
|
'--format-sort-force',
|
||||||
action='store_true', dest='format_sort_force', metavar='FORMAT', default=False,
|
action='store_true', dest='format_sort_force', metavar='FORMAT', default=False,
|
||||||
help=(
|
help=(
|
||||||
'User specified sort order takes priority even over '
|
'User specified sort order takes priority even over '
|
||||||
'preference and language_preference'))
|
'avoid_bad, has_video, has_audio, extractor and language. '
|
||||||
|
'These fields normally filter out the undesirable formats. '
|
||||||
|
'So use this option with caution. '))
|
||||||
video_format.add_option(
|
video_format.add_option(
|
||||||
'--all-formats',
|
'--all-formats',
|
||||||
action='store_const', dest='format', const='all',
|
action='store_const', dest='format', const='all',
|
||||||
|
Loading…
Reference in New Issue
Block a user