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