1 from __future__ import unicode_literals
2 from .common import InfoExtractor
3 from .common import ExtractorError
6 from ..utils import int_or_none
9 class CamModelsIE(InfoExtractor):
10 _VALID_URL = r'https?://(?:www\.)?cammodels\.com/cam/(?P<id>\w+)'
12 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36'
13 # Needed because server doesn't return links to video URLs if a browser-like User-Agent is not used
16 def _real_extract(self, url):
17 video_id = self._match_id(url)
18 webpage = self._download_webpage(
21 headers=self._HEADERS)
22 manifest_url_root = self._html_search_regex(
23 r'manifestUrlRoot=(?P<id>https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*))',
28 if not manifest_url_root:
29 offline = self._html_search_regex(
30 r'(?P<id>I\'m offline, but let\'s stay connected!)',
35 private = self._html_search_regex(
36 r'(?P<id>I’m in a private show right now)',
38 'private show indicator',
41 err = 'This user is currently offline, so nothing can be downloaded.' if offline \
42 else 'This user is doing a private show, which requires payment. This extractor currently does not support private streams.' if private \
43 else 'Unable to find link to stream info on webpage. Room is not offline, so something else is wrong.'
46 expected=True if offline or private else False,
49 manifest_url = manifest_url_root + video_id + '.json'
50 manifest = self._download_json(
53 'Downloading links to streams.',
54 'Link to stream URLs was found, but we couldn\'t access it.',
55 headers=self._HEADERS)
58 for fmtName in ['mp4-rtmp', 'mp4-hls']:
59 for encoding in manifest['formats'][fmtName]['encodings']:
62 'url': encoding['location'],
63 'width': int_or_none(encoding.get('videoWidth')),
64 'height': int_or_none(encoding.get('videoHeight')),
65 'vbr': int_or_none(encoding.get('videoKbps')),
66 'abr': int_or_none(encoding.get('audioKbps')),
67 'format_id': fmtName + str(encoding.get('videoWidth'))
69 # If they change the JSON format, then fallback to parsing out RTMP links via regex.
71 manifest_json = json.dumps(manifest)
72 manifest_links = re.finditer(
73 r'(?P<id>rtmp?:\/\/[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#&//=]*))',
75 if not manifest_links:
77 'Link to stream info was found, but we couldn\'t read the response. This is probably a bug.',
81 for manifest_link in manifest_links:
82 url = manifest_link.group('id')
86 'format_id': url.split(sep='/')[-1]
88 self._sort_formats(formats)
91 'title': self._live_title(video_id),