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.

109 lines
3.8 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. lowercase_escape,
  7. url_or_none,
  8. )
  9. class ChaturbateIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:[^/]+\.)?chaturbate\.com/(?:fullvideo/?\?.*?\bb=)?(?P<id>[^/?&#]+)'
  11. _TESTS = [{
  12. 'url': 'https://www.chaturbate.com/siswet19/',
  13. 'info_dict': {
  14. 'id': 'siswet19',
  15. 'ext': 'mp4',
  16. 'title': 're:^siswet19 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  17. 'age_limit': 18,
  18. 'is_live': True,
  19. },
  20. 'params': {
  21. 'skip_download': True,
  22. },
  23. 'skip': 'Room is offline',
  24. }, {
  25. 'url': 'https://chaturbate.com/fullvideo/?b=caylin',
  26. 'only_matching': True,
  27. }, {
  28. 'url': 'https://en.chaturbate.com/siswet19/',
  29. 'only_matching': True,
  30. }]
  31. _ROOM_OFFLINE = 'Room is currently offline'
  32. def _real_extract(self, url):
  33. video_id = self._match_id(url)
  34. webpage = self._download_webpage(
  35. 'https://chaturbate.com/%s/' % video_id, video_id,
  36. headers=self.geo_verification_headers())
  37. found_m3u8_urls = []
  38. data = self._parse_json(
  39. self._search_regex(
  40. r'initialRoomDossier\s*=\s*(["\'])(?P<value>(?:(?!\1).)+)\1',
  41. webpage, 'data', default='{}', group='value'),
  42. video_id, transform_source=lowercase_escape, fatal=False)
  43. if data:
  44. m3u8_url = url_or_none(data.get('hls_source'))
  45. if m3u8_url:
  46. found_m3u8_urls.append(m3u8_url)
  47. if not found_m3u8_urls:
  48. for m in re.finditer(
  49. r'(\\u002[27])(?P<url>http.+?\.m3u8.*?)\1', webpage):
  50. found_m3u8_urls.append(lowercase_escape(m.group('url')))
  51. if not found_m3u8_urls:
  52. for m in re.finditer(
  53. r'(["\'])(?P<url>http.+?\.m3u8.*?)\1', webpage):
  54. found_m3u8_urls.append(m.group('url'))
  55. m3u8_urls = []
  56. for found_m3u8_url in found_m3u8_urls:
  57. m3u8_fast_url, m3u8_no_fast_url = found_m3u8_url, found_m3u8_url.replace('_fast', '')
  58. for m3u8_url in (m3u8_fast_url, m3u8_no_fast_url):
  59. if m3u8_url not in m3u8_urls:
  60. m3u8_urls.append(m3u8_url)
  61. if not m3u8_urls:
  62. error = self._search_regex(
  63. [r'<span[^>]+class=(["\'])desc_span\1[^>]*>(?P<error>[^<]+)</span>',
  64. r'<div[^>]+id=(["\'])defchat\1[^>]*>\s*<p><strong>(?P<error>[^<]+)<'],
  65. webpage, 'error', group='error', default=None)
  66. if not error:
  67. if any(p in webpage for p in (
  68. self._ROOM_OFFLINE, 'offline_tipping', 'tip_offline')):
  69. error = self._ROOM_OFFLINE
  70. if error:
  71. raise ExtractorError(error, expected=True)
  72. raise ExtractorError('Unable to find stream URL')
  73. formats = []
  74. for m3u8_url in m3u8_urls:
  75. for known_id in ('fast', 'slow'):
  76. if '_%s' % known_id in m3u8_url:
  77. m3u8_id = known_id
  78. break
  79. else:
  80. m3u8_id = None
  81. formats.extend(self._extract_m3u8_formats(
  82. m3u8_url, video_id, ext='mp4',
  83. # ffmpeg skips segments for fast m3u8
  84. preference=-10 if m3u8_id == 'fast' else None,
  85. m3u8_id=m3u8_id, fatal=False, live=True))
  86. self._sort_formats(formats)
  87. return {
  88. 'id': video_id,
  89. 'title': self._live_title(video_id),
  90. 'thumbnail': 'https://roomimg.stream.highwebmedia.com/ri/%s.jpg' % video_id,
  91. 'age_limit': self._rta_search(webpage),
  92. 'is_live': True,
  93. 'formats': formats,
  94. }