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

Code before:
            })
        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,
            'title': clip.get('title'),
            'formats': formats,
            'duration': traverse_obj(clip, ('durationSeconds', {int_or_none})),
            'view_count': traverse_obj(clip, ('viewCount', {int_or_none})),
            'timestamp': traverse_obj(clip, ('createdAt', {parse_iso8601})),
            'thumbnails': thumbnails,
            'creator': traverse_obj(clip, ('broadcaster', 'displayName')),
            'channel': traverse_obj(clip, ('broadcaster', 'displayName')),
            'channel_id': traverse_obj(clip, ('broadcaster', 'id')),
            'channel_follower_count': traverse_obj(clip, ('broadcaster', 'followers', 'totalCount', {int_or_none})),
            'channel_is_verified': traverse_obj(clip, ('broadcaster', 'isPartner')),
            'uploader': traverse_obj(clip, ('curator', 'displayName')),
            'uploader_id': traverse_obj(clip, ('curator', 'id')),
            'categories': [game] if game else None,
        }


Review comment (suggestion):
I'd just unpack one big traverse_obj call for everything that you can (obviously not `formats` etc)

```py
**traverse_obj(clip, {
    'title': ('title', {str}),
    'duration': ('durationSeconds', {int_or_none}),
    'view_count': ('viewCount', {int_or_none}),
    # etc 
}),

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