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.

76 lines
2.6 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import ExtractorError
  5. class ChaturbateIE(InfoExtractor):
  6. _VALID_URL = r'https?://(?:[^/]+\.)?chaturbate\.com/(?P<id>[^/?#]+)'
  7. _TESTS = [{
  8. 'url': 'https://www.chaturbate.com/siswet19/',
  9. 'info_dict': {
  10. 'id': 'siswet19',
  11. 'ext': 'mp4',
  12. 'title': 're:^siswet19 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  13. 'age_limit': 18,
  14. 'is_live': True,
  15. },
  16. 'params': {
  17. 'skip_download': True,
  18. },
  19. 'skip': 'Room is offline',
  20. }, {
  21. 'url': 'https://en.chaturbate.com/siswet19/',
  22. 'only_matching': True,
  23. }]
  24. _ROOM_OFFLINE = 'Room is currently offline'
  25. def _real_extract(self, url):
  26. video_id = self._match_id(url)
  27. webpage = self._download_webpage(url, video_id)
  28. m3u8_urls = []
  29. for m in re.finditer(
  30. r'(["\'])(?P<url>http.+?\.m3u8.*?)\1', webpage):
  31. m3u8_fast_url, m3u8_no_fast_url = m.group('url'), m.group(
  32. 'url').replace('_fast', '')
  33. for m3u8_url in (m3u8_fast_url, m3u8_no_fast_url):
  34. if m3u8_url not in m3u8_urls:
  35. m3u8_urls.append(m3u8_url)
  36. if not m3u8_urls:
  37. error = self._search_regex(
  38. [r'<span[^>]+class=(["\'])desc_span\1[^>]*>(?P<error>[^<]+)</span>',
  39. r'<div[^>]+id=(["\'])defchat\1[^>]*>\s*<p><strong>(?P<error>[^<]+)<'],
  40. webpage, 'error', group='error', default=None)
  41. if not error:
  42. if any(p in webpage for p in (
  43. self._ROOM_OFFLINE, 'offline_tipping', 'tip_offline')):
  44. error = self._ROOM_OFFLINE
  45. if error:
  46. raise ExtractorError(error, expected=True)
  47. raise ExtractorError('Unable to find stream URL')
  48. formats = []
  49. for m3u8_url in m3u8_urls:
  50. m3u8_id = 'fast' if '_fast' in m3u8_url else 'slow'
  51. formats.extend(self._extract_m3u8_formats(
  52. m3u8_url, video_id, ext='mp4',
  53. # ffmpeg skips segments for fast m3u8
  54. preference=-10 if m3u8_id == 'fast' else None,
  55. m3u8_id=m3u8_id, fatal=False, live=True))
  56. self._sort_formats(formats)
  57. return {
  58. 'id': video_id,
  59. 'title': self._live_title(video_id),
  60. 'thumbnail': 'https://roomimg.stream.highwebmedia.com/ri/%s.jpg' % video_id,
  61. 'age_limit': self._rta_search(webpage),
  62. 'is_live': True,
  63. 'formats': formats,
  64. }