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

Code before:
                formats.append({
                    'url': update_url_query(source, access_query),
                    'format_id': join_nonempty('portrait', 'best' if i == 0 else quality.get('quality')),
                    'height': int_or_none(quality.get('quality')),
                    'fps': float_or_none(quality.get('frameRate')),
                    'aspect_ratio': portrait_aspect_ratio,
                    'quality': -2,
                })

        thumbnails = []
        thumb_default = clip.get('thumbnailURL')
        thumb_asset_default = asset_default.get('thumbnailURL')
        thumbnails.append({
            'id': 'default',
            'url': thumb_asset_default,
        })
        if thumb_asset_default != thumb_default:
            thumbnails.append({
                'id': 'small',
                'url': thumb_default,
            })
        if thumb_asset_portrait := asset_portrait.get('thumbnailURL'):
            thumbnails.append({
                'id': 'portrait',
                'url': thumb_asset_portrait,
            })

        old_id = self._search_regex(r'%7C(\d+)(?:-\d+)?.mp4', formats[-1]['url'], 'old id', default=None)

        return {
            'id': clip.get('id') or slug,
            '_old_archive_ids': [make_archive_id(self, old_id)] if old_id else None,
            'display_id': slug,
            'formats': formats,
            'thumbnails': thumbnails,
            **traverse_obj(clip, {
                'title': ('title', {str}),
                'duration': ('durationSeconds', {int_or_none}),
                'view_count': ('viewCount', {int_or_none}),
                'timestamp': ('createdAt', {parse_iso8601}),
                'creator': ('broadcaster', 'displayName', {str}),
                'channel': ('broadcaster', 'displayName', {str}),
                'channel_id': ('broadcaster', 'id', {str}),
                'channel_follower_count': ('broadcaster', 'followers', 'totalCount', {int_or_none}),
                'channel_is_verified': ('broadcaster', 'isPartner', {bool}),
                'uploader': ('broadcaster', 'displayName', {str}),
                'uploader_id': ('broadcaster', 'id', {str}),
                'categories': ('game', 'displayName', {str}, filter, all, filter),
            }),
        }


Review comment (suggestion):
```suggestion
        thumb_asset_default_url = url_or_none(asset_default.get('thumbnailURL'))
        if thumb_asset_default_url:
            thumbnails.append({
                'id': 'default',
                'url': thumb_asset_default_url,
                'preference': 0,
            })
        if thumb_asset_portrait_url := url_or_none(asset_portrait.get('thumbnailURL')):
            thumbnails.append({
                'id': 'portrait',
                'url': thumb_asset_portrait_url,
                'preference': -1,
            })
        thumb_default_url = url_or_none(clip.get('thumbnailURL'))
        if thumb_default_url and thumb_default_url != thumb_asset_default_url:
            thumbnails.append({
                'id': 'small',
                'url': thumb_default_url,
                'preference': -2,
            })
```

Code after:
                'format_id': join_nonempty('portrait', source.get('quality')),
                'height': int_or_none(source.get('quality')),
                'fps': float_or_none(source.get('frameRate')),
                'aspect_ratio': portrait_aspect_ratio,
                'quality': -2,
            })

        thumbnails = []
        thumb_asset_default_url = url_or_none(asset_default.get('thumbnailURL'))
        if thumb_asset_default_url:
            thumbnails.append({
                'id': 'default',
                'url': thumb_asset_default_url,
                'preference': 0,
            })
        if thumb_asset_portrait_url := url_or_none(asset_portrait.get('thumbnailURL')):
            thumbnails.append({
                'id': 'portrait',
                'url': thumb_asset_portrait_url,
                'preference': -1,
            })
        thumb_default_url = url_or_none(clip.get('thumbnailURL'))
        if thumb_default_url and thumb_default_url != thumb_asset_default_url:
            thumbnails.append({
                'id': 'small',
                'url': thumb_default_url,
                'preference': -2,
            })

        old_id = self._search_regex(r'%7C(\d+)(?:-\d+)?.mp4', formats[-1]['url'], 'old id', default=None)

        return {
            'id': clip.get('id') or slug,
            '_old_archive_ids': [make_archive_id(self, old_id)] if old_id else None,
            'display_id': slug,
            'formats': formats,
            'thumbnails': thumbnails,
            **traverse_obj(clip, {
                'title': ('title', {str}),
                'duration': ('durationSeconds', {int_or_none}),
                'view_count': ('viewCount', {int_or_none}),
                'timestamp': ('createdAt', {parse_iso8601}),
                'creators': ('broadcaster', 'displayName', {str}, filter, all),
                'channel': ('broadcaster', 'displayName', {str}),
                'channel_id': ('broadcaster', 'id', {str}),
                'channel_follower_count': ('broadcaster', 'followers', 'totalCount', {int_or_none}),
                'channel_is_verified': ('broadcaster', 'isPartner', {bool}),
                'uploader': ('broadcaster', 'displayName', {str}),
                'uploader_id': ('broadcaster', 'id', {str}),
                'categories': ('game', 'displayName', {str}, filter, all, filter),
            }),