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