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