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.

77 lines
2.7 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(
  28. url, video_id, headers=self.geo_verification_headers())
  29. m3u8_urls = []
  30. for m in re.finditer(
  31. r'(["\'])(?P<url>http.+?\.m3u8.*?)\1', webpage):
  32. m3u8_fast_url, m3u8_no_fast_url = m.group('url'), m.group(
  33. 'url').replace('_fast', '')
  34. for m3u8_url in (m3u8_fast_url, m3u8_no_fast_url):
  35. if m3u8_url not in m3u8_urls:
  36. m3u8_urls.append(m3u8_url)
  37. if not m3u8_urls:
  38. error = self._search_regex(
  39. [r'<span[^>]+class=(["\'])desc_span\1[^>]*>(?P<error>[^<]+)</span>',
  40. r'<div[^>]+id=(["\'])defchat\1[^>]*>\s*<p><strong>(?P<error>[^<]+)<'],
  41. webpage, 'error', group='error', default=None)
  42. if not error:
  43. if any(p in webpage for p in (
  44. self._ROOM_OFFLINE, 'offline_tipping', 'tip_offline')):
  45. error = self._ROOM_OFFLINE
  46. if error:
  47. raise ExtractorError(error, expected=True)
  48. raise ExtractorError('Unable to find stream URL')
  49. formats = []
  50. for m3u8_url in m3u8_urls:
  51. m3u8_id = 'fast' if '_fast' in m3u8_url else 'slow'
  52. formats.extend(self._extract_m3u8_formats(
  53. m3u8_url, video_id, ext='mp4',
  54. # ffmpeg skips segments for fast m3u8
  55. preference=-10 if m3u8_id == 'fast' else None,
  56. m3u8_id=m3u8_id, fatal=False, live=True))
  57. self._sort_formats(formats)
  58. return {
  59. 'id': video_id,
  60. 'title': self._live_title(video_id),
  61. 'thumbnail': 'https://roomimg.stream.highwebmedia.com/ri/%s.jpg' % video_id,
  62. 'age_limit': self._rta_search(webpage),
  63. 'is_live': True,
  64. 'formats': formats,
  65. }