forked from minhngoc25a/yt-dlc
[twitch] Pass v5 accept header and fix thumbnails extraction (closes #25531)
This commit is contained in:
parent
c8b232cc48
commit
a0455d0ffd
|
@ -21,6 +21,7 @@ from ..utils import (
|
||||||
orderedSet,
|
orderedSet,
|
||||||
parse_duration,
|
parse_duration,
|
||||||
parse_iso8601,
|
parse_iso8601,
|
||||||
|
qualities,
|
||||||
try_get,
|
try_get,
|
||||||
unified_timestamp,
|
unified_timestamp,
|
||||||
update_url_query,
|
update_url_query,
|
||||||
|
@ -50,7 +51,10 @@ class TwitchBaseIE(InfoExtractor):
|
||||||
|
|
||||||
def _call_api(self, path, item_id, *args, **kwargs):
|
def _call_api(self, path, item_id, *args, **kwargs):
|
||||||
headers = kwargs.get('headers', {}).copy()
|
headers = kwargs.get('headers', {}).copy()
|
||||||
headers['Client-ID'] = self._CLIENT_ID
|
headers.update({
|
||||||
|
'Accept': 'application/vnd.twitchtv.v5+json; charset=UTF-8',
|
||||||
|
'Client-ID': self._CLIENT_ID,
|
||||||
|
})
|
||||||
kwargs['headers'] = headers
|
kwargs['headers'] = headers
|
||||||
response = self._download_json(
|
response = self._download_json(
|
||||||
'%s/%s' % (self._API_BASE, path), item_id,
|
'%s/%s' % (self._API_BASE, path), item_id,
|
||||||
|
@ -186,12 +190,27 @@ class TwitchItemBaseIE(TwitchBaseIE):
|
||||||
is_live = False
|
is_live = False
|
||||||
else:
|
else:
|
||||||
is_live = None
|
is_live = None
|
||||||
|
_QUALITIES = ('small', 'medium', 'large')
|
||||||
|
quality_key = qualities(_QUALITIES)
|
||||||
|
thumbnails = []
|
||||||
|
preview = info.get('preview')
|
||||||
|
if isinstance(preview, dict):
|
||||||
|
for thumbnail_id, thumbnail_url in preview.items():
|
||||||
|
thumbnail_url = url_or_none(thumbnail_url)
|
||||||
|
if not thumbnail_url:
|
||||||
|
continue
|
||||||
|
if thumbnail_id not in _QUALITIES:
|
||||||
|
continue
|
||||||
|
thumbnails.append({
|
||||||
|
'url': thumbnail_url,
|
||||||
|
'preference': quality_key(thumbnail_id),
|
||||||
|
})
|
||||||
return {
|
return {
|
||||||
'id': info['_id'],
|
'id': info['_id'],
|
||||||
'title': info.get('title') or 'Untitled Broadcast',
|
'title': info.get('title') or 'Untitled Broadcast',
|
||||||
'description': info.get('description'),
|
'description': info.get('description'),
|
||||||
'duration': int_or_none(info.get('length')),
|
'duration': int_or_none(info.get('length')),
|
||||||
'thumbnail': info.get('preview'),
|
'thumbnails': thumbnails,
|
||||||
'uploader': info.get('channel', {}).get('display_name'),
|
'uploader': info.get('channel', {}).get('display_name'),
|
||||||
'uploader_id': info.get('channel', {}).get('name'),
|
'uploader_id': info.get('channel', {}).get('name'),
|
||||||
'timestamp': parse_iso8601(info.get('recorded_at')),
|
'timestamp': parse_iso8601(info.get('recorded_at')),
|
||||||
|
|
Loading…
Reference in New Issue