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

Code before:
        video_id = self._match_id(url)
        user_id = 'guest_%u' % random.randrange(10000, 99999)
        webpage = self._download_webpage(url, video_id, headers=self.geo_verification_headers())

        data = self._download_json(
            f'https://camsoda.com/api/v1/video/vtoken/{video_id}?username={user_id}',
            video_id, headers=self.geo_verification_headers())
        if not data:
            raise ExtractorError('Unable to find configuration for stream.')

        private_servers = traverse_obj(data, ('private_servers'), expected_type=list)
        if private_servers:
            raise ExtractorError(self._ROOM_PRIVATE, expected=True)

        stream_name = traverse_obj(data, ('stream_name'), expected_type=str)
        if not stream_name:
            raise ExtractorError(self._ROOM_OFFLINE, expected=True)

        token = traverse_obj(data, ('token'), expected_type=str)

        for server in traverse_obj(data, ('edge_servers'), expected_type=list):
            formats = self._extract_m3u8_formats(
                f'https://{server}/{stream_name}_v1/index.m3u8?token={token}',
                video_id, ext='mp4', m3u8_id='hls', fatal=False, live=True)
            if formats:
                break

        self._sort_formats(formats)

        return {
            'id': video_id,
            'title': video_id,
            'description': self._html_search_meta('description', webpage, default=None),
            'is_live': True,
            'formats': formats,
            # Camsoda does not declare the RTA meta-tag
            'age_limit': 18,
        }


Review comment (refactor):
```suggestion
        if data.get('private_servers'):
            raise ExtractorError(self._ROOM_PRIVATE, expected=True)
        elif not data.get('stream_name'):
            raise ExtractorError(self._ROOM_OFFLINE, expected=True)

        token = traverse_obj(data, 'token', expected_type=str)
        
        for server in traverse_obj(data, ('edge_servers', ...)):
            formats = self._extract_m3u8_formats(
                f'https://{server}/{stream_name}_v1/index.m3u8?token={token}',
                video_id, ext='mp4', m3u8_id='hls', fatal=False, live=True)
            if formats:
                break
```

Code after:
        data = self._download_json(
            f'https://camsoda.com/api/v1/video/vtoken/{video_id}', video_id,
            query={'username': f'guest_{random.randrange(10000, 99999)}'},
            headers=self.geo_verification_headers())
        if not data:
            raise ExtractorError('Unable to find configuration for stream.')
        elif data.get('private_servers'):
            raise ExtractorError('Model is in private show.', expected=True)
        elif not data.get('stream_name'):
            raise ExtractorError('Model is offline.', expected=True)

        stream_name = traverse_obj(data, 'stream_name', expected_type=str)
        token = traverse_obj(data, 'token', expected_type=str)

        formats = []
        for server in traverse_obj(data, ('edge_servers', ...)):
            formats = self._extract_m3u8_formats(
                f'https://{server}/{stream_name}_v1/index.m3u8?token={token}',
                video_id, ext='mp4', m3u8_id='hls', fatal=False, live=True)
            if formats:
                break
        if not formats:
            self.raise_no_formats('No active streams found', expected=True)

        self._sort_formats(formats)

        return {
            'id': video_id,
            'title': self._html_extract_title(webpage),
            'description': self._html_search_meta('description', webpage, default=None),
            'is_live': True,
            'formats': formats,
            'age_limit': 18,
        }