mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-10 01:02:13 +01:00
[youtube] Populate thumbnail
with the best "known" thumbnail
Closes #402, Related: https://github.com/yt-dlp/yt-dlp/issues/340#issuecomment-950290624
This commit is contained in:
parent
9f1a1c36e6
commit
fccf502118
1 changed files with 6 additions and 1 deletions
|
@ -2696,6 +2696,8 @@ def feed_entry(name):
|
|||
thumbnails.append({
|
||||
'url': thumbnail_url,
|
||||
})
|
||||
original_thumbnails = thumbnails.copy()
|
||||
|
||||
# The best resolution thumbnails sometimes does not appear in the webpage
|
||||
# See: https://github.com/ytdl-org/youtube-dl/issues/29049, https://github.com/yt-dlp/yt-dlp/issues/340
|
||||
# List of possible thumbnails - Ref: <https://stackoverflow.com/a/20542029>
|
||||
|
@ -2706,7 +2708,6 @@ def feed_entry(name):
|
|||
'default', '1', '2', '3'
|
||||
]
|
||||
n_thumbnail_names = len(thumbnail_names)
|
||||
|
||||
thumbnails.extend({
|
||||
'url': 'https://i.ytimg.com/vi{webp}/{video_id}/{name}{live}.{ext}'.format(
|
||||
video_id=video_id, name=name, ext=ext,
|
||||
|
@ -2716,6 +2717,7 @@ def feed_entry(name):
|
|||
i = next((i for i, t in enumerate(thumbnail_names) if f'/{video_id}/{t}' in thumb['url']), n_thumbnail_names)
|
||||
thumb['preference'] = (0 if '.webp' in thumb['url'] else -1) - (2 * i)
|
||||
self._remove_duplicate_formats(thumbnails)
|
||||
self._downloader._sort_thumbnails(original_thumbnails)
|
||||
|
||||
category = get_first(microformats, 'category') or search_meta('genre')
|
||||
channel_id = str_or_none(
|
||||
|
@ -2745,6 +2747,9 @@ def feed_entry(name):
|
|||
'title': self._live_title(video_title) if is_live else video_title,
|
||||
'formats': formats,
|
||||
'thumbnails': thumbnails,
|
||||
# The best thumbnail that we are sure exists. Prevents unnecessary
|
||||
# URL checking if user don't care about getting the best possible thumbnail
|
||||
'thumbnail': traverse_obj(original_thumbnails, (-1, 'url')),
|
||||
'description': video_description,
|
||||
'upload_date': unified_strdate(
|
||||
get_first(microformats, 'uploadDate')
|
||||
|
|
Loading…
Reference in a new issue