1 from __future__ import unicode_literals
5 from .common import InfoExtractor
13 class ChaturbateIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:[^/]+\.)?chaturbate\.com/(?:fullvideo/?\?.*?\bb=)?(?P<id>[^/?&#]+)'
16 'url': 'https://www.chaturbate.com/siswet19/',
20 'title': 're:^siswet19 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
25 'skip_download': True,
27 'skip': 'Room is offline',
29 'url': 'https://chaturbate.com/fullvideo/?b=caylin',
30 'only_matching': True,
32 'url': 'https://en.chaturbate.com/siswet19/',
33 'only_matching': True,
36 _ROOM_OFFLINE = 'Room is currently offline'
38 def _real_extract(self, url):
39 video_id = self._match_id(url)
41 webpage = self._download_webpage(
42 'https://chaturbate.com/%s/' % video_id, video_id,
43 headers=self.geo_verification_headers())
47 data = self._parse_json(
49 r'initialRoomDossier\s*=\s*(["\'])(?P<value>(?:(?!\1).)+)\1',
50 webpage, 'data', default='{}', group='value'),
51 video_id, transform_source=lowercase_escape, fatal=False)
53 m3u8_url = url_or_none(data.get('hls_source'))
55 found_m3u8_urls.append(m3u8_url)
57 if not found_m3u8_urls:
59 r'(\\u002[27])(?P<url>http.+?\.m3u8.*?)\1', webpage):
60 found_m3u8_urls.append(lowercase_escape(m.group('url')))
62 if not found_m3u8_urls:
64 r'(["\'])(?P<url>http.+?\.m3u8.*?)\1', webpage):
65 found_m3u8_urls.append(m.group('url'))
68 for found_m3u8_url in found_m3u8_urls:
69 m3u8_fast_url, m3u8_no_fast_url = found_m3u8_url, found_m3u8_url.replace('_fast', '')
70 for m3u8_url in (m3u8_fast_url, m3u8_no_fast_url):
71 if m3u8_url not in m3u8_urls:
72 m3u8_urls.append(m3u8_url)
75 error = self._search_regex(
76 [r'<span[^>]+class=(["\'])desc_span\1[^>]*>(?P<error>[^<]+)</span>',
77 r'<div[^>]+id=(["\'])defchat\1[^>]*>\s*<p><strong>(?P<error>[^<]+)<'],
78 webpage, 'error', group='error', default=None)
80 if any(p in webpage for p in (
81 self._ROOM_OFFLINE, 'offline_tipping', 'tip_offline')):
82 error = self._ROOM_OFFLINE
84 raise ExtractorError(error, expected=True)
85 raise ExtractorError('Unable to find stream URL')
88 for m3u8_url in m3u8_urls:
89 for known_id in ('fast', 'slow'):
90 if '_%s' % known_id in m3u8_url:
95 formats.extend(self._extract_m3u8_formats(
96 m3u8_url, video_id, ext='mp4',
97 # ffmpeg skips segments for fast m3u8
98 preference=-10 if m3u8_id == 'fast' else None,
99 m3u8_id=m3u8_id, fatal=False, live=True))
100 self._sort_formats(formats)
104 'title': self._live_title(video_id),
105 'thumbnail': 'https://roomimg.stream.highwebmedia.com/ri/%s.jpg' % video_id,
106 'age_limit': self._rta_search(webpage),