]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/cammodels.py
[downloader/rtmp] Generalize download messages and report time elapsed on finish
[yt-dlp.git] / youtube_dl / extractor / cammodels.py
CommitLineData
8b1da46e 1# coding: utf-8
2a49d019 2from __future__ import unicode_literals
8b1da46e 3
2a49d019 4from .common import InfoExtractor
8b1da46e
S
5from ..compat import compat_str
6from ..utils import (
7 ExtractorError,
8 int_or_none,
9)
2a49d019 10
11
12class CamModelsIE(InfoExtractor):
8b1da46e
S
13 _VALID_URL = r'https?://(?:www\.)?cammodels\.com/cam/(?P<id>[^/?#&]+)'
14 _TESTS = [{
15 'url': 'https://www.cammodels.com/cam/AutumnKnight/',
16 'only_matching': True,
17 }]
2a49d019 18
19 def _real_extract(self, url):
8b1da46e
S
20 user_id = self._match_id(url)
21
22 webpage = self._download_webpage(url, user_id)
23
24 manifest_root = self._html_search_regex(
25 r'manifestUrlRoot=([^&\']+)', webpage, 'manifest', default=None)
26
27 if not manifest_root:
28 ERRORS = (
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'),
2a49d019 31 )
8b1da46e
S
32 for pattern, message in ERRORS:
33 if pattern in webpage:
34 error = message
35 expected = True
36 break
37 else:
38 error = 'Unable to find manifest URL root'
39 expected = False
40 raise ExtractorError(error, expected=expected)
41
2a49d019 42 manifest = self._download_json(
8b1da46e
S
43 '%s%s.json' % (manifest_root, user_id), user_id)
44
45 formats = []
46 for format_id, format_dict in manifest['formats'].items():
47 if not isinstance(format_dict, dict):
48 continue
49 encodings = format_dict.get('encodings')
50 if not isinstance(encodings, list):
51 continue
52 vcodec = format_dict.get('videoCodec')
53 acodec = format_dict.get('audioCodec')
54 for media in encodings:
55 if not isinstance(media, dict):
56 continue
57 media_url = media.get('location')
58 if not media_url or not isinstance(media_url, compat_str):
59 continue
60
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)
65 f = {
66 'url': media_url,
67 'format_id': '-'.join(format_id_list),
68 'width': int_or_none(media.get('videoWidth')),
69 'height': height,
70 'vbr': int_or_none(media.get('videoKbps')),
71 'abr': int_or_none(media.get('audioKbps')),
72 'fps': int_or_none(media.get('fps')),
73 'vcodec': vcodec,
74 'acodec': acodec,
75 }
76 if 'rtmp' in format_id:
77 f['ext'] = 'flv'
78 elif 'hls' in format_id:
79 f.update({
2a49d019 80 'ext': 'mp4',
8b1da46e
S
81 # hls skips fragments, preferring rtmp
82 'preference': -1,
2a49d019 83 })
8b1da46e
S
84 else:
85 continue
86 formats.append(f)
2a49d019 87 self._sort_formats(formats)
8b1da46e 88
2a49d019 89 return {
8b1da46e
S
90 'id': user_id,
91 'title': self._live_title(user_id),
92 'is_live': True,
93 'formats': formats,
2a49d019 94 }