2 from __future__ import unicode_literals
4 from .common import InfoExtractor
5 from ..compat import compat_str
12 class CamModelsIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:www\.)?cammodels\.com/cam/(?P<id>[^/?#&]+)'
15 'url': 'https://www.cammodels.com/cam/AutumnKnight/',
16 'only_matching': True,
19 def _real_extract(self, url):
20 user_id = self._match_id(url)
22 webpage = self._download_webpage(url, user_id)
24 manifest_root = self._html_search_regex(
25 r'manifestUrlRoot=([^&\']+)', webpage, 'manifest', default=None)
29 ("I'm offline, but let's stay connected", 'This user is currently offline'),
30 ('in a private show', 'This user is in a private show'),
32 for pattern, message in ERRORS:
33 if pattern in webpage:
38 error = 'Unable to find manifest URL root'
40 raise ExtractorError(error, expected=expected)
42 manifest = self._download_json(
43 '%s%s.json' % (manifest_root, user_id), user_id)
46 for format_id, format_dict in manifest['formats'].items():
47 if not isinstance(format_dict, dict):
49 encodings = format_dict.get('encodings')
50 if not isinstance(encodings, list):
52 vcodec = format_dict.get('videoCodec')
53 acodec = format_dict.get('audioCodec')
54 for media in encodings:
55 if not isinstance(media, dict):
57 media_url = media.get('location')
58 if not media_url or not isinstance(media_url, compat_str):
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)
67 'format_id': '-'.join(format_id_list),
68 'width': int_or_none(media.get('videoWidth')),
70 'vbr': int_or_none(media.get('videoKbps')),
71 'abr': int_or_none(media.get('audioKbps')),
72 'fps': int_or_none(media.get('fps')),
76 if 'rtmp' in format_id:
78 elif 'hls' in format_id:
81 # hls skips fragments, preferring rtmp
87 self._sort_formats(formats)
91 'title': self._live_title(user_id),