]>
Commit | Line | Data |
---|---|---|
6ef3e65a S |
1 | import re |
2 | ||
3 | from .common import InfoExtractor | |
6ef3e65a S |
4 | from ..utils import ( |
5 | determine_ext, | |
6 | float_or_none, | |
bc2ca1bb | 7 | int_or_none, |
6ef3e65a S |
8 | parse_age_limit, |
9 | qualities, | |
0c265486 | 10 | random_birthday, |
6ef3e65a S |
11 | unified_timestamp, |
12 | urljoin, | |
13 | ) | |
14 | ||
15 | ||
16 | class VideoPressIE(InfoExtractor): | |
bc2ca1bb | 17 | _ID_REGEX = r'[\da-zA-Z]{8}' |
18 | _PATH_REGEX = r'video(?:\.word)?press\.com/embed/' | |
19 | _VALID_URL = r'https?://%s(?P<id>%s)' % (_PATH_REGEX, _ID_REGEX) | |
6ef3e65a S |
20 | _TESTS = [{ |
21 | 'url': 'https://videopress.com/embed/kUJmAcSf', | |
22 | 'md5': '706956a6c875873d51010921310e4bc6', | |
23 | 'info_dict': { | |
24 | 'id': 'kUJmAcSf', | |
25 | 'ext': 'mp4', | |
26 | 'title': 'VideoPress Demo', | |
27 | 'thumbnail': r're:^https?://.*\.jpg', | |
28 | 'duration': 634.6, | |
29 | 'timestamp': 1434983935, | |
30 | 'upload_date': '20150622', | |
31 | 'age_limit': 0, | |
32 | }, | |
33 | }, { | |
34 | # 17+, requires birth_* params | |
35 | 'url': 'https://videopress.com/embed/iH3gstfZ', | |
36 | 'only_matching': True, | |
bc2ca1bb | 37 | }, { |
38 | 'url': 'https://video.wordpress.com/embed/kUJmAcSf', | |
39 | 'only_matching': True, | |
6ef3e65a S |
40 | }] |
41 | ||
42 | @staticmethod | |
43 | def _extract_urls(webpage): | |
44 | return re.findall( | |
bc2ca1bb | 45 | r'<iframe[^>]+src=["\']((?:https?://)?%s%s)' % (VideoPressIE._PATH_REGEX, VideoPressIE._ID_REGEX), |
6ef3e65a S |
46 | webpage) |
47 | ||
48 | def _real_extract(self, url): | |
49 | video_id = self._match_id(url) | |
50 | ||
0c265486 | 51 | query = random_birthday('birth_year', 'birth_month', 'birth_day') |
bc2ca1bb | 52 | query['fields'] = 'description,duration,file_url_base,files,height,original,poster,rating,title,upload_date,width' |
6ef3e65a S |
53 | video = self._download_json( |
54 | 'https://public-api.wordpress.com/rest/v1.1/videos/%s' % video_id, | |
0c265486 | 55 | video_id, query=query) |
6ef3e65a S |
56 | |
57 | title = video['title'] | |
58 | ||
bc2ca1bb | 59 | file_url_base = video.get('file_url_base') or {} |
60 | base_url = file_url_base.get('https') or file_url_base.get('http') | |
6ef3e65a S |
61 | |
62 | QUALITIES = ('std', 'dvd', 'hd') | |
63 | quality = qualities(QUALITIES) | |
64 | ||
65 | formats = [] | |
bc2ca1bb | 66 | for format_id, f in (video.get('files') or {}).items(): |
6ef3e65a S |
67 | if not isinstance(f, dict): |
68 | continue | |
69 | for ext, path in f.items(): | |
70 | if ext in ('mp4', 'ogg'): | |
71 | formats.append({ | |
72 | 'url': urljoin(base_url, path), | |
73 | 'format_id': '%s-%s' % (format_id, ext), | |
74 | 'ext': determine_ext(path, ext), | |
75 | 'quality': quality(format_id), | |
76 | }) | |
bc2ca1bb | 77 | original_url = video.get('original') |
6ef3e65a S |
78 | if original_url: |
79 | formats.append({ | |
80 | 'url': original_url, | |
81 | 'format_id': 'original', | |
82 | 'quality': len(QUALITIES), | |
bc2ca1bb | 83 | 'width': int_or_none(video.get('width')), |
84 | 'height': int_or_none(video.get('height')), | |
6ef3e65a S |
85 | }) |
86 | self._sort_formats(formats) | |
87 | ||
88 | return { | |
89 | 'id': video_id, | |
90 | 'title': title, | |
91 | 'description': video.get('description'), | |
92 | 'thumbnail': video.get('poster'), | |
93 | 'duration': float_or_none(video.get('duration'), 1000), | |
94 | 'timestamp': unified_timestamp(video.get('upload_date')), | |
95 | 'age_limit': parse_age_limit(video.get('rating')), | |
96 | 'formats': formats, | |
97 | } |