]>
Commit | Line | Data |
---|---|---|
b47ecd0b | 1 | from .common import InfoExtractor |
f5b01753 | 2 | from ..compat import compat_str |
b47ecd0b RA |
3 | from ..utils import ( |
4 | int_or_none, | |
5 | float_or_none, | |
f5b01753 S |
6 | unified_timestamp, |
7 | url_or_none, | |
b47ecd0b RA |
8 | ) |
9 | ||
10 | ||
11 | class VzaarIE(InfoExtractor): | |
12 | _VALID_URL = r'https?://(?:(?:www|view)\.)?vzaar\.com/(?:videos/)?(?P<id>\d+)' | |
bfd973ec | 13 | _EMBED_REGEX = [r'<iframe[^>]+src=["\'](?P<url>(?:https?:)?//(?:view\.vzaar\.com)/[0-9]+)'] |
b47ecd0b | 14 | _TESTS = [{ |
f5b01753 | 15 | # HTTP and HLS |
b47ecd0b RA |
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 | }, | |
6797de75 RA |
31 | }, { |
32 | # hlsAes = true | |
63fe44eb | 33 | 'url': 'https://view.vzaar.com/11379930/player', |
6797de75 | 34 | 'info_dict': { |
63fe44eb | 35 | 'id': '11379930', |
6797de75 | 36 | 'ext': 'mp4', |
63fe44eb RA |
37 | 'title': 'Videoaula', |
38 | }, | |
39 | 'params': { | |
40 | # m3u8 download | |
41 | 'skip_download': True, | |
6797de75 | 42 | }, |
313877c6 S |
43 | }, { |
44 | # with null videoTitle | |
45 | 'url': 'https://view.vzaar.com/20313539/download', | |
46 | 'only_matching': True, | |
b47ecd0b RA |
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) | |
b47ecd0b | 53 | |
313877c6 | 54 | title = video_data.get('videoTitle') or video_id |
f5b01753 S |
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', | |
f983b875 | 63 | 'quality': 1, |
f5b01753 S |
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') | |
6797de75 RA |
81 | if video_data.get('uspEnabled') and isinstance(video_guid, compat_str) and isinstance(usp, dict): |
82 | hls_aes = video_data.get('hlsAes') | |
c712b16d RA |
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: | |
7e68567e | 90 | f['hls_aes'] = {'uri': url_templ % ('goose', '') + qs} |
c712b16d | 91 | formats.extend(m3u8_formats) |
f5b01753 | 92 | |
f5b01753 | 93 | return { |
b47ecd0b | 94 | 'id': video_id, |
f5b01753 | 95 | 'title': title, |
b47ecd0b RA |
96 | 'thumbnail': self._proto_relative_url(video_data.get('poster')), |
97 | 'duration': float_or_none(video_data.get('videoDuration')), | |
f5b01753 S |
98 | 'timestamp': unified_timestamp(video_data.get('ts')), |
99 | 'formats': formats, | |
b47ecd0b | 100 | } |