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

Code before:

    def _real_extract(self, url):
        video_id = self._match_id(url)
        video_info = self._download_json(f'https://www.parliamentlive.tv/Event/GetShareVideo/{video_id}', video_id)

        thumbnail = video_info.get('thumbnailUrl')
        event_title = video_info['event']['title']
        timestamp = unified_timestamp(try_get(video_info, lambda x: x['event']['publishedStartTime']))
        auth = 'Bearer ' + self._download_json(
            'https://exposure.api.redbee.live/v2/customer/UKParliament/businessunit/ParliamentLive/auth/anonymous',
            video_id, headers={'Origin': 'https://videoplayback.parliamentlive.tv',
                               'Accept': 'application/json, text/plain, */*',
                               'Content-Type': 'application/json;charset=utf-8'}, data=self._DATA)['sessionToken']

        video_urls = self._download_json(
            f'https://exposure.api.redbee.live/v2/customer/UKParliament/businessunit/ParliamentLive/entitlement/{video_id}/play',
            video_id, headers={'Authorization': auth, 'Accept': 'application/json, text/plain, */*'})['formats']

        formats = []
        for format in video_urls:
            if format.get('format') == 'DASH' or format.get('format') == 'SMOOTHSTREAMING':
                formats.extend(self._extract_mpd_formats(
                    format.get('mediaLocator'), video_id, mpd_id='dash', fatal=False))
            elif format.get('format') == 'HLS':
                formats.extend(self._extract_m3u8_formats(
                    format.get('mediaLocator'), video_id, m3u8_id='hls'))

        self._sort_formats(formats)

        return {
            'id': video_id,
            'formats': formats,
            'title': event_title,
            'timestamp': timestamp,
            'thumbnail': thumbnail,
        }


Review comment (refactor):
```suggestion
            if not format.get('mediaLocator'):
                continue
            if format.get('format') in ('DASH', 'SMOOTHSTREAMING'):
                formats.extend(self._extract_mpd_formats(
                    format['mediaLocator'], video_id, mpd_id='dash', fatal=False))
            elif format.get('format') == 'HLS':
                formats.extend(self._extract_m3u8_formats(
                    format['mediaLocator'], video_id, m3u8_id='hls', fatal=False))
```

btw, are you sure SMOOTHSTREAMING is not ism but is mpd? that would be weird

Code after:
                'Origin': 'https://videoplayback.parliamentlive.tv',
                'Accept': 'application/json, text/plain, */*',
                'Content-Type': 'application/json;charset=utf-8'
            }, data=json.dumps({
                'deviceId': _DEVICE_ID,
                'device': {
                    'deviceId': _DEVICE_ID,
                    'width': 653,
                    'height': 368,
                    'type': 'WEB',
                    'name': ' Mozilla Firefox 91'
                }
            }).encode('utf-8'))['sessionToken']

        video_urls = self._download_json(
            f'https://exposure.api.redbee.live/v2/customer/UKParliament/businessunit/ParliamentLive/entitlement/{video_id}/play',
            video_id, headers={'Authorization': auth, 'Accept': 'application/json, text/plain, */*'})['formats']

        formats = []
        for format in video_urls:
            if not format.get('mediaLocator'):
                continue
            if format.get('format') == 'DASH':
                formats.extend(self._extract_mpd_formats(
                    format['mediaLocator'], video_id, mpd_id='dash', fatal=False))
            elif format.get('format') == 'SMOOTHSTREAMING':
                formats.extend(self._extract_ism_formats(
                    format['mediaLocator'], video_id, ism_id='ism', fatal=False))
            elif format.get('format') == 'HLS':
                formats.extend(self._extract_m3u8_formats(
                    format['mediaLocator'], video_id, m3u8_id='hls', fatal=False))

        self._sort_formats(formats)

        return {
            'id': video_id,
            'formats': formats,
            'title': video_info['event']['title'],
            'timestamp': unified_timestamp(try_get(video_info, lambda x: x['event']['publishedStartTime'])),
            'thumbnail': video_info.get('thumbnailUrl'),
        }