You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
2.0 KiB

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