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

Code before:
        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) 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,
            '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')))

        if not found_m3u8_urls:

Review comment (refactor):
```suggestion
            'is_live': True,
            'age_limit': 18,
            'formats': self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4', live=True),
```

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