]>
Commit | Line | Data |
---|---|---|
1 | from .common import InfoExtractor | |
2 | from ..compat import compat_str | |
3 | from ..utils import ( | |
4 | int_or_none, | |
5 | float_or_none, | |
6 | unified_timestamp, | |
7 | url_or_none, | |
8 | ) | |
9 | ||
10 | ||
11 | class VzaarIE(InfoExtractor): | |
12 | _VALID_URL = r'https?://(?:(?:www|view)\.)?vzaar\.com/(?:videos/)?(?P<id>\d+)' | |
13 | _EMBED_REGEX = [r'<iframe[^>]+src=["\'](?P<url>(?:https?:)?//(?:view\.vzaar\.com)/[0-9]+)'] | |
14 | _TESTS = [{ | |
15 | # HTTP and HLS | |
16 | 'url': 'https://vzaar.com/videos/1152805', | |
17 | 'md5': 'bde5ddfeb104a6c56a93a06b04901dbf', | |
18 | 'info_dict': { | |
19 | 'id': '1152805', | |
20 | 'ext': 'mp4', | |
21 | 'title': 'sample video (public)', | |
22 | }, | |
23 | }, { | |
24 | 'url': 'https://view.vzaar.com/27272/player', | |
25 | 'md5': '3b50012ac9bbce7f445550d54e0508f2', | |
26 | 'info_dict': { | |
27 | 'id': '27272', | |
28 | 'ext': 'mp3', | |
29 | 'title': 'MP3', | |
30 | }, | |
31 | }, { | |
32 | # hlsAes = true | |
33 | 'url': 'https://view.vzaar.com/11379930/player', | |
34 | 'info_dict': { | |
35 | 'id': '11379930', | |
36 | 'ext': 'mp4', | |
37 | 'title': 'Videoaula', | |
38 | }, | |
39 | 'params': { | |
40 | # m3u8 download | |
41 | 'skip_download': True, | |
42 | }, | |
43 | }, { | |
44 | # with null videoTitle | |
45 | 'url': 'https://view.vzaar.com/20313539/download', | |
46 | 'only_matching': True, | |
47 | }] | |
48 | ||
49 | def _real_extract(self, url): | |
50 | video_id = self._match_id(url) | |
51 | video_data = self._download_json( | |
52 | 'http://view.vzaar.com/v2/%s/video' % video_id, video_id) | |
53 | ||
54 | title = video_data.get('videoTitle') or video_id | |
55 | ||
56 | formats = [] | |
57 | ||
58 | source_url = url_or_none(video_data.get('sourceUrl')) | |
59 | if source_url: | |
60 | f = { | |
61 | 'url': source_url, | |
62 | 'format_id': 'http', | |
63 | 'quality': 1, | |
64 | } | |
65 | if 'audio' in source_url: | |
66 | f.update({ | |
67 | 'vcodec': 'none', | |
68 | 'ext': 'mp3', | |
69 | }) | |
70 | else: | |
71 | f.update({ | |
72 | 'width': int_or_none(video_data.get('width')), | |
73 | 'height': int_or_none(video_data.get('height')), | |
74 | 'ext': 'mp4', | |
75 | 'fps': float_or_none(video_data.get('fps')), | |
76 | }) | |
77 | formats.append(f) | |
78 | ||
79 | video_guid = video_data.get('guid') | |
80 | usp = video_data.get('usp') | |
81 | if video_data.get('uspEnabled') and isinstance(video_guid, compat_str) and isinstance(usp, dict): | |
82 | hls_aes = video_data.get('hlsAes') | |
83 | qs = '&'.join('%s=%s' % (k, v) for k, v in usp.items()) | |
84 | url_templ = 'http://%%s.vzaar.com/v5/usp%s/%s/%s.ism%%s?' % ('aes' if hls_aes else '', video_guid, video_id) | |
85 | m3u8_formats = self._extract_m3u8_formats( | |
86 | url_templ % ('fable', '/.m3u8') + qs, video_id, 'mp4', 'm3u8_native', | |
87 | m3u8_id='hls', fatal=False) | |
88 | if hls_aes: | |
89 | for f in m3u8_formats: | |
90 | f['_decryption_key_url'] = url_templ % ('goose', '') + qs | |
91 | formats.extend(m3u8_formats) | |
92 | ||
93 | return { | |
94 | 'id': video_id, | |
95 | 'title': title, | |
96 | 'thumbnail': self._proto_relative_url(video_data.get('poster')), | |
97 | 'duration': float_or_none(video_data.get('videoDuration')), | |
98 | 'timestamp': unified_timestamp(video_data.get('ts')), | |
99 | 'formats': formats, | |
100 | } |