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