logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

kick.py (9823B)


  1. from .common import InfoExtractor
  2. from ..networking import HEADRequest
  3. from ..utils import (
  4. UserNotLive,
  5. determine_ext,
  6. float_or_none,
  7. int_or_none,
  8. merge_dicts,
  9. parse_iso8601,
  10. str_or_none,
  11. traverse_obj,
  12. unified_timestamp,
  13. url_or_none,
  14. )
  15. class KickBaseIE(InfoExtractor):
  16. def _real_initialize(self):
  17. self._request_webpage(
  18. HEADRequest('https://kick.com/'), None, 'Setting up session', fatal=False, impersonate=True)
  19. xsrf_token = self._get_cookies('https://kick.com/').get('XSRF-TOKEN')
  20. if not xsrf_token:
  21. self.write_debug('kick.com did not set XSRF-TOKEN cookie')
  22. KickBaseIE._API_HEADERS = {
  23. 'Authorization': f'Bearer {xsrf_token.value}',
  24. 'X-XSRF-TOKEN': xsrf_token.value,
  25. } 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/{path}', display_id, note=note,
  29. headers=merge_dicts(headers, self._API_HEADERS), impersonate=True, **kwargs)
  30. class KickIE(KickBaseIE):
  31. IE_NAME = 'kick:live'
  32. _VALID_URL = r'https?://(?:www\.)?kick\.com/(?!(?:video|categories|search|auth)(?:[/?#]|$))(?P<id>[\w-]+)'
  33. _TESTS = [{
  34. 'url': 'https://kick.com/buddha',
  35. 'info_dict': {
  36. 'id': '92722911-nopixel-40',
  37. 'ext': 'mp4',
  38. 'title': str,
  39. 'description': str,
  40. 'timestamp': int,
  41. 'thumbnail': r're:https?://.+\.jpg',
  42. 'categories': list,
  43. 'upload_date': str,
  44. 'channel': 'buddha',
  45. 'channel_id': '32807',
  46. 'uploader': 'Buddha',
  47. 'uploader_id': '33057',
  48. 'live_status': 'is_live',
  49. 'concurrent_view_count': int,
  50. 'release_timestamp': int,
  51. 'age_limit': 18,
  52. 'release_date': str,
  53. },
  54. 'params': {'skip_download': 'livestream'},
  55. # 'skip': 'livestream',
  56. }, {
  57. 'url': 'https://kick.com/xqc',
  58. 'only_matching': True,
  59. }]
  60. @classmethod
  61. def suitable(cls, url):
  62. return False if (KickVODIE.suitable(url) or KickClipIE.suitable(url)) else super().suitable(url)
  63. def _real_extract(self, url):
  64. channel = self._match_id(url)
  65. response = self._call_api(f'v2/channels/{channel}', channel)
  66. if not traverse_obj(response, 'livestream', expected_type=dict):
  67. raise UserNotLive(video_id=channel)
  68. return {
  69. 'channel': channel,
  70. 'is_live': True,
  71. 'formats': self._extract_m3u8_formats(response['playback_url'], channel, 'mp4', live=True),
  72. **traverse_obj(response, {
  73. 'id': ('livestream', 'slug', {str}),
  74. 'title': ('livestream', 'session_title', {str}),
  75. 'description': ('user', 'bio', {str}),
  76. 'channel_id': (('id', ('livestream', 'channel_id')), {int}, {str_or_none}, any),
  77. 'uploader': (('name', ('user', 'username')), {str}, any),
  78. 'uploader_id': (('user_id', ('user', 'id')), {int}, {str_or_none}, any),
  79. 'timestamp': ('livestream', 'created_at', {unified_timestamp}),
  80. 'release_timestamp': ('livestream', 'start_time', {unified_timestamp}),
  81. 'thumbnail': ('livestream', 'thumbnail', 'url', {url_or_none}),
  82. 'categories': ('recent_categories', ..., 'name', {str}),
  83. 'concurrent_view_count': ('livestream', 'viewer_count', {int_or_none}),
  84. 'age_limit': ('livestream', 'is_mature', {bool}, {lambda x: 18 if x else 0}),
  85. }),
  86. }
  87. class KickVODIE(KickBaseIE):
  88. IE_NAME = 'kick:vod'
  89. _VALID_URL = r'https?://(?:www\.)?kick\.com/[\w-]+/videos/(?P<id>[\da-f]{8}-(?:[\da-f]{4}-){3}[\da-f]{12})'
  90. _TESTS = [{
  91. 'url': 'https://kick.com/xqc/videos/8dd97a8d-e17f-48fb-8bc3-565f88dbc9ea',
  92. 'md5': '3870f94153e40e7121a6e46c068b70cb',
  93. 'info_dict': {
  94. 'id': '8dd97a8d-e17f-48fb-8bc3-565f88dbc9ea',
  95. 'ext': 'mp4',
  96. 'title': '18+ #ad 🛑LIVE🛑CLICK🛑DRAMA🛑NEWS🛑STUFF🛑REACT🛑GET IN HHERE🛑BOP BOP🛑WEEEE WOOOO🛑',
  97. 'description': 'THE BEST AT ABSOLUTELY EVERYTHING. THE JUICER. LEADER OF THE JUICERS.',
  98. 'channel': 'xqc',
  99. 'channel_id': '668',
  100. 'uploader': 'xQc',
  101. 'uploader_id': '676',
  102. 'upload_date': '20240909',
  103. 'timestamp': 1725919141,
  104. 'duration': 10155.0,
  105. 'thumbnail': r're:^https?://.*\.jpg',
  106. 'view_count': int,
  107. 'categories': ['Just Chatting'],
  108. 'age_limit': 0,
  109. },
  110. 'params': {'skip_download': 'm3u8'},
  111. }]
  112. def _real_extract(self, url):
  113. video_id = self._match_id(url)
  114. response = self._call_api(f'v1/video/{video_id}', video_id)
  115. return {
  116. 'id': video_id,
  117. 'formats': self._extract_m3u8_formats(response['source'], video_id, 'mp4'),
  118. **traverse_obj(response, {
  119. 'title': ('livestream', ('session_title', 'slug'), {str}, any),
  120. 'description': ('livestream', 'channel', 'user', 'bio', {str}),
  121. 'channel': ('livestream', 'channel', 'slug', {str}),
  122. 'channel_id': ('livestream', 'channel', 'id', {int}, {str_or_none}),
  123. 'uploader': ('livestream', 'channel', 'user', 'username', {str}),
  124. 'uploader_id': ('livestream', 'channel', 'user_id', {int}, {str_or_none}),
  125. 'timestamp': ('created_at', {parse_iso8601}),
  126. 'duration': ('livestream', 'duration', {float_or_none(scale=1000)}),
  127. 'thumbnail': ('livestream', 'thumbnail', {url_or_none}),
  128. 'categories': ('livestream', 'categories', ..., 'name', {str}),
  129. 'view_count': ('views', {int_or_none}),
  130. 'age_limit': ('livestream', 'is_mature', {bool}, {lambda x: 18 if x else 0}),
  131. }),
  132. }
  133. class KickClipIE(KickBaseIE):
  134. IE_NAME = 'kick:clips'
  135. _VALID_URL = r'https?://(?:www\.)?kick\.com/[\w-]+(?:/clips/|/?\?(?:[^#]+&)?clip=)(?P<id>clip_[\w-]+)'
  136. _TESTS = [{
  137. 'url': 'https://kick.com/mxddy?clip=clip_01GYXVB5Y8PWAPWCWMSBCFB05X',
  138. 'info_dict': {
  139. 'id': 'clip_01GYXVB5Y8PWAPWCWMSBCFB05X',
  140. 'ext': 'mp4',
  141. 'title': 'Maddy detains Abd D:',
  142. 'channel': 'mxddy',
  143. 'channel_id': '133789',
  144. 'uploader': 'AbdCreates',
  145. 'uploader_id': '3309077',
  146. 'thumbnail': r're:^https?://.*\.jpeg',
  147. 'duration': 35,
  148. 'timestamp': 1682481453,
  149. 'upload_date': '20230426',
  150. 'view_count': int,
  151. 'like_count': int,
  152. 'categories': ['VALORANT'],
  153. 'age_limit': 18,
  154. },
  155. 'params': {'skip_download': 'm3u8'},
  156. }, {
  157. 'url': 'https://kick.com/destiny?clip=clip_01H9SKET879NE7N9RJRRDS98J3',
  158. 'info_dict': {
  159. 'id': 'clip_01H9SKET879NE7N9RJRRDS98J3',
  160. 'title': 'W jews',
  161. 'ext': 'mp4',
  162. 'channel': 'destiny',
  163. 'channel_id': '1772249',
  164. 'uploader': 'punished_furry',
  165. 'uploader_id': '2027722',
  166. 'duration': 49.0,
  167. 'upload_date': '20230908',
  168. 'timestamp': 1694150180,
  169. 'thumbnail': 'https://clips.kick.com/clips/j3/clip_01H9SKET879NE7N9RJRRDS98J3/thumbnail.png',
  170. 'view_count': int,
  171. 'like_count': int,
  172. 'categories': ['Just Chatting'],
  173. 'age_limit': 0,
  174. },
  175. 'params': {'skip_download': 'm3u8'},
  176. }, {
  177. 'url': 'https://kick.com/spreen/clips/clip_01J8RGZRKHXHXXKJEHGRM932A5',
  178. 'info_dict': {
  179. 'id': 'clip_01J8RGZRKHXHXXKJEHGRM932A5',
  180. 'ext': 'mp4',
  181. 'title': 'KLJASLDJKLJKASDLJKDAS',
  182. 'channel': 'spreen',
  183. 'channel_id': '5312671',
  184. 'uploader': 'AnormalBarraBaja',
  185. 'uploader_id': '26518262',
  186. 'duration': 43.0,
  187. 'upload_date': '20240927',
  188. 'timestamp': 1727399987,
  189. 'thumbnail': 'https://clips.kick.com/clips/f2/clip_01J8RGZRKHXHXXKJEHGRM932A5/thumbnail.webp',
  190. 'view_count': int,
  191. 'like_count': int,
  192. 'categories': ['Minecraft'],
  193. 'age_limit': 0,
  194. },
  195. 'params': {'skip_download': 'm3u8'},
  196. }]
  197. def _real_extract(self, url):
  198. clip_id = self._match_id(url)
  199. clip = self._call_api(f'v2/clips/{clip_id}/play', clip_id)['clip']
  200. clip_url = clip['clip_url']
  201. if determine_ext(clip_url) == 'm3u8':
  202. formats = self._extract_m3u8_formats(clip_url, clip_id, 'mp4')
  203. else:
  204. formats = [{'url': clip_url}]
  205. return {
  206. 'id': clip_id,
  207. 'formats': formats,
  208. **traverse_obj(clip, {
  209. 'title': ('title', {str}),
  210. 'channel': ('channel', 'slug', {str}),
  211. 'channel_id': ('channel', 'id', {int}, {str_or_none}),
  212. 'uploader': ('creator', 'username', {str}),
  213. 'uploader_id': ('creator', 'id', {int}, {str_or_none}),
  214. 'thumbnail': ('thumbnail_url', {url_or_none}),
  215. 'duration': ('duration', {float_or_none}),
  216. 'categories': ('category', 'name', {str}, all),
  217. 'timestamp': ('created_at', {parse_iso8601}),
  218. 'view_count': ('views', {int_or_none}),
  219. 'like_count': ('likes', {int_or_none}),
  220. 'age_limit': ('is_mature', {bool}, {lambda x: 18 if x else 0}),
  221. }),
  222. }