]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/kick.py
1 from .common
import InfoExtractor
2 from ..networking
import HEADRequest
14 class KickBaseIE(InfoExtractor
):
15 def _real_initialize(self
):
16 self
._request
_webpage
(
17 HEADRequest('https://kick.com/'), None, 'Setting up session', fatal
=False, impersonate
=True)
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
), impersonate
=True, **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/58bac65b-e641-4476-a7ba-3707a35e60e3',
87 'md5': '3870f94153e40e7121a6e46c068b70cb',
89 'id': '58bac65b-e641-4476-a7ba-3707a35e60e3',
91 'title': '🤠REBIRTH IS BACK!!!!🤠!stake CODE JAREDFPS 🤠',
92 'description': 'md5:02b0c46f9b4197fb545ab09dddb85b1d',
93 'channel': 'jaredfps',
94 'channel_id': '26608',
95 'uploader': 'JaredFPS',
96 'uploader_id': '26799',
97 'upload_date': '20240402',
98 'timestamp': 1712097108,
100 'thumbnail': r
're:^https?://.*\.jpg',
101 'categories': ['Call of Duty: Warzone'],
104 'skip_download': 'm3u8',
106 'expected_warnings': [r
'impersonation'],
109 def _real_extract(self
, url
):
110 video_id
= self
._match
_id
(url
)
111 response
= self
._call
_api
(f
'video/{video_id}', video_id
)
115 'formats': self
._extract
_m
3u8_formats
(response
['source'], video_id
, 'mp4'),
116 'title': traverse_obj(
117 response
, ('livestream', ('session_title', 'slug')), get_all
=False, default
=''),
118 'description': traverse_obj(response
, ('livestream', 'channel', 'user', 'bio')),
119 'channel': traverse_obj(response
, ('livestream', 'channel', 'slug')),
120 'channel_id': str_or_none(traverse_obj(response
, ('livestream', 'channel', 'id'))),
121 'uploader': traverse_obj(response
, ('livestream', 'channel', 'user', 'username')),
122 'uploader_id': str_or_none(traverse_obj(response
, ('livestream', 'channel', 'user_id'))),
123 'timestamp': unified_timestamp(response
.get('created_at')),
124 'duration': float_or_none(traverse_obj(response
, ('livestream', 'duration')), scale
=1000),
125 'thumbnail': traverse_obj(
126 response
, ('livestream', 'thumbnail'), expected_type
=url_or_none
),
127 'categories': traverse_obj(response
, ('livestream', 'categories', ..., 'name')),