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

Code before:
                'variables': {'slug': slug},
            }],
            'Downloading clip GraphQL')[0]['data']['clip']

        if not clip:
            raise ExtractorError(
                'This clip is no longer available', expected=True)

        access_query = {
            'sig': clip['playbackAccessToken']['signature'],
            'token': clip['playbackAccessToken']['value'],
        }
        asset_default = traverse_obj(clip, ('assets', 0), {})
        asset_portrait = traverse_obj(clip, ('assets', 1), {})
        game = traverse_obj(clip, ('game', 'displayName'))

        formats = []
        for quality in traverse_obj(asset_default, ('videoQualities'), default=[]):
            if source := traverse_obj(quality, ('sourceURL', {url_or_none})):
                formats.append({
                    'url': update_url_query(source, access_query),
                    'format_id': quality.get('quality'),
                    'height': int_or_none(quality.get('quality')),
                    'fps': float_or_none(quality.get('frameRate')),
                    'aspect_ratio': float_or_none(asset_default.get('aspectRatio')),
                })

        for i, quality in enumerate(traverse_obj(asset_portrait, ('videoQualities'), default=[])):
            if source := traverse_obj(quality, ('sourceURL', {url_or_none})):
                formats.append({
                    'url': update_url_query(source, access_query),
                    'format_id': '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': float_or_none(asset_portrait.get('aspectRatio')),
                    'quality': -1,
                })

        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'):

Review comment (suggestion):
`from yt_dlp.utils.traversal import traverse_obj, value`
```suggestion
        default_aspect_ratio = float_or_none(asset_default.get('aspectRatio'))
        formats.extend(traverse_obj(asset_default, ('videoQualities', lambda _, v: url_or_none(v['sourceURL']), {
            'url': ('sourceURL', {update_url_query(query=access_query)}),
            'format_id': ('quality, {str}),
            'height': ('quality', {int_or_none}),
            'fps': ('frameRate', {float_or_none}),
            'aspect_ratio': {value(default_aspect_ratio)},
        })))
```

Code after:
                'operationName': 'ShareClipRenderStatus',
                'variables': {'slug': slug},
            }],
            'Downloading clip GraphQL')[0]['data']['clip']

        if not clip:
            raise ExtractorError(
                'This clip is no longer available', expected=True)

        access_query = {
            'sig': clip['playbackAccessToken']['signature'],
            'token': clip['playbackAccessToken']['value'],
        }
        asset_default = traverse_obj(clip, ('assets', 0, {dict})) or {}
        asset_portrait = traverse_obj(clip, ('assets', 1, {dict})) or {}

        formats = []
        default_aspect_ratio = float_or_none(asset_default.get('aspectRatio'))
        formats.extend(traverse_obj(asset_default, ('videoQualities', lambda _, v: url_or_none(v['sourceURL']), {
            'url': ('sourceURL', {update_url_query(query=access_query)}),
            'format_id': ('quality', {str}),
            'height': ('quality', {int_or_none}),
            'fps': ('frameRate', {float_or_none}),
            'aspect_ratio': {value(default_aspect_ratio)},
        })))
        portrait_aspect_ratio = float_or_none(asset_portrait.get('aspectRatio'))
        for source in traverse_obj(asset_portrait, ('videoQualities', lambda _, v: url_or_none(v['sourceURL']))):
            formats.append({
                'url': update_url_query(source['sourceURL'], access_query),
                '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'))