]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/cammodels.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / cammodels.py
CommitLineData
2a49d019 1from .common import InfoExtractor
8b1da46e
S
2from ..utils import (
3 ExtractorError,
4 int_or_none,
3052a30d 5 url_or_none,
8b1da46e 6)
2a49d019 7
8
9class CamModelsIE(InfoExtractor):
8b1da46e
S
10 _VALID_URL = r'https?://(?:www\.)?cammodels\.com/cam/(?P<id>[^/?#&]+)'
11 _TESTS = [{
12 'url': 'https://www.cammodels.com/cam/AutumnKnight/',
13 'only_matching': True,
9b5c8751 14 'age_limit': 18
8b1da46e 15 }]
2a49d019 16
17 def _real_extract(self, url):
8b1da46e
S
18 user_id = self._match_id(url)
19
8882840e
S
20 webpage = self._download_webpage(
21 url, user_id, headers=self.geo_verification_headers())
8b1da46e
S
22
23 manifest_root = self._html_search_regex(
24 r'manifestUrlRoot=([^&\']+)', webpage, 'manifest', default=None)
25
26 if not manifest_root:
27 ERRORS = (
28 ("I'm offline, but let's stay connected", 'This user is currently offline'),
29 ('in a private show', 'This user is in a private show'),
2ce35d9f 30 ('is currently performing LIVE', 'This model is currently performing live'),
2a49d019 31 )
8b1da46e
S
32 for pattern, message in ERRORS:
33 if pattern in webpage:
34 error = message
35 expected = True
36 break
37 else:
38 error = 'Unable to find manifest URL root'
39 expected = False
40 raise ExtractorError(error, expected=expected)
41
2a49d019 42 manifest = self._download_json(
8b1da46e
S
43 '%s%s.json' % (manifest_root, user_id), user_id)
44
45 formats = []
46 for format_id, format_dict in manifest['formats'].items():
47 if not isinstance(format_dict, dict):
48 continue
49 encodings = format_dict.get('encodings')
50 if not isinstance(encodings, list):
51 continue
52 vcodec = format_dict.get('videoCodec')
53 acodec = format_dict.get('audioCodec')
54 for media in encodings:
55 if not isinstance(media, dict):
56 continue
3052a30d
S
57 media_url = url_or_none(media.get('location'))
58 if not media_url:
8b1da46e
S
59 continue
60
61 format_id_list = [format_id]
62 height = int_or_none(media.get('videoHeight'))
63 if height is not None:
64 format_id_list.append('%dp' % height)
65 f = {
66 'url': media_url,
67 'format_id': '-'.join(format_id_list),
68 'width': int_or_none(media.get('videoWidth')),
69 'height': height,
70 'vbr': int_or_none(media.get('videoKbps')),
71 'abr': int_or_none(media.get('audioKbps')),
72 'fps': int_or_none(media.get('fps')),
73 'vcodec': vcodec,
74 'acodec': acodec,
75 }
76 if 'rtmp' in format_id:
77 f['ext'] = 'flv'
78 elif 'hls' in format_id:
79 f.update({
2a49d019 80 'ext': 'mp4',
8b1da46e 81 # hls skips fragments, preferring rtmp
f983b875 82 'quality': -10,
2a49d019 83 })
8b1da46e
S
84 else:
85 continue
86 formats.append(f)
8b1da46e 87
2a49d019 88 return {
8b1da46e 89 'id': user_id,
39ca3b5c 90 'title': user_id,
8b1da46e
S
91 'is_live': True,
92 'formats': formats,
9b5c8751 93 'age_limit': 18
2a49d019 94 }