stripchat.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. ExtractorError,
  4. UserNotLive,
  5. lowercase_escape,
  6. traverse_obj,
  7. )
  8. class StripchatIE(InfoExtractor):
  9. _VALID_URL = r'https?://stripchat\.com/(?P<id>[^/?#]+)'
  10. _TESTS = [{
  11. 'url': 'https://stripchat.com/Joselin_Flower',
  12. 'info_dict': {
  13. 'id': 'Joselin_Flower',
  14. 'ext': 'mp4',
  15. 'title': 're:^Joselin_Flower [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  16. 'description': str,
  17. 'is_live': True,
  18. 'age_limit': 18,
  19. },
  20. 'skip': 'Room is offline',
  21. }, {
  22. 'url': 'https://stripchat.com/Rakhijaan@xh',
  23. 'only_matching': True,
  24. }]
  25. def _real_extract(self, url):
  26. video_id = self._match_id(url)
  27. webpage = self._download_webpage(url, video_id, headers=self.geo_verification_headers())
  28. data = self._parse_json(
  29. self._search_regex(
  30. r'<script\b[^>]*>\s*window\.__PRELOADED_STATE__\s*=(?P<value>.*?)<\/script>',
  31. webpage, 'data', default='{}', group='value'),
  32. video_id, transform_source=lowercase_escape, fatal=False)
  33. if not data:
  34. raise ExtractorError('Unable to find configuration for stream.')
  35. if traverse_obj(data, ('viewCam', 'show'), expected_type=dict):
  36. raise ExtractorError('Model is in private show', expected=True)
  37. elif not traverse_obj(data, ('viewCam', 'model', 'isLive'), expected_type=bool):
  38. raise UserNotLive(video_id=video_id)
  39. model_id = traverse_obj(data, ('viewCam', 'model', 'id'), expected_type=int)
  40. formats = []
  41. for host in traverse_obj(data, ('config', 'data', (
  42. (('features', 'featuresV2'), 'hlsFallback', 'fallbackDomains', ...), 'hlsStreamHost'))):
  43. formats = self._extract_m3u8_formats(
  44. f'https://edge-hls.{host}/hls/{model_id}/master/{model_id}_auto.m3u8',
  45. video_id, ext='mp4', m3u8_id='hls', fatal=False, live=True)
  46. if formats:
  47. break
  48. if not formats:
  49. self.raise_no_formats('No active streams found', expected=True)
  50. return {
  51. 'id': video_id,
  52. 'title': video_id,
  53. 'description': self._og_search_description(webpage),
  54. 'is_live': True,
  55. 'formats': formats,
  56. # Stripchat declares the RTA meta-tag, but in an non-standard format so _rta_search() can't be used
  57. 'age_limit': 18,
  58. }