]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/kick.py
1 from .common
import InfoExtractor
15 class KickBaseIE(InfoExtractor
):
16 def _real_initialize(self
):
17 self
._request
_webpage
(HEADRequest('https://kick.com/'), None, 'Setting up session', fatal
=False)
18 xsrf_token
= self
._get
_cookies
('https://kick.com/').get('XSRF-TOKEN')
20 self
.write_debug('kick.com did not set XSRF-TOKEN cookie')
21 KickBaseIE
._API
_HEADERS
= {
22 'Authorization': f
'Bearer {xsrf_token.value}',
23 'X-XSRF-TOKEN': xsrf_token
.value
,
24 } if xsrf_token
else {}
26 def _call_api(self
, path
, display_id
, note
='Downloading API JSON', headers
={}, **kwargs
):
27 return self
._download
_json
(
28 f
'https://kick.com/api/v1/{path}', display_id
, note
=note
,
29 headers
=merge_dicts(headers
, self
._API
_HEADERS
), **kwargs
)
32 class KickIE(KickBaseIE
):
33 _VALID_URL
= r
'https?://(?:www\.)?kick\.com/(?!(?:video|categories|search|auth)(?:[/?#]|$))(?P<id>[\w_]+)'
35 'url': 'https://kick.com/yuppy',
37 'id': '6cde1-kickrp-joe-flemmingskick-info-heremust-knowmust-see21',
42 'channel_id': '33538',
44 'uploader_id': '33793',
46 'live_status': 'is_live',
48 'thumbnail': r
're:^https?://.*\.jpg',
53 'url': 'https://kick.com/kmack710',
54 'only_matching': True,
57 def _real_extract(self
, url
):
58 channel
= self
._match
_id
(url
)
59 response
= self
._call
_api
(f
'channels/{channel}', channel
)
60 if not traverse_obj(response
, 'livestream', expected_type
=dict):
61 raise UserNotLive(video_id
=channel
)
64 'id': str(traverse_obj(
65 response
, ('livestream', ('slug', 'id')), get_all
=False, default
=channel
)),
66 'formats': self
._extract
_m
3u8_formats
(
67 response
['playback_url'], channel
, 'mp4', live
=True),
68 'title': traverse_obj(
69 response
, ('livestream', ('session_title', 'slug')), get_all
=False, default
=''),
70 'description': traverse_obj(response
, ('user', 'bio')),
72 'channel_id': str_or_none(traverse_obj(response
, 'id', ('livestream', 'channel_id'))),
73 'uploader': traverse_obj(response
, 'name', ('user', 'username')),
74 'uploader_id': str_or_none(traverse_obj(response
, 'user_id', ('user', 'id'))),
76 'timestamp': unified_timestamp(traverse_obj(response
, ('livestream', 'created_at'))),
77 'thumbnail': traverse_obj(
78 response
, ('livestream', 'thumbnail', 'url'), expected_type
=url_or_none
),
79 'categories': traverse_obj(response
, ('recent_categories', ..., 'name')),
83 class KickVODIE(KickBaseIE
):
84 _VALID_URL
= r
'https?://(?:www\.)?kick\.com/video/(?P<id>[\da-f]{8}-(?:[\da-f]{4}-){3}[\da-f]{12})'
86 'url': 'https://kick.com/video/54244b5e-050a-4df4-a013-b2433dafbe35',
87 'md5': '73691206a6a49db25c5aa1588e6538fc',
89 'id': '54244b5e-050a-4df4-a013-b2433dafbe35',
91 'title': 'Making 710-carBoosting. Kinda No Pixel inspired. !guilded - !links',
92 'description': 'md5:a0d3546bf7955d0a8252ffe0fd6f518f',
93 'channel': 'kmack710',
94 'channel_id': '16278',
95 'uploader': 'Kmack710',
96 'uploader_id': '16412',
97 'upload_date': '20221206',
98 'timestamp': 1670318289,
100 'thumbnail': r
're:^https?://.*\.jpg',
101 'categories': ['Grand Theft Auto V'],
104 'skip_download': 'm3u8',
108 def _real_extract(self
, url
):
109 video_id
= self
._match
_id
(url
)
110 response
= self
._call
_api
(f
'video/{video_id}', video_id
)
114 'formats': self
._extract
_m
3u8_formats
(response
['source'], video_id
, 'mp4'),
115 'title': traverse_obj(
116 response
, ('livestream', ('session_title', 'slug')), get_all
=False, default
=''),
117 'description': traverse_obj(response
, ('livestream', 'channel', 'user', 'bio')),
118 'channel': traverse_obj(response
, ('livestream', 'channel', 'slug')),
119 'channel_id': str_or_none(traverse_obj(response
, ('livestream', 'channel', 'id'))),
120 'uploader': traverse_obj(response
, ('livestream', 'channel', 'user', 'username')),
121 'uploader_id': str_or_none(traverse_obj(response
, ('livestream', 'channel', 'user_id'))),
122 'timestamp': unified_timestamp(response
.get('created_at')),
123 'duration': float_or_none(traverse_obj(response
, ('livestream', 'duration')), scale
=1000),
124 'thumbnail': traverse_obj(
125 response
, ('livestream', 'thumbnail'), expected_type
=url_or_none
),
126 'categories': traverse_obj(response
, ('livestream', 'categories', ..., 'name')),