]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/stripchat.py
[extractor/wistia] Match IDs in embed URLs (#4990)
[yt-dlp.git] / yt_dlp / extractor / stripchat.py
CommitLineData
c6118ca2 1from .common import InfoExtractor
2from ..compat import (
3 compat_str,
4)
5from ..utils import (
6 ExtractorError,
7 lowercase_escape,
8 try_get,
9)
10
11
12class StripchatIE(InfoExtractor):
befcac11 13 _VALID_URL = r'https?://stripchat\.com/(?P<id>[^/?#]+)'
c6118ca2 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',
befcac11
AM
25 }, {
26 'url': 'https://stripchat.com/Rakhijaan@xh',
27 'only_matching': True
c6118ca2 28 }]
29
30 def _real_extract(self, url):
31 video_id = self._match_id(url)
76f2bb17 32 webpage = self._download_webpage(url, video_id, headers=self.geo_verification_headers())
c6118ca2 33
34 data = self._parse_json(
35 self._search_regex(
36 r'<script\b[^>]*>\s*window\.__PRELOADED_STATE__\s*=(?P<value>.*?)<\/script>',
37 webpage, 'data', default='{}', group='value'),
38 video_id, transform_source=lowercase_escape, fatal=False)
39 if not data:
40 raise ExtractorError('Unable to find configuration for stream.')
41
42 if try_get(data, lambda x: x['viewCam']['show'], dict):
43 raise ExtractorError('Model is in private show', expected=True)
44 elif not try_get(data, lambda x: x['viewCam']['model']['isLive'], bool):
45 raise ExtractorError('Model is offline', expected=True)
46
47 server = try_get(data, lambda x: x['viewCam']['viewServers']['flashphoner-hls'], compat_str)
48 host = try_get(data, lambda x: x['config']['data']['hlsStreamHost'], compat_str)
49 model_id = try_get(data, lambda x: x['viewCam']['model']['id'], int)
50
51 formats = self._extract_m3u8_formats(
52 'https://b-%s.%s/hls/%d/%d.m3u8' % (server, host, model_id, model_id),
53 video_id, ext='mp4', m3u8_id='hls', fatal=False, live=True)
54 self._sort_formats(formats)
55
56 return {
57 'id': video_id,
39ca3b5c 58 'title': video_id,
c6118ca2 59 'description': self._og_search_description(webpage),
60 'is_live': True,
61 'formats': formats,
62 # Stripchat declares the RTA meta-tag, but in an non-standard format so _rta_search() can't be used
63 'age_limit': 18,
64 }