[cnn] Improve thumbnail extraction
authorPhilipp Hagemeister <phihag@phihag.de>
Sat, 7 Jun 2014 13:39:21 +0000 (15:39 +0200)
committerPhilipp Hagemeister <phihag@phihag.de>
Sat, 7 Jun 2014 13:39:21 +0000 (15:39 +0200)
youtube_dl/YoutubeDL.py
youtube_dl/extractor/cnn.py

index 455c0a7b0e1d93d8a4db9ca5543ba0f6a5fa1fe8..dc0ba986a98744151cafd932acbcd6bbe33fb4a0 100755 (executable)
@@ -719,6 +719,8 @@ class YoutubeDL(object):
 
         thumbnails = info_dict.get('thumbnails')
         if thumbnails:
+            thumbnails.sort(key=lambda t: (
+                t.get('width'), t.get('height'), t.get('url')))
             for t in thumbnails:
                 if 'width' in t and 'height' in t:
                     t['resolution'] = '%dx%d' % (t['width'], t['height'])
index b32cb898010a0ad0e02e12f3b3a55c3769cc3979..dae40c136bae20fd54cae401e711b9233c750e14 100644 (file)
@@ -79,8 +79,11 @@ class CNNIE(InfoExtractor):
 
         self._sort_formats(formats)
 
-        thumbnails = sorted([((int(t.attrib['height']),int(t.attrib['width'])), t.text) for t in info.findall('images/image')])
-        thumbs_dict = [{'resolution': res, 'url': t_url} for (res, t_url) in thumbnails]
+        thumbnails = [{
+            'height': int(t.attrib['height']),
+            'width': int(t.attrib['width']),
+            'url': t.text,
+        } for t in info.findall('images/image')]
 
         metas_el = info.find('metas')
         upload_date = (
@@ -93,8 +96,7 @@ class CNNIE(InfoExtractor):
             'id': info.attrib['id'],
             'title': info.find('headline').text,
             'formats': formats,
-            'thumbnail': thumbnails[-1][1],
-            'thumbnails': thumbs_dict,
+            'thumbnails': thumbnails,
             'description': info.find('description').text,
             'duration': duration,
             'upload_date': upload_date,