2 from __future__ import unicode_literals
6 from .common import InfoExtractor
19 class VideoPressIE(InfoExtractor):
20 _ID_REGEX = r'[\da-zA-Z]{8}'
21 _PATH_REGEX = r'video(?:\.word)?press\.com/embed/'
22 _VALID_URL = r'https?://%s(?P<id>%s)' % (_PATH_REGEX, _ID_REGEX)
24 'url': 'https://videopress.com/embed/kUJmAcSf',
25 'md5': '706956a6c875873d51010921310e4bc6',
29 'title': 'VideoPress Demo',
30 'thumbnail': r're:^https?://.*\.jpg',
32 'timestamp': 1434983935,
33 'upload_date': '20150622',
37 # 17+, requires birth_* params
38 'url': 'https://videopress.com/embed/iH3gstfZ',
39 'only_matching': True,
41 'url': 'https://video.wordpress.com/embed/kUJmAcSf',
42 'only_matching': True,
46 def _extract_urls(webpage):
48 r'<iframe[^>]+src=["\']((?:https?://)?%s%s)' % (VideoPressIE._PATH_REGEX, VideoPressIE._ID_REGEX),
51 def _real_extract(self, url):
52 video_id = self._match_id(url)
54 query = random_birthday('birth_year', 'birth_month', 'birth_day')
55 query['fields'] = 'description,duration,file_url_base,files,height,original,poster,rating,title,upload_date,width'
56 video = self._download_json(
57 'https://public-api.wordpress.com/rest/v1.1/videos/%s' % video_id,
58 video_id, query=query)
60 title = video['title']
62 file_url_base = video.get('file_url_base') or {}
63 base_url = file_url_base.get('https') or file_url_base.get('http')
65 QUALITIES = ('std', 'dvd', 'hd')
66 quality = qualities(QUALITIES)
69 for format_id, f in (video.get('files') or {}).items():
70 if not isinstance(f, dict):
72 for ext, path in f.items():
73 if ext in ('mp4', 'ogg'):
75 'url': urljoin(base_url, path),
76 'format_id': '%s-%s' % (format_id, ext),
77 'ext': determine_ext(path, ext),
78 'quality': quality(format_id),
80 original_url = video.get('original')
84 'format_id': 'original',
85 'quality': len(QUALITIES),
86 'width': int_or_none(video.get('width')),
87 'height': int_or_none(video.get('height')),
89 self._sort_formats(formats)
94 'description': video.get('description'),
95 'thumbnail': video.get('poster'),
96 'duration': float_or_none(video.get('duration'), 1000),
97 'timestamp': unified_timestamp(video.get('upload_date')),
98 'age_limit': parse_age_limit(video.get('rating')),