Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/kick.py (Python)

Code before:

from ..utils import (
    HEADRequest,
    UserNotLive,
    float_or_none,
    merge_dicts,
    str_or_none,
    traverse_obj,
    unified_timestamp,
    url_or_none,
)


class KickBaseIE(InfoExtractor):
    _API_HEADERS = {}

    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 xsrf_token:
            self._API_HEADERS.update({
                'Authorization': f'Bearer {xsrf_token.value}',
                'X-XSRF-TOKEN': xsrf_token.value,
            })
        else:
            self.write_debug('kick.com did not set XSRF-TOKEN cookie')

    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,

Review comment (bug):
```suggestion
    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 {}
```

Code after:

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',
    }, {