3 from .common
import InfoExtractor
4 from ..networking
import HEADRequest
19 class KickBaseIE(InfoExtractor
):
20 def _real_initialize(self
):
21 self
._request
_webpage
(
22 HEADRequest('https://kick.com/'), None, 'Setting up session', fatal
=False, impersonate
=True)
23 xsrf_token
= self
._get
_cookies
('https://kick.com/').get('XSRF-TOKEN')
25 self
.write_debug('kick.com did not set XSRF-TOKEN cookie')
26 KickBaseIE
._API
_HEADERS
= {
27 'Authorization': f
'Bearer {xsrf_token.value}',
28 'X-XSRF-TOKEN': xsrf_token
.value
,
29 } if xsrf_token
else {}
31 def _call_api(self
, path
, display_id
, note
='Downloading API JSON', headers
={}, **kwargs
):
32 return self
._download
_json
(
33 f
'https://kick.com/api/{path}', display_id
, note
=note
,
34 headers
=merge_dicts(headers
, self
._API
_HEADERS
), impersonate
=True, **kwargs
)
37 class KickIE(KickBaseIE
):
39 _VALID_URL
= r
'https?://(?:www\.)?kick\.com/(?!(?:video|categories|search|auth)(?:[/?#]|$))(?P<id>[\w-]+)'
41 'url': 'https://kick.com/buddha',
43 'id': '92722911-nopixel-40',
48 'thumbnail': r
're:https?://.+\.jpg',
52 'channel_id': '32807',
54 'uploader_id': '33057',
55 'live_status': 'is_live',
56 'concurrent_view_count': int,
57 'release_timestamp': int,
61 'params': {'skip_download': 'livestream'},
62 # 'skip': 'livestream',
64 'url': 'https://kick.com/xqc',
65 'only_matching': True,
69 def suitable(cls
, url
):
70 return False if (KickVODIE
.suitable(url
) or KickClipIE
.suitable(url
)) else super().suitable(url
)
72 def _real_extract(self
, url
):
73 channel
= self
._match
_id
(url
)
74 response
= self
._call
_api
(f
'v2/channels/{channel}', channel
)
75 if not traverse_obj(response
, 'livestream', expected_type
=dict):
76 raise UserNotLive(video_id
=channel
)
81 'formats': self
._extract
_m
3u8_formats
(response
['playback_url'], channel
, 'mp4', live
=True),
82 **traverse_obj(response
, {
83 'id': ('livestream', 'slug', {str}
),
84 'title': ('livestream', 'session_title', {str}
),
85 'description': ('user', 'bio', {str}
),
86 'channel_id': (('id', ('livestream', 'channel_id')), {int}
, {str_or_none}
, any
),
87 'uploader': (('name', ('user', 'username')), {str}
, any
),
88 'uploader_id': (('user_id', ('user', 'id')), {int}
, {str_or_none}
, any
),
89 'timestamp': ('livestream', 'created_at', {unified_timestamp}
),
90 'release_timestamp': ('livestream', 'start_time', {unified_timestamp}
),
91 'thumbnail': ('livestream', 'thumbnail', 'url', {url_or_none}
),
92 'categories': ('recent_categories', ..., 'name', {str}
),
93 'concurrent_view_count': ('livestream', 'viewer_count', {int_or_none}
),
94 'age_limit': ('livestream', 'is_mature', {bool}
, {lambda x
: 18 if x
else 0}),
99 class KickVODIE(KickBaseIE
):
101 _VALID_URL
= r
'https?://(?:www\.)?kick\.com/[\w-]+/videos/(?P<id>[\da-f]{8}-(?:[\da-f]{4}-){3}[\da-f]{12})'
103 'url': 'https://kick.com/xqc/videos/8dd97a8d-e17f-48fb-8bc3-565f88dbc9ea',
104 'md5': '3870f94153e40e7121a6e46c068b70cb',
106 'id': '8dd97a8d-e17f-48fb-8bc3-565f88dbc9ea',
108 'title': '18+ #ad 🛑LIVE🛑CLICK🛑DRAMA🛑NEWS🛑STUFF🛑REACT🛑GET IN HHERE🛑BOP BOP🛑WEEEE WOOOO🛑',
109 'description': 'THE BEST AT ABSOLUTELY EVERYTHING. THE JUICER. LEADER OF THE JUICERS.',
113 'uploader_id': '676',
114 'upload_date': '20240909',
115 'timestamp': 1725919141,
117 'thumbnail': r
're:^https?://.*\.jpg',
119 'categories': ['Just Chatting'],
122 'params': {'skip_download': 'm3u8'},
125 def _real_extract(self
, url
):
126 video_id
= self
._match
_id
(url
)
127 response
= self
._call
_api
(f
'v1/video/{video_id}', video_id
)
131 'formats': self
._extract
_m
3u8_formats
(response
['source'], video_id
, 'mp4'),
132 **traverse_obj(response
, {
133 'title': ('livestream', ('session_title', 'slug'), {str}
, any
),
134 'description': ('livestream', 'channel', 'user', 'bio', {str}
),
135 'channel': ('livestream', 'channel', 'slug', {str}
),
136 'channel_id': ('livestream', 'channel', 'id', {int}
, {str_or_none}
),
137 'uploader': ('livestream', 'channel', 'user', 'username', {str}
),
138 'uploader_id': ('livestream', 'channel', 'user_id', {int}
, {str_or_none}
),
139 'timestamp': ('created_at', {parse_iso8601}
),
140 'duration': ('livestream', 'duration', {functools
.partial(float_or_none
, scale
=1000)}),
141 'thumbnail': ('livestream', 'thumbnail', {url_or_none}
),
142 'categories': ('livestream', 'categories', ..., 'name', {str}
),
143 'view_count': ('views', {int_or_none}
),
144 'age_limit': ('livestream', 'is_mature', {bool}
, {lambda x
: 18 if x
else 0}),
149 class KickClipIE(KickBaseIE
):
150 IE_NAME
= 'kick:clips'
151 _VALID_URL
= r
'https?://(?:www\.)?kick\.com/[\w-]+(?:/clips/|/?\?(?:[^#]+&)?clip=)(?P<id>clip_[\w-]+)'
153 'url': 'https://kick.com/mxddy?clip=clip_01GYXVB5Y8PWAPWCWMSBCFB05X',
155 'id': 'clip_01GYXVB5Y8PWAPWCWMSBCFB05X',
157 'title': 'Maddy detains Abd D:',
159 'channel_id': '133789',
160 'uploader': 'AbdCreates',
161 'uploader_id': '3309077',
162 'thumbnail': r
're:^https?://.*\.jpeg',
164 'timestamp': 1682481453,
165 'upload_date': '20230426',
168 'categories': ['VALORANT'],
171 'params': {'skip_download': 'm3u8'},
173 'url': 'https://kick.com/destiny?clip=clip_01H9SKET879NE7N9RJRRDS98J3',
175 'id': 'clip_01H9SKET879NE7N9RJRRDS98J3',
178 'channel': 'destiny',
179 'channel_id': '1772249',
180 'uploader': 'punished_furry',
181 'uploader_id': '2027722',
183 'upload_date': '20230908',
184 'timestamp': 1694150180,
185 'thumbnail': 'https://clips.kick.com/clips/j3/clip_01H9SKET879NE7N9RJRRDS98J3/thumbnail.png',
188 'categories': ['Just Chatting'],
191 'params': {'skip_download': 'm3u8'},
193 'url': 'https://kick.com/spreen/clips/clip_01J8RGZRKHXHXXKJEHGRM932A5',
195 'id': 'clip_01J8RGZRKHXHXXKJEHGRM932A5',
197 'title': 'KLJASLDJKLJKASDLJKDAS',
199 'channel_id': '5312671',
200 'uploader': 'AnormalBarraBaja',
201 'uploader_id': '26518262',
203 'upload_date': '20240927',
204 'timestamp': 1727399987,
205 'thumbnail': 'https://clips.kick.com/clips/f2/clip_01J8RGZRKHXHXXKJEHGRM932A5/thumbnail.webp',
208 'categories': ['Minecraft'],
211 'params': {'skip_download': 'm3u8'},
214 def _real_extract(self
, url
):
215 clip_id
= self
._match
_id
(url
)
216 clip
= self
._call
_api
(f
'v2/clips/{clip_id}/play', clip_id
)['clip']
217 clip_url
= clip
['clip_url']
219 if determine_ext(clip_url
) == 'm3u8':
220 formats
= self
._extract
_m
3u8_formats
(clip_url
, clip_id
, 'mp4')
222 formats
= [{'url': clip_url
}]
227 **traverse_obj(clip
, {
228 'title': ('title', {str}
),
229 'channel': ('channel', 'slug', {str}
),
230 'channel_id': ('channel', 'id', {int}
, {str_or_none}
),
231 'uploader': ('creator', 'username', {str}
),
232 'uploader_id': ('creator', 'id', {int}
, {str_or_none}
),
233 'thumbnail': ('thumbnail_url', {url_or_none}
),
234 'duration': ('duration', {float_or_none}
),
235 'categories': ('category', 'name', {str}
, all
),
236 'timestamp': ('created_at', {parse_iso8601}
),
237 'view_count': ('views', {int_or_none}
),
238 'like_count': ('likes', {int_or_none}
),
239 'age_limit': ('is_mature', {bool}
, {lambda x
: 18 if x
else 0}),