mirror of https://github.com/yt-dlp/yt-dlp
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
3.4 KiB
Python
99 lines
3.4 KiB
Python
7 years ago
|
# coding: utf-8
|
||
7 years ago
|
from __future__ import unicode_literals
|
||
7 years ago
|
|
||
7 years ago
|
from .common import InfoExtractor
|
||
7 years ago
|
from ..utils import (
|
||
|
ExtractorError,
|
||
|
int_or_none,
|
||
6 years ago
|
url_or_none,
|
||
7 years ago
|
)
|
||
7 years ago
|
|
||
|
|
||
|
class CamModelsIE(InfoExtractor):
|
||
7 years ago
|
_VALID_URL = r'https?://(?:www\.)?cammodels\.com/cam/(?P<id>[^/?#&]+)'
|
||
|
_TESTS = [{
|
||
|
'url': 'https://www.cammodels.com/cam/AutumnKnight/',
|
||
|
'only_matching': True,
|
||
6 years ago
|
'age_limit': 18
|
||
7 years ago
|
}]
|
||
7 years ago
|
|
||
|
def _real_extract(self, url):
|
||
7 years ago
|
user_id = self._match_id(url)
|
||
|
|
||
7 years ago
|
webpage = self._download_webpage(
|
||
|
url, user_id, headers=self.geo_verification_headers())
|
||
7 years ago
|
|
||
|
manifest_root = self._html_search_regex(
|
||
|
r'manifestUrlRoot=([^&\']+)', webpage, 'manifest', default=None)
|
||
|
|
||
|
if not manifest_root:
|
||
|
ERRORS = (
|
||
|
("I'm offline, but let's stay connected", 'This user is currently offline'),
|
||
|
('in a private show', 'This user is in a private show'),
|
||
7 years ago
|
('is currently performing LIVE', 'This model is currently performing live'),
|
||
7 years ago
|
)
|
||
7 years ago
|
for pattern, message in ERRORS:
|
||
|
if pattern in webpage:
|
||
|
error = message
|
||
|
expected = True
|
||
|
break
|
||
|
else:
|
||
|
error = 'Unable to find manifest URL root'
|
||
|
expected = False
|
||
|
raise ExtractorError(error, expected=expected)
|
||
|
|
||
7 years ago
|
manifest = self._download_json(
|
||
7 years ago
|
'%s%s.json' % (manifest_root, user_id), user_id)
|
||
|
|
||
|
formats = []
|
||
|
for format_id, format_dict in manifest['formats'].items():
|
||
|
if not isinstance(format_dict, dict):
|
||
|
continue
|
||
|
encodings = format_dict.get('encodings')
|
||
|
if not isinstance(encodings, list):
|
||
|
continue
|
||
|
vcodec = format_dict.get('videoCodec')
|
||
|
acodec = format_dict.get('audioCodec')
|
||
|
for media in encodings:
|
||
|
if not isinstance(media, dict):
|
||
|
continue
|
||
6 years ago
|
media_url = url_or_none(media.get('location'))
|
||
|
if not media_url:
|
||
7 years ago
|
continue
|
||
|
|
||
|
format_id_list = [format_id]
|
||
|
height = int_or_none(media.get('videoHeight'))
|
||
|
if height is not None:
|
||
|
format_id_list.append('%dp' % height)
|
||
|
f = {
|
||
|
'url': media_url,
|
||
|
'format_id': '-'.join(format_id_list),
|
||
|
'width': int_or_none(media.get('videoWidth')),
|
||
|
'height': height,
|
||
|
'vbr': int_or_none(media.get('videoKbps')),
|
||
|
'abr': int_or_none(media.get('audioKbps')),
|
||
|
'fps': int_or_none(media.get('fps')),
|
||
|
'vcodec': vcodec,
|
||
|
'acodec': acodec,
|
||
|
}
|
||
|
if 'rtmp' in format_id:
|
||
|
f['ext'] = 'flv'
|
||
|
elif 'hls' in format_id:
|
||
|
f.update({
|
||
7 years ago
|
'ext': 'mp4',
|
||
7 years ago
|
# hls skips fragments, preferring rtmp
|
||
4 years ago
|
'quality': -10,
|
||
7 years ago
|
})
|
||
7 years ago
|
else:
|
||
|
continue
|
||
|
formats.append(f)
|
||
7 years ago
|
self._sort_formats(formats)
|
||
7 years ago
|
|
||
7 years ago
|
return {
|
||
7 years ago
|
'id': user_id,
|
||
|
'title': self._live_title(user_id),
|
||
|
'is_live': True,
|
||
|
'formats': formats,
|
||
6 years ago
|
'age_limit': 18
|
||
7 years ago
|
}
|