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.

68 lines
2.4 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_formats = [(m.group('id').lower(), m.group('url')) for m in re.finditer(
  29. r'hlsSource(?P<id>.+?)\s*=\s*(?P<q>["\'])(?P<url>http.+?)(?P=q)', webpage)]
  30. if not m3u8_formats:
  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 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 = []
  43. for m3u8_id, m3u8_url in m3u8_formats:
  44. formats.extend(self._extract_m3u8_formats(
  45. m3u8_url, video_id, ext='mp4',
  46. # ffmpeg skips segments for fast m3u8
  47. preference=-10 if m3u8_id == 'fast' else None,
  48. m3u8_id=m3u8_id, fatal=False, live=True))
  49. self._sort_formats(formats)
  50. return {
  51. 'id': video_id,
  52. 'title': self._live_title(video_id),
  53. 'thumbnail': 'https://roomimg.stream.highwebmedia.com/ri/%s.jpg' % video_id,
  54. 'age_limit': self._rta_search(webpage),
  55. 'is_live': True,
  56. 'formats': formats,
  57. }