Explorar o código

[YoutubeIE] Sort formats by resolution

rzhxeo %!s(int64=12) %!d(string=hai) anos
pai
achega
e56f22ae20
Modificáronse 1 ficheiros con 4 adicións e 0 borrados
  1. 4 0
      youtube_dl/extractor/youtube.py

+ 4 - 0
youtube_dl/extractor/youtube.py

@@ -1432,6 +1432,10 @@ class YoutubeIE(YoutubeBaseInfoExtractor, SubtitlesInfoExtractor):
                 '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,