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

Code before:
class LaXarxaMesIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?laxarxames\.cat/(?:[^/]+/)*?(player|movie-details)/(?P<id>[0-9]+)'
    _NETRC_MACHINE = 'laxarxames'
    _IS_LOGGED_IN = False
    _LOGIN_URL = 'https://www.laxarxames.cat/login'
    _TESTS = [{
        'url': 'https://www.laxarxames.cat/player/3459421',
        'md5': '0966f46c34275934c19af78f3df6e2bc',
        'info_dict': {
            'id': '3459421',
            'ext': 'mp4',
            'title': 'Resum | UA Horta — UD Viladecans',
            'type': 'video/mp4',
        },
        'skip': 'Requires login',
    }]

    def _perform_login(self, username, password):
        login = self._download_json(
            'https://api.laxarxames.cat/Authorization/SignIn', None, note='Logging in', headers={
                'X-Tenantorigin': 'https://laxarxames.cat',
                'Content-Type': 'application/json',
                'Accept': 'application/json, text/plain, */*',
                'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko)',
                'Origin': 'https://www.laxarxames.cat',
            }, data=b'{"Username":"%s","Password":"%s","Device":{"PlatformCode":"WEB","Name":"Mac OS ()"}}' % (username.encode(), password.encode())
        )

        if not login['AuthorizationToken']:
            raise Exception('Login failed')
        else:
            self._set_cookie('www.laxarxames.cat', 'didomi_token', login['AuthorizationToken']['Token'])

    def _real_extract(self, url):
        video_id = self._match_id(url)
        authorization = self._get_cookies('https://www.laxarxames.cat/').get('didomi_token')

        if not authorization:
            raise Exception('No authorization token found. Log in with --netrc or --username and --password')
        mediaplayinfo = self._download_json(
            'https://api.laxarxames.cat/Media/GetMediaPlayInfo',
            video_id,
            data=b'{"MediaId":%s,"StreamType":"MAIN"}' % video_id.encode(),
            headers={
                'Authorization': 'Bearer ' + authorization.value,
                'X-Tenantorigin': 'https://laxarxames.cat',
                'Content-Type': 'application/json',
                'Accept': 'application/json, text/plain, */*',
                'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko)',
                'Origin': 'https://www.laxarxames.cat',
            }

Review comment (suggestion):
```suggestion
            }, data=json.dumps({
                'Username': username,
                'Password': password,
                'Device': {
                    'PlatformCode': 'WEB',
                    'Name': 'Mac OS ()',
                },
            }).encode('utf-8'))
```
And import json

Code after:
from .common import InfoExtractor
from ..utils import ExtractorError
from ..utils.traversal import traverse_obj


class LaXarxaMesIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?laxarxames\.cat/(?:[^/?#]+/)*?(player|movie-details)/(?P<id>\d+)'
    _NETRC_MACHINE = 'laxarxames'
    _TOKEN = None
    _TESTS = [{
        'url': 'https://www.laxarxames.cat/player/3459421',
        'md5': '0966f46c34275934c19af78f3df6e2bc',
        'info_dict': {
            'id': '6339612436112',
            'ext': 'mp4',
            'title': 'Resum | UA Horta — UD Viladecans',
            'timestamp': 1697905186,
            'thumbnail': r're:https?://.*\.jpg',
            'description': '',
            'upload_date': '20231021',
            'duration': 129.44,
            'tags': ['ott', 'esports', '23-24', ' futbol', ' futbol-partits', 'elit', 'resum'],
            'uploader_id': '5779379807001',
        },
        'skip': 'Requires login',
    }]

    def _perform_login(self, username, password):
        if self._TOKEN:
            return

        login = self._download_json(
            'https://api.laxarxames.cat/Authorization/SignIn', None, note='Logging in', headers={
                'X-Tenantorigin': 'https://laxarxames.cat',
                'Content-Type': 'application/json',
            }, data=json.dumps({
                'Username': username,
                'Password': password,
                'Device': {
                    'PlatformCode': 'WEB',
                    'Name': 'Mac OS ()',
                },
            }).encode(), expected_status=401)

        self._TOKEN = traverse_obj(login, ('AuthorizationToken', 'Token', {str}))
        if not self._TOKEN:
            raise ExtractorError('Login failed', expected=True)

    def _real_extract(self, url):
        video_id = self._match_id(url)
        if not self._TOKEN: