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

Code before:
                    'videoID': item_id,
                },
            }, {
                'operationName': 'VideoPlayer_ChapterSelectButtonVideo',
                'variables': {
                    'includePrivate': False,
                    'videoID': item_id,
                },
            }, {
                'operationName': 'VideoPlayer_VODSeekbarPreviewVideo',
                'variables': {
                    'includePrivate': False,
                    'videoID': item_id,
                },
            }],
            'Downloading stream metadata GraphQL')

        initial_index = 1 if data[0].get('errors') else 0

        video = traverse_obj(data, (initial_index, 'data', 'video'))
        if video is None:
            raise ExtractorError(f'Video {item_id} does not exist', expected=True)

        video['moments'] = traverse_obj(data, (initial_index + 1, 'data', 'video', 'moments', 'edges', ..., 'node'))
        video['storyboard'] = traverse_obj(
            data, (initial_index + 2, 'data', 'video', 'seekPreviewsURL'), expected_type=url_or_none)

        return video

    def _extract_info(self, info):
        status = info.get('status')
        if status == 'recording':
            is_live = True
        elif status == 'recorded':
            is_live = False
        else:
            is_live = None
        _QUALITIES = ('small', 'medium', 'large')
        quality_key = qualities(_QUALITIES)
        thumbnails = []
        preview = info.get('preview')
        if isinstance(preview, dict):
            for thumbnail_id, thumbnail_url in preview.items():
                thumbnail_url = url_or_none(thumbnail_url)
                if not thumbnail_url:
                    continue
                if thumbnail_id not in _QUALITIES:
                    continue
                thumbnails.append({
                    'url': thumbnail_url,
                    'preference': quality_key(thumbnail_id),

Review comment (refactor):
```suggestion
        video = traverse_obj(data, (..., 'data', 'video'), get_all=False)
        if not video:
            raise ExtractorError(f'Video {item_id} does not exist', expected=True)

        video['moments'] = traverse_obj(data, (..., 'data', 'video', 'moments', 'edges', ..., 'node'))
        video['storyboard'] = traverse_obj(data, (..., 'data', 'video', 'seekPreviewsURL',{url_or_none}), get_all=False)

```
Wouldn't this work?

Code after:
                    'videoID': item_id,
                },
            }, {
                'operationName': 'VideoPlayer_ChapterSelectButtonVideo',
                'variables': {
                    'includePrivate': False,
                    'videoID': item_id,
                },
            }, {
                'operationName': 'VideoPlayer_VODSeekbarPreviewVideo',
                'variables': {
                    'includePrivate': False,
                    'videoID': item_id,
                },
            }],
            'Downloading stream metadata GraphQL')

        video = traverse_obj(data, (..., 'data', 'video'), get_all=False)
        if video is None:
            raise ExtractorError(f'Video {item_id} does not exist', expected=True)

        video['moments'] = traverse_obj(data, (..., 'data', 'video', 'moments', 'edges', ..., 'node'))
        video['storyboard'] = traverse_obj(
            data, (..., 'data', 'video', 'seekPreviewsURL', {url_or_none}), get_all=False)

        return video

    def _extract_info(self, info):
        status = info.get('status')
        if status == 'recording':
            is_live = True
        elif status == 'recorded':
            is_live = False
        else:
            is_live = None
        _QUALITIES = ('small', 'medium', 'large')
        quality_key = qualities(_QUALITIES)
        thumbnails = []
        preview = info.get('preview')
        if isinstance(preview, dict):
            for thumbnail_id, thumbnail_url in preview.items():
                thumbnail_url = url_or_none(thumbnail_url)
                if not thumbnail_url:
                    continue
                if thumbnail_id not in _QUALITIES:
                    continue
                thumbnails.append({
                    'url': thumbnail_url,
                    'preference': quality_key(thumbnail_id),
                })
        return {