Skip to content

Commit

Permalink
[extractor/twitch] Extract original size thumbnail (#6629)
Browse files Browse the repository at this point in the history
Authored by: JC-Chung
  • Loading branch information
JC-Chung authored Apr 22, 2023
1 parent 1ea1560 commit 80b732b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions yt_dlp/extractor/twitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ def _download_access_token(self, video_id, token_kind, param_name):
video_id, ops,
'Downloading %s access token GraphQL' % token_kind)['data'][method]

def _get_thumbnails(self, thumbnail):
return [{
'url': re.sub(r'\d+x\d+(\.\w+)($|(?=[?#]))', r'0x0\g<1>', thumbnail),
'preference': 1,
}, {
'url': thumbnail,
}] if thumbnail else None


class TwitchVodIE(TwitchBaseIE):
IE_NAME = 'twitch:vod'
Expand Down Expand Up @@ -460,15 +468,13 @@ def _extract_info_gql(self, info, item_id):
is_live, thumbnail = True, None
else:
is_live = False
for p in ('width', 'height'):
thumbnail = thumbnail.replace('{%s}' % p, '0')

return {
'id': vod_id,
'title': info.get('title') or 'Untitled Broadcast',
'description': info.get('description'),
'duration': int_or_none(info.get('lengthSeconds')),
'thumbnail': thumbnail,
'thumbnails': self._get_thumbnails(thumbnail),
'uploader': try_get(info, lambda x: x['owner']['displayName'], compat_str),
'uploader_id': try_get(info, lambda x: x['owner']['login'], compat_str),
'timestamp': unified_timestamp(info.get('publishedAt')),
Expand Down Expand Up @@ -1053,7 +1059,7 @@ def _real_extract(self, url):
'display_id': channel_name,
'title': title,
'description': description,
'thumbnail': thumbnail,
'thumbnails': self._get_thumbnails(thumbnail),
'uploader': uploader,
'uploader_id': channel_name,
'timestamp': timestamp,
Expand Down

0 comments on commit 80b732b

Please sign in to comment.