mirror of https://github.com/yt-dlp/yt-dlp.git
[youtube:tab] Extract channel banner (#2400)
Closes #2237 Authored by: coletdjnz
This commit is contained in:
parent
d14cbdd92d
commit
301d07fc4b
|
@ -3913,10 +3913,37 @@ class YoutubeTabBaseInfoExtractor(YoutubeBaseInfoExtractor):
|
||||||
playlist_id = channel_id
|
playlist_id = channel_id
|
||||||
tags = renderer.get('keywords', '').split()
|
tags = renderer.get('keywords', '').split()
|
||||||
|
|
||||||
thumbnails = (
|
# We can get the uncropped banner/avatar by replacing the crop params with '=s0'
|
||||||
self._extract_thumbnails(renderer, 'avatar')
|
# See: https://github.com/yt-dlp/yt-dlp/issues/2237#issuecomment-1013694714
|
||||||
or self._extract_thumbnails(
|
def _get_uncropped(url):
|
||||||
primary_sidebar_renderer, ('thumbnailRenderer', 'playlistVideoThumbnailRenderer', 'thumbnail')))
|
return url_or_none((url or '').split('=')[0] + '=s0')
|
||||||
|
|
||||||
|
avatar_thumbnails = self._extract_thumbnails(renderer, 'avatar')
|
||||||
|
if avatar_thumbnails:
|
||||||
|
uncropped_avatar = _get_uncropped(avatar_thumbnails[0]['url'])
|
||||||
|
if uncropped_avatar:
|
||||||
|
avatar_thumbnails.append({
|
||||||
|
'url': uncropped_avatar,
|
||||||
|
'id': 'avatar_uncropped',
|
||||||
|
'preference': 1
|
||||||
|
})
|
||||||
|
|
||||||
|
channel_banners = self._extract_thumbnails(
|
||||||
|
data, ('header', ..., ['banner', 'mobileBanner', 'tvBanner']))
|
||||||
|
for banner in channel_banners:
|
||||||
|
banner['preference'] = -10
|
||||||
|
|
||||||
|
if channel_banners:
|
||||||
|
uncropped_banner = _get_uncropped(channel_banners[0]['url'])
|
||||||
|
if uncropped_banner:
|
||||||
|
channel_banners.append({
|
||||||
|
'url': uncropped_banner,
|
||||||
|
'id': 'banner_uncropped',
|
||||||
|
'preference': -5
|
||||||
|
})
|
||||||
|
|
||||||
|
primary_thumbnails = self._extract_thumbnails(
|
||||||
|
primary_sidebar_renderer, ('thumbnailRenderer', 'playlistVideoThumbnailRenderer', 'thumbnail'))
|
||||||
|
|
||||||
if playlist_id is None:
|
if playlist_id is None:
|
||||||
playlist_id = item_id
|
playlist_id = item_id
|
||||||
|
@ -3935,7 +3962,7 @@ class YoutubeTabBaseInfoExtractor(YoutubeBaseInfoExtractor):
|
||||||
'uploader': channel_name,
|
'uploader': channel_name,
|
||||||
'uploader_id': channel_id,
|
'uploader_id': channel_id,
|
||||||
'uploader_url': channel_url,
|
'uploader_url': channel_url,
|
||||||
'thumbnails': thumbnails,
|
'thumbnails': primary_thumbnails + avatar_thumbnails + channel_banners,
|
||||||
'tags': tags,
|
'tags': tags,
|
||||||
'view_count': self._get_count(playlist_stats, 1),
|
'view_count': self._get_count(playlist_stats, 1),
|
||||||
'availability': self._extract_availability(data),
|
'availability': self._extract_availability(data),
|
||||||
|
|
Loading…
Reference in New Issue