Repository: yt-dlp/yt-dlp

Issue:
kick.com
### DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

- [X] I understand that I will be **blocked** if I remove or skip any mandatory\* field

### Checklist

- [X] I'm reporting a new site support request
- [X] I've verified that I'm running yt-dlp version **2022.11.11** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
- [X] I've checked that all provided URLs are playable in a browser with the same IP and same login details
- [X] I've checked that none of provided URLs [violate any copyrights](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#is-the-website-primarily-used-for-piracy) or contain any [DRM](https://en.wikipedia.org/wiki/Digital_rights_management) to the best of my knowledge
- [X] I've searched the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
- [X] I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
- [X] I've read about [sharing account credentials](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#are-you-willing-to-share-account-details-if-needed) and am willing to share it if required

### Region

United States

### Example URLs

- Livestream https://kick.com/kmack710 (might be offline)
- Any URL from the live channels page on https://kick.com/categories in case above is offline

### Provide a description that is worded well enough to be understood

The site appears to use all AWS services, live-video.net is the domain for the m3u8 playlist. Streams work without logging in.

### Provide verbose output that clearly demonstrates the problem

- [X] Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
- [X] Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below

### Complete Verbose Output

```shell
yt-dlp -vU https://kick.com/kmack710
[debug] Command-line config: ['-vU', 'https://kick.com/kmack710']
[debug] Portable config "C:\Users\User\scoop\apps\yt-dlp\current\yt-dlp.conf": []
[debug] Encodings: locale cp1252, fs utf-8, pref cp1252, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version 2022.11.11 [8b64402] (win_exe)
[debug] Python 3.8.10 (CPython AMD64 64bit) - Windows-10-10.0.22621-SP0 (OpenSSL 1.1.1k  25 Mar 2021)
[debug] exe versions: ffmpeg N-109235-g1009396953-20221127 (setts), ffprobe N-109235-g1009396953-20221127
[debug] Optional libraries: Cryptodome-3.15.0, brotli-1.0.9, certifi-2022.09.24, mutagen-1.46.0, sqlite3-2.6.0, websockets-10.4
[debug] Proxy map: {}
[debug] Loaded 1723 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
Latest version: 2022.11.11, Current version: 2022.11.11
yt-dlp is up to date (2022.11.11)
[debug] [generic] Extracting URL: https://kick.com/kmack710
[generic] kmack710: Downloading webpage
WARNING: [generic] Falling back on generic information extractor
[generic] kmack710: Extracting information
[debug] Looking for embeds
ERROR: Unsupported URL: https://kick.com/kmack710
Traceback (most recent call last):
  File "yt_dlp\YoutubeDL.py", line 1485, in wrapper
  File "yt_dlp\YoutubeDL.py", line 1561, in __extract_info
  File "yt_dlp\extractor\common.py", line 674, in extract
  File "yt_dlp\extractor\generic.py", line 2721, in _real_extract
yt_dlp.utils.UnsupportedError: Unsupported URL: https://kick.com/kmack710
```



Discussion:
To add to this; kick.com is using Amazon IVS as its backend. Most of the same methods used to extract Twitch videos should be applicable here, as they share a tech stack. It might even be worth it to try aliasing the kick.com decoder to Twitch's.

Resolving patch:
diff --git a/yt_dlp/extractor/_extractors.py b/yt_dlp/extractor/_extractors.py
--- a/yt_dlp/extractor/_extractors.py
+++ b/yt_dlp/extractor/_extractors.py
@@ -836,6 +836,10 @@
     KhanAcademyIE,
     KhanAcademyUnitIE,
 )
+from .kick import (
+    KickIE,
+    KickVODIE,
+)
 from .kicker import KickerIE
 from .kickstarter import KickStarterIE
 from .kinja import KinjaEmbedIE
