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

Code before:

            data = extract_from_video_info(media)
            if data:
                entries.append({**info, **data, 'display_id': twid})
            continue

        card = status.get('card')
        if card:
            data = extract_from_card_info(card)
            if data:
                entries.append({**info, **data, 'display_id': twid})

        if not entries:
            expanded_url = traverse_obj(status, ('entities', 'urls', 0, 'expanded_url'))
            if not expanded_url or expanded_url == url:
                raise ExtractorError('No video could be found in this tweet')

            transparent_result = self.url_result(expanded_url, transparent=True, display_id=twid, **info)
            if not url_or_none(transparent_result.get('url')) and not transparent_result.get('formats'):
                raise ExtractorError('No video could be found in this tweet')

            return transparent_result

        if len(entries) == 1:
            # compat: tweet id was previously used instead of media id
            return {**entries[0], 'id': twid}

        return self.playlist_result(entries, multi_video=True, **info)


class TwitterAmplifyIE(TwitterBaseIE):
    IE_NAME = 'twitter:amplify'
    _VALID_URL = r'https?://amp\.twimg\.com/v/(?P<id>[0-9a-f\-]{36})'

    _TEST = {
        'url': 'https://amp.twimg.com/v/0ba0c3c7-0af3-4c0a-bed5-7efd1ffa2951',
        'md5': '7df102d0b9fd7066b86f3159f8e81bf6',
        'info_dict': {
            'id': '0ba0c3c7-0af3-4c0a-bed5-7efd1ffa2951',
            'ext': 'mp4',
            'title': 'Twitter Video',
            'thumbnail': 're:^https?://.*',
        },
    }

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)

        vmap_url = self._html_search_meta(
            'twitter:amplify:vmap', webpage, 'vmap url')

Review comment (suggestion):
Another way to handle compat is to set `_old_archive_ids`

Code after:
                    'formats': formats,
                    'subtitles': subtitles,
                    'thumbnails': thumbnails,
                    'duration': int_or_none(get_binding_value(
                        'content_duration_seconds')),
                }

        media_path = ((None, 'quoted_status'), 'extended_entities', 'media', lambda _, m: m['type'] != 'photo')
        videos = map(extract_from_video_info, traverse_obj(status, media_path, expected_type=dict))
        entries = [{**info, **data, 'display_id': twid} for data in videos if data]

        data = extract_from_card_info(status.get('card'))
        if data:
            entries.append({**info, **data, 'display_id': twid})

        if not entries:
            expanded_url = traverse_obj(status, ('entities', 'urls', 0, 'expanded_url'), expected_type=url_or_none)
            if not expanded_url or expanded_url == url:
                raise ExtractorError('No video could be found in this tweet', expected=True)

            return self.url_result(expanded_url, display_id=twid, **info)

        entries[0]['_old_archive_ids'] = [make_archive_id(self, twid)]

        if len(entries) == 1:
            return entries[0]

        for index, entry in enumerate(entries, 1):
            entry['title'] += f' #{index}'

        return self.playlist_result(entries, **info)


class TwitterAmplifyIE(TwitterBaseIE):
    IE_NAME = 'twitter:amplify'
    _VALID_URL = r'https?://amp\.twimg\.com/v/(?P<id>[0-9a-f\-]{36})'

    _TEST = {
        'url': 'https://amp.twimg.com/v/0ba0c3c7-0af3-4c0a-bed5-7efd1ffa2951',
        'md5': '7df102d0b9fd7066b86f3159f8e81bf6',
        'info_dict': {
            'id': '0ba0c3c7-0af3-4c0a-bed5-7efd1ffa2951',
            'ext': 'mp4',
            'title': 'Twitter Video',
            'thumbnail': 're:^https?://.*',
        },
    }

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)