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