1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-12-15 14:47:44 +01:00
yt-dlp/yt_dlp/extractor/cammodels.py

78 lines
2.8 KiB
Python
Raw Normal View History

2017-10-15 07:09:44 +02:00
from .common import InfoExtractor
from ..utils import int_or_none, url_or_none
2017-10-15 07:09:44 +02:00
class CamModelsIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?cammodels\.com/cam/(?P<id>[^/?#&]+)'
_TESTS = [{
'url': 'https://www.cammodels.com/cam/AutumnKnight/',
'only_matching': True,
2019-01-01 15:39:18 +01:00
'age_limit': 18
}]
2017-10-15 07:09:44 +02:00
def _real_extract(self, url):
user_id = self._match_id(url)
2017-10-15 07:09:44 +02:00
manifest = self._download_json(
'https://manifest-server.naiadsystems.com/live/s:%s.json' % user_id, user_id)
formats = []
thumbnails = []
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
2018-07-21 14:08:28 +02:00
media_url = url_or_none(media.get('location'))
if not media_url:
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({
2017-10-15 07:09:44 +02:00
'ext': 'mp4',
# hls skips fragments, preferring rtmp
'quality': -10,
2017-10-15 07:09:44 +02:00
})
else:
if format_id == 'jpeg':
thumbnails.append({
'url': f['url'],
'width': f['width'],
'height': f['height'],
'format_id': f['format_id'],
})
continue
formats.append(f)
2017-10-15 07:09:44 +02:00
return {
'id': user_id,
2021-12-15 17:00:46 +01:00
'title': user_id,
'thumbnails': thumbnails,
'is_live': True,
'formats': formats,
2019-01-01 15:39:18 +01:00
'age_limit': 18
2017-10-15 07:09:44 +02:00
}