]>
Commit | Line | Data |
---|---|---|
1 | import re | |
2 | ||
3 | from .common import InfoExtractor | |
4 | from ..utils import ( | |
5 | int_or_none, | |
6 | str_or_none, | |
7 | url_or_none, | |
8 | ) | |
9 | ||
10 | ||
11 | class ViqeoIE(InfoExtractor): | |
12 | _VALID_URL = r'''(?x) | |
13 | (?: | |
14 | viqeo:| | |
15 | https?://cdn\.viqeo\.tv/embed/*\?.*?\bvid=| | |
16 | https?://api\.viqeo\.tv/v\d+/data/startup?.*?\bvideo(?:%5B%5D|\[\])= | |
17 | ) | |
18 | (?P<id>[\da-f]+) | |
19 | ''' | |
20 | _TESTS = [{ | |
21 | 'url': 'https://cdn.viqeo.tv/embed/?vid=cde96f09d25f39bee837', | |
22 | 'md5': 'a169dd1a6426b350dca4296226f21e76', | |
23 | 'info_dict': { | |
24 | 'id': 'cde96f09d25f39bee837', | |
25 | 'ext': 'mp4', | |
26 | 'title': 'cde96f09d25f39bee837', | |
27 | 'thumbnail': r're:^https?://.*\.jpg$', | |
28 | 'duration': 76, | |
29 | }, | |
30 | }, { | |
31 | 'url': 'viqeo:cde96f09d25f39bee837', | |
32 | 'only_matching': True, | |
33 | }, { | |
34 | 'url': 'https://api.viqeo.tv/v1/data/startup?video%5B%5D=71bbec412ade45c3216c&profile=112', | |
35 | 'only_matching': True, | |
36 | }] | |
37 | ||
38 | @staticmethod | |
39 | def _extract_urls(webpage): | |
40 | return [ | |
41 | mobj.group('url') | |
42 | for mobj in re.finditer( | |
43 | r'<iframe[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//cdn\.viqeo\.tv/embed/*\?.*?\bvid=[\da-f]+.*?)\1', | |
44 | webpage)] | |
45 | ||
46 | def _real_extract(self, url): | |
47 | video_id = self._match_id(url) | |
48 | ||
49 | webpage = self._download_webpage( | |
50 | 'https://cdn.viqeo.tv/embed/?vid=%s' % video_id, video_id) | |
51 | ||
52 | data = self._parse_json( | |
53 | self._search_regex( | |
54 | r'SLOT_DATA\s*=\s*({.+?})\s*;', webpage, 'slot data'), | |
55 | video_id) | |
56 | ||
57 | formats = [] | |
58 | thumbnails = [] | |
59 | for media_file in data['mediaFiles']: | |
60 | if not isinstance(media_file, dict): | |
61 | continue | |
62 | media_url = url_or_none(media_file.get('url')) | |
63 | if not media_url or not media_url.startswith(('http', '//')): | |
64 | continue | |
65 | media_type = str_or_none(media_file.get('type')) | |
66 | if not media_type: | |
67 | continue | |
68 | media_kind = media_type.split('/')[0].lower() | |
69 | f = { | |
70 | 'url': media_url, | |
71 | 'width': int_or_none(media_file.get('width')), | |
72 | 'height': int_or_none(media_file.get('height')), | |
73 | } | |
74 | format_id = str_or_none(media_file.get('quality')) | |
75 | if media_kind == 'image': | |
76 | f['id'] = format_id | |
77 | thumbnails.append(f) | |
78 | elif media_kind in ('video', 'audio'): | |
79 | is_audio = media_kind == 'audio' | |
80 | f.update({ | |
81 | 'format_id': 'audio' if is_audio else format_id, | |
82 | 'fps': int_or_none(media_file.get('fps')), | |
83 | 'vcodec': 'none' if is_audio else None, | |
84 | }) | |
85 | formats.append(f) | |
86 | self._sort_formats(formats) | |
87 | ||
88 | duration = int_or_none(data.get('duration')) | |
89 | ||
90 | return { | |
91 | 'id': video_id, | |
92 | 'title': video_id, | |
93 | 'duration': duration, | |
94 | 'thumbnails': thumbnails, | |
95 | 'formats': formats, | |
96 | } |