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.

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