diff --git a/yt_dlp/extractor/kick.py b/yt_dlp/extractor/kick.py
new file mode 100644
--- /dev/null
+++ b/yt_dlp/extractor/kick.py
@@ -0,0 +1,127 @@
+from .common import InfoExtractor
+
+from ..utils import (
+    HEADRequest,
+    UserNotLive,
+    float_or_none,
+    merge_dicts,
+    str_or_none,
+    traverse_obj,
+    unified_timestamp,
+    url_or_none,
+)
+
+
+class KickBaseIE(InfoExtractor):
+    def _real_initialize(self):
+        self._request_webpage(HEADRequest('https://kick.com/'), None, 'Setting up session')
+        xsrf_token = self._get_cookies('https://kick.com/').get('XSRF-TOKEN')
+        if not xsrf_token:
+            self.write_debug('kick.com did not set XSRF-TOKEN cookie')
+        KickBaseIE._API_HEADERS = {
+            'Authorization': f'Bearer {xsrf_token.value}',
+            'X-XSRF-TOKEN': xsrf_token.value,
+        } if xsrf_token else {}
+
+    def _call_api(self, path, display_id, note='Downloading API JSON', headers={}, **kwargs):
+        return self._download_json(
+            f'https://kick.com/api/v1/{path}', display_id, note=note,
+            headers=merge_dicts(headers, self._API_HEADERS), **kwargs)
+
+
+class KickIE(KickBaseIE):
+    _VALID_URL = r'https?://(?:www\.)?kick\.com/(?!(?:video|categories|search|auth)(?:[/?#]|$))(?P<id>[\w_]+)'
+    _TESTS = [{
+        'url': 'https://kick.com/yuppy',
+        'info_dict': {
+            'id': '6cde1-kickrp-joe-flemmingskick-info-heremust-knowmust-see21',
+            'ext': 'mp4',
+            'title': str,
+            'description': str,
+            'channel': 'yuppy',
+            'channel_id': '33538',
+            'uploader': 'Yuppy',
+            'uploader_id': '33793',
+            'upload_date': str,
+            'live_status': 'is_live',
+            'timestamp': int,
+            'thumbnail': r're:^https?://.*\.jpg',
+            'categories': list,
+        },
+        'skip': 'livestream',
+    }, {
+        'url': 'https://kick.com/kmack710',
+        'only_matching': True,
+    }]
+
+    def _real_extract(self, url):
+        channel = self._match_id(url)
+        response = self._call_api(f'channels/{channel}', channel)
+        if not traverse_obj(response, 'livestream', expected_type=dict):
+            raise UserNotLive(video_id=channel)
+
+        return {
+            'id': str(traverse_obj(
+                response, ('livestream', ('slug', 'id')), get_all=False, default=channel)),
+            'formats': self._extract_m3u8_formats(
+                response['playback_url'], channel, 'mp4', live=True),
+            'title': traverse_obj(
+                response, ('livestream', ('session_title', 'slug')), get_all=False, default=''),
+            'description': traverse_obj(response, ('user', 'bio')),
+            'channel': channel,
+            'channel_id': str_or_none(traverse_obj(response, 'id', ('livestream', 'channel_id'))),
+            'uploader': traverse_obj(response, 'name', ('user', 'username')),
+            'uploader_id': str_or_none(traverse_obj(response, 'user_id', ('user', 'id'))),
+            'is_live': True,
+            'timestamp': unified_timestamp(traverse_obj(response, ('livestream', 'created_at'))),
+            'thumbnail': traverse_obj(
+                response, ('livestream', 'thumbnail', 'url'), expected_type=url_or_none),
+            'categories': traverse_obj(response, ('recent_categories', ..., 'name')),
+        }
+
+
+class KickVODIE(KickBaseIE):
+    _VALID_URL = r'https?://(?:www\.)?kick\.com/video/(?P<id>[\da-f]{8}-(?:[\da-f]{4}-){3}[\da-f]{12})'
+    _TESTS = [{
+        'url': 'https://kick.com/video/54244b5e-050a-4df4-a013-b2433dafbe35',
+        'md5': '73691206a6a49db25c5aa1588e6538fc',
+        'info_dict': {
+            'id': '54244b5e-050a-4df4-a013-b2433dafbe35',
+            'ext': 'mp4',
+            'title': 'Making 710-carBoosting. Kinda No Pixel inspired.  !guilded  - !links',
+            'description': 'md5:a0d3546bf7955d0a8252ffe0fd6f518f',
+            'channel': 'kmack710',
+            'channel_id': '16278',
+            'uploader': 'Kmack710',
+            'uploader_id': '16412',
+            'upload_date': '20221206',
+            'timestamp': 1670318289,
+            'duration': 40104.0,
+            'thumbnail': r're:^https?://.*\.jpg',
+            'categories': ['Grand Theft Auto V'],
+        },
+        'params': {
+            'skip_download': 'm3u8',
+        },
+    }]
+
+    def _real_extract(self, url):
+        video_id = self._match_id(url)
+        response = self._call_api(f'video/{video_id}', video_id)
+
+        return {
+            'id': video_id,
+            'formats': self._extract_m3u8_formats(response['source'], video_id, 'mp4'),
+            'title': traverse_obj(
+                response, ('livestream', ('session_title', 'slug')), get_all=False, default=''),
+            'description': traverse_obj(response, ('livestream', 'channel', 'user', 'bio')),
+            'channel': traverse_obj(response, ('livestream', 'channel', 'slug')),
+            'channel_id': str_or_none(traverse_obj(response, ('livestream', 'channel', 'id'))),
+            'uploader': traverse_obj(response, ('livestream', 'channel', 'user', 'username')),
+            'uploader_id': str_or_none(traverse_obj(response, ('livestream', 'channel', 'user_id'))),
+            'timestamp': unified_timestamp(response.get('created_at')),
+            'duration': float_or_none(traverse_obj(response, ('livestream', 'duration')), scale=1000),
+            'thumbnail': traverse_obj(
+                response, ('livestream', 'thumbnail'), expected_type=url_or_none),
+            'categories': traverse_obj(response, ('livestream', 'categories', ..., 'name')),
+        }


Test patch: