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