]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/chaturbate.py
Merge pull request #7851 from remitamine/kaltura
[yt-dlp.git] / youtube_dl / extractor / chaturbate.py
CommitLineData
0f61db44 1from __future__ import unicode_literals
1bd39035
P
2
3from .common import InfoExtractor
0f61db44 4from ..utils import ExtractorError
1bd39035
P
5
6
7class ChaturbateIE(InfoExtractor):
0f61db44
S
8 _VALID_URL = r'https?://(?:[^/]+\.)?chaturbate\.com/(?P<id>[^/?#]+)'
9 _TESTS = [{
10 'url': 'https://www.chaturbate.com/siswet19/',
11 'info_dict': {
12 'id': 'siswet19',
13 'ext': 'mp4',
14 'title': 're:^siswet19 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
15 'age_limit': 18,
16 'is_live': True,
17 },
18 'params': {
19 'skip_download': True,
20 }
21 }, {
22 'url': 'https://en.chaturbate.com/siswet19/',
23 'only_matching': True,
24 }]
1bd39035 25
8a609c32
S
26 _ROOM_OFFLINE = 'Room is currently offline'
27
1bd39035
P
28 def _real_extract(self, url):
29 video_id = self._match_id(url)
0f61db44 30
1bd39035
P
31 webpage = self._download_webpage(url, video_id)
32
0f61db44
S
33 m3u8_url = self._search_regex(
34 r'src=(["\'])(?P<url>http.+?\.m3u8.*?)\1', webpage,
35 'playlist', default=None, group='url')
36
37 if not m3u8_url:
38 error = self._search_regex(
8a609c32
S
39 [r'<span[^>]+class=(["\'])desc_span\1[^>]*>(?P<error>[^<]+)</span>',
40 r'<div[^>]+id=(["\'])defchat\1[^>]*>\s*<p><strong>(?P<error>[^<]+)<'],
41 webpage, 'error', group='error', default=None)
42 if not error:
43 if any(p not in webpage for p in (
44 self._ROOM_OFFLINE, 'offline_tipping', 'tip_offline')):
45 error = self._ROOM_OFFLINE
46 if error:
47 raise ExtractorError(error, expected=True)
48 raise ExtractorError('Unable to find stream URL')
1bd39035
P
49
50 formats = self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4')
51
52 return {
53 'id': video_id,
54 'title': self._live_title(video_id),
0f61db44
S
55 'thumbnail': 'https://cdn-s.highwebmedia.com/uHK3McUtGCG3SMFcd4ZJsRv8/roomimage/%s.jpg' % video_id,
56 'age_limit': self._rta_search(webpage),
1bd39035 57 'is_live': True,
1bd39035
P
58 'formats': formats,
59 }