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

Code before:
            formats = self._extract_m3u8_formats(
                source, metadata['media_key'], 'm4a' if is_audio_space else 'mp4',
                # XXX: Some audio-only Spaces need ffmpeg as downloader
                entry_protocol='m3u8' if is_audio_space else 'm3u8_native',
                live=is_live, headers=headers, fatal=False) if source else []
            if is_audio_space:
                for fmt in formats:
                    fmt.update({'vcodec': 'none', 'acodec': 'aac'})
                    if not is_live:
                        fmt['container'] = 'm4a_dash'

        participants = ', '.join(traverse_obj(
            space_data, ('participants', 'speakers', ..., 'display_name'))) or 'nobody yet'

        if not formats and live_status == 'post_live':
            self.raise_no_formats('Twitter Space ended but not downloadable yet', expected=True)

        return {
            'id': space_id,
            'description': f'Twitter Space participated by {participants}',
            'formats': formats,
            'http_headers': headers,
            'live_status': live_status,
            **traverse_obj(metadata, {
                'title': ('title', {str}),
                'release_timestamp': ('started_at', {int_or_none(scale=1000)}),
                'timestamp': ('created_at', {int_or_none(scale=1000)}),
            }),
            **traverse_obj(metadata, ('creator_results', 'result', 'legacy', {
                'uploader': ('name', {str}),
                'uploader_id': ('screen_name', {str_or_none}),
                'thumbnail': (
                    'profile_image_url_https', {lambda x: x.replace('_normal', '_400x400')}, {url_or_none},
                ),
            })),
        }


class TwitterShortenerIE(TwitterBaseIE):
    IE_NAME = 'twitter:shortener'
    _VALID_URL = r'https?://t\.co/(?P<id>[^?#]+)|tco:(?P<eid>[^?#]+)'
    _BASE_URL = 'https://t.co/'

    def _real_extract(self, url):
        mobj = self._match_valid_url(url)
        eid, shortcode = mobj.group('eid', 'id')
        if eid:
            shortcode = eid
            url = self._BASE_URL + shortcode
        new_url = self._request_webpage(url, shortcode, headers={'User-Agent': 'curl'}).url
        __UNSAFE_LINK = 'https://twitter.com/safety/unsafe_link_warning?unsafe_link='

Review comment (suggestion):
`release_timestamp` is what is used by `--wait-for-video`, so we want it to be the `scheduled_start` at least before the livestream starts

Code after:
            formats = self._extract_m3u8_formats(
                source, metadata['media_key'], 'm4a' if is_audio_space else 'mp4',
                # XXX: Some audio-only Spaces need ffmpeg as downloader
                entry_protocol='m3u8' if is_audio_space else 'm3u8_native',
                live=is_live, headers=headers, fatal=False) if source else []
            if is_audio_space:
                for fmt in formats:
                    fmt.update({'vcodec': 'none', 'acodec': 'aac'})
                    if not is_live:
                        fmt['container'] = 'm4a_dash'

        participants = ', '.join(traverse_obj(
            space_data, ('participants', 'speakers', ..., 'display_name'))) or 'nobody yet'

        if not formats and live_status == 'post_live':
            self.raise_no_formats('Twitter Space ended but not downloadable yet', expected=True)

        return {
            'id': space_id,
            'description': f'Twitter Space participated by {participants}',
            'formats': formats,
            'http_headers': headers,
            'live_status': live_status,
            **traverse_obj(metadata, {
                'title': ('title', {str}),
                # started_at is None when stream is_upcoming so fallback to scheduled_start for --wait-for-video
                'release_timestamp': (('started_at', 'scheduled_start'), {int_or_none(scale=1000)}, any),
                'timestamp': ('created_at', {int_or_none(scale=1000)}),
            }),
            **traverse_obj(metadata, ('creator_results', 'result', 'legacy', {
                'uploader': ('name', {str}),
                'uploader_id': ('screen_name', {str_or_none}),
                'thumbnail': ('profile_image_url_https', {lambda x: x.replace('_normal', '_400x400')}, {url_or_none}),
            })),
        }


class TwitterShortenerIE(TwitterBaseIE):
    IE_NAME = 'twitter:shortener'
    _VALID_URL = r'https?://t\.co/(?P<id>[^?#]+)|tco:(?P<eid>[^?#]+)'
    _BASE_URL = 'https://t.co/'

    def _real_extract(self, url):
        mobj = self._match_valid_url(url)
        eid, shortcode = mobj.group('eid', 'id')
        if eid:
            shortcode = eid
            url = self._BASE_URL + shortcode
        new_url = self._request_webpage(url, shortcode, headers={'User-Agent': 'curl'}).url
        __UNSAFE_LINK = 'https://twitter.com/safety/unsafe_link_warning?unsafe_link='
        if new_url.startswith(__UNSAFE_LINK):