3 from .common
import InfoExtractor
12 class ChaturbateIE(InfoExtractor
):
13 _VALID_URL
= r
'https?://(?:[^/]+\.)?chaturbate\.(?P<tld>com|eu|global)/(?:fullvideo/?\?.*?\bb=)?(?P<id>[^/?&#]+)'
15 'url': 'https://www.chaturbate.com/siswet19/',
19 'title': 're:^siswet19 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
24 'skip_download': True,
26 'skip': 'Room is offline',
28 'url': 'https://chaturbate.com/fullvideo/?b=caylin',
29 'only_matching': True,
31 'url': 'https://en.chaturbate.com/siswet19/',
32 'only_matching': True,
34 'url': 'https://chaturbate.eu/siswet19/',
35 'only_matching': True,
37 'url': 'https://chaturbate.eu/fullvideo/?b=caylin',
38 'only_matching': True,
40 'url': 'https://chaturbate.global/siswet19/',
41 'only_matching': True,
45 'offline': 'Room is currently offline',
46 'private': 'Room is currently in a private show',
47 'away': 'Performer is currently away',
48 'password protected': 'Room is password protected',
49 'hidden': 'Hidden session in progress',
52 def _extract_from_api(self
, video_id
, tld
):
53 response
= self
._download
_json
(
54 f
'https://chaturbate.{tld}/get_edge_hls_url_ajax/', video_id
,
55 data
=urlencode_postdata({'room_slug': video_id
}),
57 **self
.geo_verification_headers(),
58 'X-Requested-With': 'XMLHttpRequest',
59 'Accept': 'application/json',
60 }, fatal
=False, impersonate
=True) or {}
62 m3u8_url
= response
.get('url')
64 status
= response
.get('room_status')
65 if error
:= self
._ERROR
_MAP
.get(status
):
66 raise ExtractorError(error
, expected
=True)
67 if status
== 'public':
68 self
.raise_geo_restricted()
69 self
.report_warning(f
'Got status "{status}" from API; falling back to webpage extraction')
75 'thumbnail': f
'https://roomimg.stream.highwebmedia.com/ri/{video_id}.jpg',
78 'formats': self
._extract
_m
3u8_formats
(m3u8_url
, video_id
, ext
='mp4', live
=True),
81 def _extract_from_html(self
, video_id
, tld
):
82 webpage
= self
._download
_webpage
(
83 f
'https://chaturbate.{tld}/{video_id}/', video_id
,
84 headers
=self
.geo_verification_headers(), impersonate
=True)
88 data
= self
._parse
_json
(
90 r
'initialRoomDossier\s*=\s*(["\'])(?P
<value
>(?
:(?
!\
1).)+)\
1',
91 webpage, 'data
', default='{}', group='value
'),
92 video_id, transform_source=lowercase_escape, fatal=False)
94 m3u8_url = url_or_none(data.get('hls_source
'))
96 found_m3u8_urls.append(m3u8_url)
98 if not found_m3u8_urls:
100 r'(\\u002
[27])(?P
<url
>http
.+?\
.m3u8
.*?
)\
1', webpage):
101 found_m3u8_urls.append(lowercase_escape(m.group('url
')))
103 if not found_m3u8_urls:
104 for m in re.finditer(
105 r'(["\'])(?P<url>http.+?\.m3u8.*?)\1', webpage):
106 found_m3u8_urls.append(m.group('url'))
109 for found_m3u8_url in found_m3u8_urls:
110 m3u8_fast_url, m3u8_no_fast_url = found_m3u8_url, found_m3u8_url.replace('_fast', '')
111 for m3u8_url in (m3u8_fast_url, m3u8_no_fast_url):
112 if m3u8_url not in m3u8_urls:
113 m3u8_urls.append(m3u8_url)
116 error = self._search_regex(
117 [r'<span[^>]+class=(["\'])desc_span\
1[^
>]*>(?P
<error
>[^
<]+)</span
>',
118 r'<div
[^
>]+id=(["\'])defchat\1[^>]*>\s*<p><strong>(?P<error>[^<]+)<'],
119 webpage, 'error', group='error', default=None)
121 if any(p in webpage for p in (
122 self._ERROR_MAP['offline'], 'offline_tipping', 'tip_offline')):
123 error = self._ERROR_MAP['offline']
125 raise ExtractorError(error, expected=True)
126 raise ExtractorError('Unable to find stream URL')
129 for m3u8_url in m3u8_urls:
130 for known_id in ('fast', 'slow'):
131 if f'_{known_id}' in m3u8_url:
136 formats.extend(self._extract_m3u8_formats(
137 m3u8_url, video_id, ext='mp4',
138 # ffmpeg skips segments for fast m3u8
139 preference=-10 if m3u8_id == 'fast' else None,
140 m3u8_id=m3u8_id, fatal=False, live=True))
145 'thumbnail': f'https://roomimg.stream.highwebmedia.com/ri/{video_id}.jpg',
146 'age_limit': self._rta_search(webpage),
151 def _real_extract(self, url):
152 video_id, tld = self._match_valid_url(url).group('id', 'tld')
153 return self._extract_from_api(video_id, tld) or self._extract_from_html(video_id, tld)