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