]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/stripchat.py
[extractor] Fix bug in 617f658b7ec1193749848c1b7343acab125dbc46
[yt-dlp.git] / yt_dlp / extractor / stripchat.py
1 from .common import InfoExtractor
2 from ..compat import (
3 compat_str,
4 )
5 from ..utils import (
6 ExtractorError,
7 lowercase_escape,
8 try_get,
9 )
10
11
12 class StripchatIE(InfoExtractor):
13 _VALID_URL = r'https?://stripchat\.com/(?P<id>[0-9A-Za-z-_]+)'
14 _TESTS = [{
15 'url': 'https://stripchat.com/feel_me',
16 'info_dict': {
17 'id': 'feel_me',
18 'ext': 'mp4',
19 'title': 're:^feel_me [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
20 'description': str,
21 'is_live': True,
22 'age_limit': 18,
23 },
24 'skip': 'Room is offline',
25 }]
26
27 def _real_extract(self, url):
28 video_id = self._match_id(url)
29 webpage = self._download_webpage(
30 'https://stripchat.com/%s/' % video_id, video_id,
31 headers=self.geo_verification_headers())
32
33 data = self._parse_json(
34 self._search_regex(
35 r'<script\b[^>]*>\s*window\.__PRELOADED_STATE__\s*=(?P<value>.*?)<\/script>',
36 webpage, 'data', default='{}', group='value'),
37 video_id, transform_source=lowercase_escape, fatal=False)
38 if not data:
39 raise ExtractorError('Unable to find configuration for stream.')
40
41 if try_get(data, lambda x: x['viewCam']['show'], dict):
42 raise ExtractorError('Model is in private show', expected=True)
43 elif not try_get(data, lambda x: x['viewCam']['model']['isLive'], bool):
44 raise ExtractorError('Model is offline', expected=True)
45
46 server = try_get(data, lambda x: x['viewCam']['viewServers']['flashphoner-hls'], compat_str)
47 host = try_get(data, lambda x: x['config']['data']['hlsStreamHost'], compat_str)
48 model_id = try_get(data, lambda x: x['viewCam']['model']['id'], int)
49
50 formats = self._extract_m3u8_formats(
51 'https://b-%s.%s/hls/%d/%d.m3u8' % (server, host, model_id, model_id),
52 video_id, ext='mp4', m3u8_id='hls', fatal=False, live=True)
53 self._sort_formats(formats)
54
55 return {
56 'id': video_id,
57 'title': video_id,
58 'description': self._og_search_description(webpage),
59 'is_live': True,
60 'formats': formats,
61 # Stripchat declares the RTA meta-tag, but in an non-standard format so _rta_search() can't be used
62 'age_limit': 18,
63 }