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

Code before:
        'url': 'https://twitter.com/i/broadcasts/1yNGaQLWpejGj',
        'info_dict': {
            'id': '1yNGaQLWpejGj',
            'ext': 'mp4',
            'title': 'Andrea May Sahouri - Periscope Broadcast',
            'uploader': 'Andrea May Sahouri',
            'uploader_id': 'andreamsahouri',
            'timestamp': 1590973638,
            'upload_date': '20200601',
            'thumbnail': r're:^https?://[^?#]+\.jpg\?token=',
            'view_count': int,
        },
    }

    def _real_extract(self, url):
        broadcast_id = self._match_id(url)
        broadcast = self._call_api(
            'broadcasts/show.json', broadcast_id,
            {'ids': broadcast_id})['broadcasts'][broadcast_id]
        if not broadcast:
            raise ExtractorError('Broadcast no longer exists', expected=True)
        info = self._parse_broadcast_data(broadcast, broadcast_id)
        info['title'] = broadcast.get('status') or info.get('title')
        info['uploader_id'] = broadcast.get('twitter_username') or info.get('uploader_id')
        info['channel'] = info.get('uploader')
        info['channel_id'] = info.get('uploader_id')
        media_key = broadcast['media_key']
        source = self._call_api(
            f'live_video_stream/status/{media_key}', media_key)['source']
        m3u8_url = source.get('noRedirectPlaybackUrl') or source['location']
        if '/live_video_stream/geoblocked/' in m3u8_url:
            self.raise_geo_restricted()
        m3u8_id = compat_parse_qs(compat_urllib_parse_urlparse(
            m3u8_url).query).get('type', [None])[0]
        state, width, height = self._extract_common_format_info(broadcast)
        info['formats'] = self._extract_pscp_m3u8_formats(
            m3u8_url, broadcast_id, m3u8_id, state, width, height)
        return info


class TwitterSpacesIE(TwitterBaseIE):
    IE_NAME = 'twitter:spaces'
    _VALID_URL = TwitterBaseIE._BASE_REGEX + r'i/spaces/(?P<id>[0-9a-zA-Z]{13})'

    _TESTS = [{
        'url': 'https://twitter.com/i/spaces/1RDxlgyvNXzJL',
        'info_dict': {
            'id': '1RDxlgyvNXzJL',
            'ext': 'm4a',
            'title': 'King Carlo e la mossa Kansas City per fare il Grande Centro',
            'description': 'Twitter Space participated by annarita digiorgio, Signor Ernesto, Raffaello Colosimo, Simone M. Sepe',

Review comment (suggestion):
IMO we should map the info_dict fields as they are in `TwitterIE`, i.e. no `channel` or `channel_id`

```suggestion
        info['uploader_url'] = format_field(broadcast, 'twitter_username', 'https://twitter.com/%s', default=None)
```

Code after:
        'url': 'https://twitter.com/i/broadcasts/1yNGaQLWpejGj',
        'info_dict': {
            'id': '1yNGaQLWpejGj',
            'ext': 'mp4',
            'title': 'Andrea May Sahouri - Periscope Broadcast',
            'uploader': 'Andrea May Sahouri',
            'uploader_id': 'andreamsahouri',
            'uploader_url': 'https://twitter.com/andreamsahouri',
            'timestamp': 1590973638,
            'upload_date': '20200601',
            'thumbnail': r're:^https?://[^?#]+\.jpg\?token=',
            'view_count': int,
        },
    }, {
        'url': 'https://twitter.com/i/broadcasts/1ZkKzeyrPbaxv',
        'info_dict': {
            'id': '1ZkKzeyrPbaxv',
            'ext': 'mp4',
            'title': 'Starship | SN10 | High-Altitude Flight Test',
            'uploader': 'SpaceX',
            'uploader_id': 'SpaceX',
            'uploader_url': 'https://twitter.com/SpaceX',
            'timestamp': 1614812942,
            'upload_date': '20210303',
            'thumbnail': r're:^https?://[^?#]+\.jpg\?token=',
            'view_count': int,
        },
    }, {
        'url': 'https://twitter.com/i/broadcasts/1OyKAVQrgzwGb',
        'info_dict': {
            'id': '1OyKAVQrgzwGb',
            'ext': 'mp4',
            'title': 'Starship Flight Test',
            'uploader': 'SpaceX',
            'uploader_id': 'SpaceX',
            'uploader_url': 'https://twitter.com/SpaceX',
            'timestamp': 1681993964,
            'upload_date': '20230420',
            'thumbnail': r're:^https?://[^?#]+\.jpg\?token=',
            'view_count': int,
        },
    }]

    def _real_extract(self, url):
        broadcast_id = self._match_id(url)
        broadcast = self._call_api(
            'broadcasts/show.json', broadcast_id,
            {'ids': broadcast_id})['broadcasts'][broadcast_id]
        if not broadcast:
            raise ExtractorError('Broadcast no longer exists', expected=True)
        info = self._parse_broadcast_data(broadcast, broadcast_id)