]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/chaturbate.py
29a8820d5835b1b3cf7aca3840705a2fb2f2e1e3
[youtubedl] / youtube_dl / extractor / chaturbate.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..utils import ExtractorError
5
6
7 class ChaturbateIE(InfoExtractor):
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 'skip': 'Room is offline',
22 }, {
23 'url': 'https://en.chaturbate.com/siswet19/',
24 'only_matching': True,
25 }]
26
27 _ROOM_OFFLINE = 'Room is currently offline'
28
29 def _real_extract(self, url):
30 video_id = self._match_id(url)
31
32 webpage = self._download_webpage(url, video_id)
33
34 m3u8_url = self._search_regex(
35 r'src=(["\'])(?P<url>http.+?\.m3u8.*?)\1', webpage,
36 'playlist', default=None, group='url')
37
38 if not m3u8_url:
39 error = self._search_regex(
40 [r'<span[^>]+class=(["\'])desc_span\1[^>]*>(?P<error>[^<]+)</span>',
41 r'<div[^>]+id=(["\'])defchat\1[^>]*>\s*<p><strong>(?P<error>[^<]+)<'],
42 webpage, 'error', group='error', default=None)
43 if not error:
44 if any(p not in webpage for p in (
45 self._ROOM_OFFLINE, 'offline_tipping', 'tip_offline')):
46 error = self._ROOM_OFFLINE
47 if error:
48 raise ExtractorError(error, expected=True)
49 raise ExtractorError('Unable to find stream URL')
50
51 formats = self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4')
52 self._sort_formats(formats)
53
54 return {
55 'id': video_id,
56 'title': self._live_title(video_id),
57 'thumbnail': 'https://cdn-s.highwebmedia.com/uHK3McUtGCG3SMFcd4ZJsRv8/roomimage/%s.jpg' % video_id,
58 'age_limit': self._rta_search(webpage),
59 'is_live': True,
60 'formats': formats,
61 }