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

Code before:
            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

        m3u8_url = response.get('url')
        if not m3u8_url:
            raise ExtractorError(self._ROOM_BLOCKED, expected=True)

        formats = self._extract_m3u8_formats(
            m3u8_url, video_id, ext='mp4',
            fatal=False, live=True)

        return {
            'id': video_id,
            'title': video_id,
            'thumbnail': f'https://roomimg.stream.highwebmedia.com/ri/{video_id}.jpg',
            'is_live': True,
            'formats': formats,
        }

    def _extract_from_webpage(self, video_id, tld):
        webpage = self._download_webpage(
            f'https://chaturbate.{tld}/{video_id}/', video_id,
            headers=self.geo_verification_headers())

        found_m3u8_urls = []

        data = self._parse_json(
            self._search_regex(
                r'initialRoomDossier\s*=\s*(["\'])(?P<value>(?:(?!\1).)+)\1',
                webpage, 'data', default='{}', group='value'),
            video_id, transform_source=lowercase_escape, fatal=False)

Review comment (suggestion):
```suggestion
            self.raise_geo_restricted()
```

Code after:
        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,
            'title': video_id,
            'thumbnail': f'https://roomimg.stream.highwebmedia.com/ri/{video_id}.jpg',
            'is_live': True,
            'age_limit': 18,
            'formats': self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4', live=True),
        }

    def _extract_from_webpage(self, video_id, tld):
        webpage = self._download_webpage(
            f'https://chaturbate.{tld}/{video_id}/', video_id,
            headers=self.geo_verification_headers(), impersonate=True)

        found_m3u8_urls = []

        data = self._parse_json(
            self._search_regex(
                r'initialRoomDossier\s*=\s*(["\'])(?P<value>(?:(?!\1).)+)\1',
                webpage, 'data', default='{}', group='value'),
            video_id, transform_source=lowercase_escape, fatal=False)
        if data:
            m3u8_url = url_or_none(data.get('hls_source'))
            if m3u8_url:
                found_m3u8_urls.append(m3u8_url)

        if not found_m3u8_urls:
            for m in re.finditer(
                    r'(\\u002[27])(?P<url>http.+?\.m3u8.*?)\1', webpage):
                found_m3u8_urls.append(lowercase_escape(m.group('url')))