[zdf] Use centralized sorting
authorPhilipp Hagemeister <phihag@phihag.de>
Tue, 24 Dec 2013 22:32:04 +0000 (23:32 +0100)
committerPhilipp Hagemeister <phihag@phihag.de>
Tue, 24 Dec 2013 22:32:04 +0000 (23:32 +0100)
youtube_dl/YoutubeDL.py
youtube_dl/extractor/common.py
youtube_dl/extractor/zdf.py

index 4910a2912bfd9c0ccfd13dbd17b20ed35baa448d..88f4b11f654360abc582fa3b5df62823b8377990 100644 (file)
@@ -1014,6 +1014,8 @@ class YoutubeDL(object):
     def list_formats(self, info_dict):
         def format_note(fdict):
             res = u''
+            if f.get('ext') in ['f4f', 'f4m']:
+                res += u'(unsupported) '
             if fdict.get('format_note') is not None:
                 res += fdict['format_note'] + u' '
             if (fdict.get('vcodec') is not None and
index 0a90382de116bdffdb88edfc0ebe1a38fb758dd6..05f0cb6d521c12766ba165796580a73b0d7b5d5b 100644 (file)
@@ -9,6 +9,7 @@ import xml.etree.ElementTree
 from ..utils import (
     compat_http_client,
     compat_urllib_error,
+    compat_urllib_parse_urlparse,
     compat_str,
 
     clean_html,
@@ -62,6 +63,9 @@ class InfoExtractor(object):
                     * vcodec     Name of the video codec in use
                     * filesize   The number of bytes, if known in advance
                     * player_url SWF Player URL (used for rtmpdump).
+                    * protocol   The protocol that will be used for the actual
+                                 download, lower-case.
+                                 "http", "https", "rtsp", "rtmp" or so.
                     * preference Order number of this format. If this field is
                                  present, the formats get sorted by this field.
                                  -1 for default (order by other properties),
@@ -445,7 +449,11 @@ class InfoExtractor(object):
 
             preference = f.get('preference')
             if preference is None:
-                preference = 0 if f.get('url', '').startswith('http') else -0.1
+                proto = f.get('protocol')
+                if proto is None:
+                    proto = compat_urllib_parse_urlparse(f.get('url', '')).scheme
+
+                preference = 0 if proto in ['http', 'https'] else -0.1
                 if f.get('ext') in ['f4f', 'f4m']:  # Not yet supported
                     preference -= 0.5
 
index 35ece354a6ecdf7ba5705184d4ceff22d57eb3d4..94594c5d68dfdc01acbb87b8133d14aa8209b52e 100644 (file)
@@ -67,29 +67,13 @@ class ZDFIE(InfoExtractor):
             ''', format_id)
 
             ext = format_m.group('container')
-            is_supported = ext != 'f4f'
-
-            PROTO_ORDER = ['http', 'rtmp', 'rtsp']
-            try:
-                proto_pref = -PROTO_ORDER.index(format_m.group('proto'))
-            except ValueError:
-                proto_pref = -999
+            proto = format_m.group('proto')
 
             quality = fnode.find('./quality').text
-            QUALITY_ORDER = ['veryhigh', '300', 'high', 'med', 'low']
-            try:
-                quality_pref = -QUALITY_ORDER.index(quality)
-            except ValueError:
-                quality_pref = -999
-
             abr = int(fnode.find('./audioBitrate').text) // 1000
             vbr = int(fnode.find('./videoBitrate').text) // 1000
-            pref = (is_available, is_supported,
-                    proto_pref, quality_pref, vbr, abr)
 
             format_note = u''
-            if not is_supported:
-                format_note += u'(unsupported)'
             if not format_note:
                 format_note = None
 
@@ -105,14 +89,16 @@ class ZDFIE(InfoExtractor):
                 'height': int(fnode.find('./height').text),
                 'filesize': int(fnode.find('./filesize').text),
                 'format_note': format_note,
-                '_pref': pref,
+                'protocol': format_m.group('proto').lower(),
                 '_available': is_available,
             }
 
         format_nodes = doc.findall('.//formitaeten/formitaet')
-        formats = sorted(filter(lambda f: f['_available'],
-                                map(xml_to_format, format_nodes)),
-                         key=operator.itemgetter('_pref'))
+        formats = list(filter(
+            lambda f: f['_available'],
+            map(xml_to_format, format_nodes)))
+
+        self._sort_formats(formats)
 
         return {
             'id': video_id,