]> jfr.im git - yt-dlp.git/commitdiff
[youtube] Always extract `maxresdefault` thumbnail
authorpukkandan <redacted>
Tue, 18 May 2021 13:45:11 +0000 (19:15 +0530)
committerpukkandan <redacted>
Tue, 18 May 2021 14:01:17 +0000 (19:31 +0530)
Fixes: https://github.com/ytdl-org/youtube-dl/issues/29049
yt_dlp/YoutubeDL.py
yt_dlp/extractor/youtube.py

index c2c2702378417bdcb2d783bac3b8de40db2247c9..55bc49a9ea3702dbfe7cc6da0aa15ffff41e3885 100644 (file)
@@ -1944,7 +1944,8 @@ def sanitize_numeric_fields(info):
                 t.get('preference') if t.get('preference') is not None else -1,
                 t.get('width') if t.get('width') is not None else -1,
                 t.get('height') if t.get('height') is not None else -1,
-                t.get('id') if t.get('id') is not None else '', t.get('url')))
+                t.get('id') if t.get('id') is not None else '',
+                t.get('url')))
             for i, t in enumerate(thumbnails):
                 t['url'] = sanitize_url(t['url'])
                 if t.get('width') and t.get('height'):
index 1d50264b6d3a3c2d273d4ccec1516cdaef6fbe49..145b89a6eca7b492a7d6c3d63d8f7f1ada4f67ca 100644 (file)
@@ -2169,16 +2169,24 @@ def feed_entry(name):
                 if 'maxresdefault' in thumbnail_url:
                     thumbnail_url = thumbnail_url.split('?')[0]
                 thumbnails.append({
-                    'height': int_or_none(thumbnail.get('height')),
                     'url': thumbnail_url,
+                    'height': int_or_none(thumbnail.get('height')),
                     'width': int_or_none(thumbnail.get('width')),
+                    'preference': 1 if 'maxresdefault' in thumbnail_url else -1
                 })
-            if thumbnails:
-                break
-        else:
-            thumbnail = search_meta(['og:image', 'twitter:image'])
-            if thumbnail:
-                thumbnails = [{'url': thumbnail}]
+        thumbnail_url = search_meta(['og:image', 'twitter:image'])
+        if thumbnail_url:
+            thumbnails.append({
+                'url': thumbnail_url,
+                'preference': 1 if 'maxresdefault' in thumbnail_url else -1
+            })
+        # All videos have a maxresdefault thumbnail, but sometimes it does not appear in the webpage
+        # See: https://github.com/ytdl-org/youtube-dl/issues/29049
+        thumbnails.append({
+            'url': 'https://i.ytimg.com/vi/%s/maxresdefault.jpg' % video_id,
+            'preference': 1,
+        })
+        self._remove_duplicate_formats(thumbnails)
 
         category = microformat.get('category') or search_meta('genre')
         channel_id = video_details.get('channelId') \