1 from __future__ 
import unicode_literals
 
   5 from .common 
import InfoExtractor
 
   6 from ..utils 
import ExtractorError
 
   9 class ChaturbateIE(InfoExtractor
): 
  10     _VALID_URL 
= r
'https?://(?:[^/]+\.)?chaturbate\.com/(?P<id>[^/?#]+)' 
  12         'url': 'https://www.chaturbate.com/siswet19/', 
  16             'title': 're:^siswet19 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$', 
  21             'skip_download': True, 
  23         'skip': 'Room is offline', 
  25         'url': 'https://en.chaturbate.com/siswet19/', 
  26         'only_matching': True, 
  29     _ROOM_OFFLINE 
= 'Room is currently offline' 
  31     def _real_extract(self
, url
): 
  32         video_id 
= self
._match
_id
(url
) 
  34         webpage 
= self
._download
_webpage
(url
, video_id
) 
  36         m3u8_formats 
= [(m
.group('id').lower(), m
.group('url')) for m 
in re
.finditer( 
  37             r
'hlsSource(?P<id>.+?)\s*=\s*(?P<q>["\'])(?P
<url
>http
.+?
)(?P
=q
)', webpage)] 
  40             error = self._search_regex( 
  41                 [r'<span
[^
>]+class=(["\'])desc_span\1[^>]*>(?P<error>[^<]+)</span>', 
  42                  r'<div[^>]+id=(["\'])defchat\
1[^
>]*>\s
*<p
><strong
>(?P
<error
>[^
<]+)<'], 
  43                 webpage, 'error
', group='error
', default=None) 
  45                 if any(p in webpage for p in ( 
  46                         self._ROOM_OFFLINE, 'offline_tipping
', 'tip_offline
')): 
  47                     error = self._ROOM_OFFLINE 
  49                 raise ExtractorError(error, expected=True) 
  50             raise ExtractorError('Unable to find stream URL
') 
  53         for m3u8_id, m3u8_url in m3u8_formats: 
  54             formats.extend(self._extract_m3u8_formats( 
  55                 m3u8_url, video_id, ext='mp4
', 
  56                 # ffmpeg skips segments for fast m3u8 
  57                 preference=-10 if m3u8_id == 'fast
' else None, 
  58                 m3u8_id=m3u8_id, fatal=False, live=True)) 
  59         self._sort_formats(formats) 
  63             'title
': self._live_title(video_id), 
  64             'thumbnail
': 'https
://roomimg
.stream
.highwebmedia
.com
/ri
/%s.jpg
' % video_id, 
  65             'age_limit
': self._rta_search(webpage),