From ff2751ac9cc7d4150797d3207da9b566396bc796 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Tue, 18 May 2021 19:15:11 +0530 Subject: [PATCH] [youtube] Always extract `maxresdefault` thumbnail Fixes: https://github.com/ytdl-org/youtube-dl/issues/29049 --- yt_dlp/YoutubeDL.py | 3 ++- yt_dlp/extractor/youtube.py | 22 +++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py index c2c270237..55bc49a9e 100644 --- a/yt_dlp/YoutubeDL.py +++ b/yt_dlp/YoutubeDL.py @@ -1944,7 +1944,8 @@ class YoutubeDL(object): 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'): diff --git a/yt_dlp/extractor/youtube.py b/yt_dlp/extractor/youtube.py index 1d50264b6..145b89a6e 100644 --- a/yt_dlp/extractor/youtube.py +++ b/yt_dlp/extractor/youtube.py @@ -2169,16 +2169,24 @@ class YoutubeIE(YoutubeBaseInfoExtractor): 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') \