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

Code before:
            'skip_download': True,
        },
        'skip': 'Room is offline',
    }, {
        'url': 'https://chaturbate.com/fullvideo/?b=caylin',
        'only_matching': True,
    }, {
        'url': 'https://en.chaturbate.com/siswet19/',
        'only_matching': True,
    }, {
        'url': 'https://chaturbate.eu/siswet19/',
        'only_matching': True,
    }, {
        'url': 'https://chaturbate.eu/fullvideo/?b=caylin',
        'only_matching': True,
    }, {
        'url': 'https://chaturbate.global/siswet19/',
        'only_matching': True,
    }]

    _ROOM_OFFLINE = 'Room is currently offline'
    _ROOM_PRIVATE = 'Room is currently in a private show'
    _ROOM_AWAY = 'Performer is currently away'
    _ROOM_PASSWORD = 'Room is password protected'
    _ROOM_HIDDEN = 'Hidden session in progress'
    _ROOM_BLOCKED = 'Room is not avaiable in this region'

    def _extract_from_api(self, video_id, tld):
        req = Request(
            f'https://chaturbate.{tld}/get_edge_hls_url_ajax/',
            data=f'room_slug={video_id}'.encode(),
            headers={
                'X-Requested-With': 'XMLHttpRequest',
                'Content-Type': 'application/x-www-form-urlencoded',
            },
        )
        response = self._download_json(req, video_id, fatal=False)

        status = response.get('room_status')
        if status == 'offline':
            raise ExtractorError(self._ROOM_OFFLINE, expected=True)
        elif status == 'private':
            raise ExtractorError(self._ROOM_PRIVATE, expected=True)
        elif status == 'away':
            raise ExtractorError(self._ROOM_AWAY, expected=True)
        elif status == 'hidden':
            raise ExtractorError(self._ROOM_HIDDEN, expected=True)
        elif status == 'password protected':
            raise ExtractorError(self._ROOM_PASSWORD, expected=True)
        elif status != 'public':
            return None

Review comment (refactor):
let's condense this into a single class var mapping (and remove `_ROOM_BLOCKED` since we won't need it per my suggestion below)
```suggestion
    _ERROR_MAP = {
        'offline': 'Room is currently offline',
        'private': 'Room is currently in a private show',
        'away': 'Performer is currently away',
        'password protected': 'Room is password protected',
        'hidden': 'Hidden session in progress',
    }
```

&nbsp;
then in `_extract_from_webpage` we'll need to adjust this:
```diff
             if not error:
                 if any(p in webpage for p in (
-                        self._ROOM_OFFLINE, 'offline_tipping', 'tip_offline')):
+                        self._ERROR_MAP['offline'], 'offline_tipping', 'tip_offline')):
-                    error = self._ROOM_OFFLINE
+                    error = self._ERROR_MAP['offline']
```

Code after:
            'skip_download': True,
        },
        'skip': 'Room is offline',
    }, {
        'url': 'https://chaturbate.com/fullvideo/?b=caylin',
        'only_matching': True,
    }, {
        'url': 'https://en.chaturbate.com/siswet19/',
        'only_matching': True,
    }, {
        'url': 'https://chaturbate.eu/siswet19/',
        'only_matching': True,
    }, {
        'url': 'https://chaturbate.eu/fullvideo/?b=caylin',
        'only_matching': True,
    }, {
        'url': 'https://chaturbate.global/siswet19/',
        'only_matching': True,
    }]

    _ERROR_MAP = {
        'offline': 'Room is currently offline',
        'private': 'Room is currently in a private show',
        'away': 'Performer is currently away',
        'password protected': 'Room is password protected',
        'hidden': 'Hidden session in progress',
    }

    def _extract_from_api(self, video_id, tld):
        response = self._download_json(
            f'https://chaturbate.{tld}/get_edge_hls_url_ajax/', video_id,
            data=urlencode_postdata({'room_slug': video_id}),
            headers={
                **self.geo_verification_headers(),
                'X-Requested-With': 'XMLHttpRequest',
                'Accept': 'application/json',
            }, fatal=False, impersonate=True) or {}

        status = response.get('room_status')
        if status != 'public':
            if error := self._ERROR_MAP.get(status):
                raise ExtractorError(error, expected=True)
            self.report_warning('Falling back to webpage extraction')
            return None

        m3u8_url = response.get('url')
        if not m3u8_url:
            self.raise_geo_restricted()

        return {
            'id': video_id,