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