[ie/youtube] Fix `uploader_id` extraction (#11818)
[yt-dlp.git] / yt_dlp / extractor / stripchat.py
blob84846042f38f15604e6c9cc0ada08c6cc97a2a63
1 from .common import InfoExtractor
2 from ..utils import (
3 ExtractorError,
4 UserNotLive,
5 lowercase_escape,
6 traverse_obj,
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,
22 'skip': 'Room is offline',
23 }, {
24 'url': 'https://stripchat.com/Rakhijaan@xh',
25 'only_matching': True,
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 data = self._search_json(
32 r'<script\b[^>]*>\s*window\.__PRELOADED_STATE__\s*=',
33 webpage, 'data', video_id, transform_source=lowercase_escape)
35 if traverse_obj(data, ('viewCam', 'show', {dict})):
36 raise ExtractorError('Model is in a private show', expected=True)
37 if not traverse_obj(data, ('viewCam', 'model', 'isLive', {bool})):
38 raise UserNotLive(video_id=video_id)
40 model_id = data['viewCam']['model']['id']
42 formats = []
43 # HLS hosts are currently found in .configV3.static.features.hlsFallback.fallbackDomains[]
44 # The rest of the path is for backwards compatibility and to guard against A/B testing
45 for host in traverse_obj(data, ((('config', 'data'), ('configV3', 'static')), (
46 (('features', 'featuresV2'), 'hlsFallback', 'fallbackDomains', ...), 'hlsStreamHost'))):
47 formats = self._extract_m3u8_formats(
48 f'https://edge-hls.{host}/hls/{model_id}/master/{model_id}_auto.m3u8',
49 video_id, ext='mp4', m3u8_id='hls', fatal=False, live=True)
50 if formats:
51 break
52 if not formats:
53 self.raise_no_formats('Unable to extract stream host', video_id=video_id)
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,