mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-01-07 17:16:08 +00:00
[YoutubeDL] Generalize best/worst format match behavior
This commit is contained in:
parent
4d72df4031
commit
e01c56f9e1
|
@ -914,22 +914,16 @@ class YoutubeDL(object):
|
||||||
if not available_formats:
|
if not available_formats:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if format_spec == 'best' or format_spec is None:
|
if format_spec in ['best', 'worst', None]:
|
||||||
|
format_idx = 0 if format_spec == 'worst' else -1
|
||||||
audiovideo_formats = [
|
audiovideo_formats = [
|
||||||
f for f in available_formats
|
f for f in available_formats
|
||||||
if f.get('vcodec') != 'none' and f.get('acodec') != 'none']
|
if f.get('vcodec') != 'none' and f.get('acodec') != 'none']
|
||||||
if audiovideo_formats:
|
if audiovideo_formats:
|
||||||
return audiovideo_formats[-1]
|
return audiovideo_formats[format_idx]
|
||||||
# for audio only urls, 'best' selects the best audio format
|
# for audio only urls, select the best/worst audio format
|
||||||
elif all(f.get('acodec') != 'none' for f in available_formats):
|
elif all(f.get('acodec') != 'none' for f in available_formats):
|
||||||
return available_formats[-1]
|
return available_formats[format_idx]
|
||||||
elif format_spec == 'worst':
|
|
||||||
audiovideo_formats = [
|
|
||||||
f for f in available_formats
|
|
||||||
if f.get('vcodec') != 'none' and f.get('acodec') != 'none']
|
|
||||||
if audiovideo_formats:
|
|
||||||
return audiovideo_formats[0]
|
|
||||||
return available_formats[0]
|
|
||||||
elif format_spec == 'bestaudio':
|
elif format_spec == 'bestaudio':
|
||||||
audio_formats = [
|
audio_formats = [
|
||||||
f for f in available_formats
|
f for f in available_formats
|
||||||
|
|
Loading…
Reference in a new issue