diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py index 793df4881d..58d2749700 100644 --- a/youtube_dl/extractor/youtube.py +++ b/youtube_dl/extractor/youtube.py @@ -1432,6 +1432,10 @@ def _extract_count(klass): 'height': height, 'format_note': note, }) + def _formats_key(f): + return (f.get('height') if f.get('height') is not None else -1, + f.get('width') if f.get('width') is not None else -1) + formats = sorted(formats, key=_formats_key) return { 'id': video_id,