stripchat.py 2.5 KB

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