[yahoo] Use centralized sorting, and add tbr field
authorPhilipp Hagemeister <phihag@phihag.de>
Wed, 25 Dec 2013 14:18:40 +0000 (15:18 +0100)
committerPhilipp Hagemeister <phihag@phihag.de>
Wed, 25 Dec 2013 14:18:40 +0000 (15:18 +0100)
youtube_dl/YoutubeDL.py
youtube_dl/extractor/common.py
youtube_dl/extractor/yahoo.py
youtube_dl/utils.py

index 88f4b11f654360abc582fa3b5df62823b8377990..a9a3639d7f7a32053990f0b41e487b837a704767 100644 (file)
@@ -1018,6 +1018,8 @@ class YoutubeDL(object):
                 res += u'(unsupported) '
             if fdict.get('format_note') is not None:
                 res += fdict['format_note'] + u' '
+            if fdict.get('tbr') is not None:
+                res += u'%4dk ' % fdict['tbr']
             if (fdict.get('vcodec') is not None and
                     fdict.get('vcodec') != 'none'):
                 res += u'%-5s@' % fdict['vcodec']
index 05f0cb6d521c12766ba165796580a73b0d7b5d5b..6fa60622e096e518a55c4cfddd71ef5a4d9a862a 100644 (file)
@@ -57,6 +57,7 @@ class InfoExtractor(object):
                     * width      Width of the video, if known
                     * height     Height of the video, if known
                     * resolution Textual description of width and height
+                    * tbr        Average bitrate of audio and video in KBit/s
                     * abr        Average audio bitrate in KBit/s
                     * acodec     Name of the audio codec in use
                     * vbr        Average video bitrate in KBit/s
index 5c9c361b9ee5658d307a7759040b855a3e794cf1..e17a39782bd2e674855dff8a5ec3112bd40158c6 100644 (file)
@@ -6,8 +6,8 @@ from .common import InfoExtractor, SearchInfoExtractor
 from ..utils import (
     compat_urllib_parse,
     compat_urlparse,
-    determine_ext,
     clean_html,
+    int_or_none,
 )
 
 
@@ -68,9 +68,9 @@ class YahooIE(InfoExtractor):
         formats = []
         for s in info['streams']:
             format_info = {
-                'width': s.get('width'),
-                'height': s.get('height'),
-                'bitrate': s.get('bitrate'),
+                'width': int_or_none(s.get('width')),
+                'height': int_or_none(s.get('height')),
+                'tbr': int_or_none(s.get('bitrate')),
             }
 
             host = s['host']
@@ -84,10 +84,10 @@ class YahooIE(InfoExtractor):
             else:
                 format_url = compat_urlparse.urljoin(host, path)
                 format_info['url'] = format_url
-                format_info['ext'] = determine_ext(format_url)
                 
             formats.append(format_info)
-        formats = sorted(formats, key=lambda f:(f['height'], f['width']))
+
+        self._sort_formats(formats)
 
         return {
             'id': video_id,
index 2e48f187e665dad81caa663efdb9d0c33f088936..4c8bdbb0cc0bf2af14c2ec006307b8b2a2c7d65d 100644 (file)
@@ -1098,3 +1098,7 @@ def url_basename(url):
 class HEADRequest(compat_urllib_request.Request):
     def get_method(self):
         return "HEAD"
+
+
+def int_or_none(v):
+    return v if v is None else int(v)