]>
Commit | Line | Data |
---|---|---|
0f61db44 | 1 | from __future__ import unicode_literals |
1bd39035 | 2 | |
42697bab | 3 | import re |
4 | ||
1bd39035 | 5 | from .common import InfoExtractor |
0f61db44 | 6 | from ..utils import ExtractorError |
1bd39035 P |
7 | |
8 | ||
9 | class ChaturbateIE(InfoExtractor): | |
0f61db44 S |
10 | _VALID_URL = r'https?://(?:[^/]+\.)?chaturbate\.com/(?P<id>[^/?#]+)' |
11 | _TESTS = [{ | |
12 | 'url': 'https://www.chaturbate.com/siswet19/', | |
13 | 'info_dict': { | |
14 | 'id': 'siswet19', | |
15 | 'ext': 'mp4', | |
16 | 'title': 're:^siswet19 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$', | |
17 | 'age_limit': 18, | |
18 | 'is_live': True, | |
19 | }, | |
20 | 'params': { | |
21 | 'skip_download': True, | |
a41a6c50 YCH |
22 | }, |
23 | 'skip': 'Room is offline', | |
0f61db44 S |
24 | }, { |
25 | 'url': 'https://en.chaturbate.com/siswet19/', | |
26 | 'only_matching': True, | |
27 | }] | |
1bd39035 | 28 | |
8a609c32 S |
29 | _ROOM_OFFLINE = 'Room is currently offline' |
30 | ||
1bd39035 P |
31 | def _real_extract(self, url): |
32 | video_id = self._match_id(url) | |
0f61db44 | 33 | |
1bd39035 P |
34 | webpage = self._download_webpage(url, video_id) |
35 | ||
a6f7263c | 36 | m3u8_urls = [] |
0f61db44 | 37 | |
a6f7263c S |
38 | for m in re.finditer( |
39 | r'(["\'])(?P<url>http.+?\.m3u8.*?)\1', webpage): | |
40 | m3u8_fast_url, m3u8_no_fast_url = m.group('url'), m.group( | |
41 | 'url').replace('_fast', '') | |
42 | for m3u8_url in (m3u8_fast_url, m3u8_no_fast_url): | |
43 | if m3u8_url not in m3u8_urls: | |
44 | m3u8_urls.append(m3u8_url) | |
45 | ||
46 | if not m3u8_urls: | |
0f61db44 | 47 | error = self._search_regex( |
8a609c32 S |
48 | [r'<span[^>]+class=(["\'])desc_span\1[^>]*>(?P<error>[^<]+)</span>', |
49 | r'<div[^>]+id=(["\'])defchat\1[^>]*>\s*<p><strong>(?P<error>[^<]+)<'], | |
50 | webpage, 'error', group='error', default=None) | |
51 | if not error: | |
42697bab | 52 | if any(p in webpage for p in ( |
8a609c32 S |
53 | self._ROOM_OFFLINE, 'offline_tipping', 'tip_offline')): |
54 | error = self._ROOM_OFFLINE | |
55 | if error: | |
56 | raise ExtractorError(error, expected=True) | |
57 | raise ExtractorError('Unable to find stream URL') | |
1bd39035 | 58 | |
42697bab | 59 | formats = [] |
a6f7263c S |
60 | for m3u8_url in m3u8_urls: |
61 | m3u8_id = 'fast' if '_fast' in m3u8_url else 'slow' | |
a243abb8 S |
62 | formats.extend(self._extract_m3u8_formats( |
63 | m3u8_url, video_id, ext='mp4', | |
64 | # ffmpeg skips segments for fast m3u8 | |
65 | preference=-10 if m3u8_id == 'fast' else None, | |
66 | m3u8_id=m3u8_id, fatal=False, live=True)) | |
19dbaeec | 67 | self._sort_formats(formats) |
1bd39035 P |
68 | |
69 | return { | |
70 | 'id': video_id, | |
71 | 'title': self._live_title(video_id), | |
42697bab | 72 | 'thumbnail': 'https://roomimg.stream.highwebmedia.com/ri/%s.jpg' % video_id, |
0f61db44 | 73 | 'age_limit': self._rta_search(webpage), |
1bd39035 | 74 | 'is_live': True, |
1bd39035 P |
75 | 'formats': formats, |
76 | } |