[cleanup] Make more playlist entries lazy (#11763)
[yt-dlp.git] / yt_dlp / extractor / cammodels.py
blob7388cfb6cd9bf47e1abfd5060386e925069429fe
1 from .common import InfoExtractor
2 from ..utils import int_or_none, url_or_none
5 class CamModelsIE(InfoExtractor):
6 _VALID_URL = r'https?://(?:www\.)?cammodels\.com/cam/(?P<id>[^/?#&]+)'
7 _TESTS = [{
8 'url': 'https://www.cammodels.com/cam/AutumnKnight/',
9 'only_matching': True,
10 'age_limit': 18,
13 def _real_extract(self, url):
14 user_id = self._match_id(url)
16 manifest = self._download_json(
17 f'https://manifest-server.naiadsystems.com/live/s:{user_id}.json', user_id)
19 formats = []
20 thumbnails = []
21 for format_id, format_dict in manifest['formats'].items():
22 if not isinstance(format_dict, dict):
23 continue
24 encodings = format_dict.get('encodings')
25 if not isinstance(encodings, list):
26 continue
27 vcodec = format_dict.get('videoCodec')
28 acodec = format_dict.get('audioCodec')
29 for media in encodings:
30 if not isinstance(media, dict):
31 continue
32 media_url = url_or_none(media.get('location'))
33 if not media_url:
34 continue
36 format_id_list = [format_id]
37 height = int_or_none(media.get('videoHeight'))
38 if height is not None:
39 format_id_list.append(f'{height}p')
40 f = {
41 'url': media_url,
42 'format_id': '-'.join(format_id_list),
43 'width': int_or_none(media.get('videoWidth')),
44 'height': height,
45 'vbr': int_or_none(media.get('videoKbps')),
46 'abr': int_or_none(media.get('audioKbps')),
47 'fps': int_or_none(media.get('fps')),
48 'vcodec': vcodec,
49 'acodec': acodec,
51 if 'rtmp' in format_id:
52 f['ext'] = 'flv'
53 elif 'hls' in format_id:
54 f.update({
55 'ext': 'mp4',
56 # hls skips fragments, preferring rtmp
57 'quality': -10,
59 else:
60 if format_id == 'jpeg':
61 thumbnails.append({
62 'url': f['url'],
63 'width': f['width'],
64 'height': f['height'],
65 'format_id': f['format_id'],
67 continue
68 formats.append(f)
70 return {
71 'id': user_id,
72 'title': user_id,
73 'thumbnails': thumbnails,
74 'is_live': True,
75 'formats': formats,
76 'age_limit': 18,