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.

61 lines
2.1 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. 'skip': 'Room is offline',
  19. }, {
  20. 'url': 'https://en.chaturbate.com/siswet19/',
  21. 'only_matching': True,
  22. }]
  23. _ROOM_OFFLINE = 'Room is currently offline'
  24. def _real_extract(self, url):
  25. video_id = self._match_id(url)
  26. webpage = self._download_webpage(url, video_id)
  27. m3u8_url = self._search_regex(
  28. r'src=(["\'])(?P<url>http.+?\.m3u8.*?)\1', webpage,
  29. 'playlist', default=None, group='url')
  30. if not m3u8_url:
  31. error = self._search_regex(
  32. [r'<span[^>]+class=(["\'])desc_span\1[^>]*>(?P<error>[^<]+)</span>',
  33. r'<div[^>]+id=(["\'])defchat\1[^>]*>\s*<p><strong>(?P<error>[^<]+)<'],
  34. webpage, 'error', group='error', default=None)
  35. if not error:
  36. if any(p not in webpage for p in (
  37. self._ROOM_OFFLINE, 'offline_tipping', 'tip_offline')):
  38. error = self._ROOM_OFFLINE
  39. if error:
  40. raise ExtractorError(error, expected=True)
  41. raise ExtractorError('Unable to find stream URL')
  42. formats = self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4')
  43. self._sort_formats(formats)
  44. return {
  45. 'id': video_id,
  46. 'title': self._live_title(video_id),
  47. 'thumbnail': 'https://cdn-s.highwebmedia.com/uHK3McUtGCG3SMFcd4ZJsRv8/roomimage/%s.jpg' % video_id,
  48. 'age_limit': self._rta_search(webpage),
  49. 'is_live': True,
  50. 'formats': formats,
  51. }