2 from __future__ import unicode_literals
4 from .common import InfoExtractor
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(
23 url, user_id, headers=self.geo_verification_headers())
25 manifest_root = self._html_search_regex(
26 r'manifestUrlRoot=([^&\']+)', webpage, 'manifest', default=None)
30 ("I'm offline, but let's stay connected", 'This user is currently offline'),
31 ('in a private show', 'This user is in a private show'),
32 ('is currently performing LIVE', 'This model is currently performing live'),
34 for pattern, message in ERRORS:
35 if pattern in webpage:
40 error = 'Unable to find manifest URL root'
42 raise ExtractorError(error, expected=expected)
44 manifest = self._download_json(
45 '%s%s.json' % (manifest_root, user_id), user_id)
48 for format_id, format_dict in manifest['formats'].items():
49 if not isinstance(format_dict, dict):
51 encodings = format_dict.get('encodings')
52 if not isinstance(encodings, list):
54 vcodec = format_dict.get('videoCodec')
55 acodec = format_dict.get('audioCodec')
56 for media in encodings:
57 if not isinstance(media, dict):
59 media_url = url_or_none(media.get('location'))
63 format_id_list = [format_id]
64 height = int_or_none(media.get('videoHeight'))
65 if height is not None:
66 format_id_list.append('%dp' % height)
69 'format_id': '-'.join(format_id_list),
70 'width': int_or_none(media.get('videoWidth')),
72 'vbr': int_or_none(media.get('videoKbps')),
73 'abr': int_or_none(media.get('audioKbps')),
74 'fps': int_or_none(media.get('fps')),
78 if 'rtmp' in format_id:
80 elif 'hls' in format_id:
83 # hls skips fragments, preferring rtmp
89 self._sort_formats(formats)
93 'title': self._live_title(user_id),