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

Code before:

                return {
                    'formats': formats,
                    'subtitles': subtitles,
                    'thumbnails': thumbnails,
                    'duration': int_or_none(get_binding_value(
                        'content_duration_seconds')),
                }

        entries = []
        media_path = ((None, 'quoted_status'), 'extended_entities', 'media', ...)
        medias = traverse_obj(status, media_path, expected_type=dict, default=[])
        for media in medias:
            if not media or media.get('type') == 'photo':
                continue

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

Review comment (refactor):
Not a necessary change, but I think it's better to make `extract_from_card_info` accept an input of `None` and then do:
```suggestion
        data = extract_from_card_info(status.get('card'))
        if data:
            entries.append({**info, **data, 'display_id': twid})
```

Code after:

                thumbnails = []
                for suffix in ('_small', '', '_large', '_x_large', '_original'):
                    image = get_binding_value('player_image' + suffix) or {}
                    image_url = image.get('url')
                    if not image_url or '/player-placeholder' in image_url:
                        continue
                    thumbnails.append({
                        'id': suffix[1:] if suffix else 'medium',
                        'url': image_url,
                        'width': int_or_none(image.get('width')),
                        'height': int_or_none(image.get('height')),
                    })

                return {
                    '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})'