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

Code before:

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

        contenturl = mediaplayinfo['ContentUrl']
        title = mediaplayinfo['Title']

        videodata = self._download_json(
            'https://edge.api.brightcove.com/playback/v1/accounts/5779379807001/videos/' + contenturl,
            video_id,
            headers={
                'Accept': 'application/json;pk=BCpkADawqM2uXEFYflHlCdYKQdRAfbdvR3tpOY9_jxup5aqCrMmJxjXtV6k9Khk7hKqFFp15BwULNmQkWBik0SJgtgqDAoni09Ezx2w4dIGs1GAjhnLMWXaeCmveEusJKQYs83DIlSUIPccu'
            }
        )

        sources = videodata['sources']

        formats = []
        for source in sources:
            url = source['src']
            type = ''
            manifest_url = None
            if 'type' in source:
                type = source['type']
                manifest_url = source['src']
            else:
                type = 'video/mp4'
            formats.append({
                'url': url,
                'type': type,
                'manifest_url': manifest_url
            })

        return {

Review comment (refactor):
Could this just be handed off to the Brightcove extractor?
I have not tried this, but something like:
```python
return self.url_result(
    f'http://players.brightcove.net/5779379807001/default_default/index.html?videoId={contenturl}',
    BrightcoveNewIE, video_id, title)
```

Code after:
            '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:
            self.raise_login_required()

        media_play_info = self._download_json(
            'https://api.laxarxames.cat/Media/GetMediaPlayInfo', video_id,
            data=json.dumps({
                'MediaId': int(video_id),
                'StreamType': 'MAIN'
            }).encode(), headers={
                'Authorization': f'Bearer {self._TOKEN}',
                'X-Tenantorigin': 'https://laxarxames.cat',
                'Content-Type': 'application/json',
            })

        if not traverse_obj(media_play_info, ('ContentUrl', {str})):
            self.raise_no_formats('No video found', expected=True)

        return self.url_result(
            f'https://players.brightcove.net/5779379807001/default_default/index.html?videoId={media_play_info["ContentUrl"]}',
            BrightcoveNewIE, video_id, media_play_info.get('Title'))