]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/stripchat.py
[misc] Add `hatch`, `ruff`, `pre-commit` and improve dev docs (#7409)
[yt-dlp.git] / yt_dlp / extractor / stripchat.py
1 from .common import InfoExtractor
2 from ..utils import (
3 ExtractorError,
4 UserNotLive,
5 lowercase_escape,
6 traverse_obj,
7 )
8
9
10 class StripchatIE(InfoExtractor):
11 _VALID_URL = r'https?://stripchat\.com/(?P<id>[^/?#]+)'
12 _TESTS = [{
13 'url': 'https://stripchat.com/Joselin_Flower',
14 'info_dict': {
15 'id': 'Joselin_Flower',
16 'ext': 'mp4',
17 'title': 're:^Joselin_Flower [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
18 'description': str,
19 'is_live': True,
20 'age_limit': 18,
21 },
22 'skip': 'Room is offline',
23 }, {
24 'url': 'https://stripchat.com/Rakhijaan@xh',
25 'only_matching': True
26 }]
27
28 def _real_extract(self, url):
29 video_id = self._match_id(url)
30 webpage = self._download_webpage(url, video_id, headers=self.geo_verification_headers())
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
40 if traverse_obj(data, ('viewCam', 'show'), expected_type=dict):
41 raise ExtractorError('Model is in private show', expected=True)
42 elif not traverse_obj(data, ('viewCam', 'model', 'isLive'), expected_type=bool):
43 raise UserNotLive(video_id=video_id)
44
45 model_id = traverse_obj(data, ('viewCam', 'model', 'id'), expected_type=int)
46
47 formats = []
48 for host in traverse_obj(data, ('config', 'data', (
49 (('features', 'featuresV2'), 'hlsFallback', 'fallbackDomains', ...), 'hlsStreamHost'))):
50 formats = self._extract_m3u8_formats(
51 f'https://edge-hls.{host}/hls/{model_id}/master/{model_id}_auto.m3u8',
52 video_id, ext='mp4', m3u8_id='hls', fatal=False, live=True)
53 if formats:
54 break
55 if not formats:
56 self.raise_no_formats('No active streams found', expected=True)
57
58 return {
59 'id': video_id,
60 'title': video_id,
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 }