diff options
author | Sergey M․ <dstftw@gmail.com> | 2015-04-30 21:06:51 +0600 |
---|---|---|
committer | Sergey M․ <dstftw@gmail.com> | 2015-04-30 21:06:51 +0600 |
commit | e01c56f9e12d7abb2e3b548818a689146092806e (patch) | |
tree | 06358a2b2fbec9b3f0db5f83bb768ca353747e2e /youtube_dl/YoutubeDL.py | |
parent | 4d72df403115458fee2fe29217000580fac029d7 (diff) |
[YoutubeDL] Generalize best/worst format match behavior
Diffstat (limited to 'youtube_dl/YoutubeDL.py')
-rwxr-xr-x | youtube_dl/YoutubeDL.py | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index eee9c0154..9d4a2dce8 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -914,22 +914,16 @@ class YoutubeDL(object): if not available_formats: 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 = [ f for f in available_formats if f.get('vcodec') != 'none' and f.get('acodec') != 'none'] if audiovideo_formats: - return audiovideo_formats[-1] - # for audio only urls, 'best' selects the best audio format + return audiovideo_formats[format_idx] + # for audio only urls, select the best/worst audio format elif all(f.get('acodec') != 'none' for f in available_formats): - return available_formats[-1] - 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] + return available_formats[format_idx] elif format_spec == 'bestaudio': audio_formats = [ f for f in available_formats |