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

Code before:
                    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')),
                }

        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)



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

Code after:
            else:
                is_amplify = card_name == 'amplify'
                vmap_url = get_binding_value('amplify_url_vmap') if is_amplify else get_binding_value('player_stream_url')
                content_id = get_binding_value('%s_content_id' % (card_name if is_amplify else 'player'))
                formats, subtitles = self._extract_formats_from_vmap_url(vmap_url, content_id or twid)
                self._sort_formats(formats)

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