]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/veo.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / veo.py
1 from .common import InfoExtractor
2
3 from ..utils import (
4 int_or_none,
5 mimetype2ext,
6 str_or_none,
7 unified_timestamp,
8 url_or_none,
9 )
10
11
12 class VeoIE(InfoExtractor):
13 _VALID_URL = r'https?://app\.veo\.co/matches/(?P<id>[0-9A-Za-z-_]+)'
14
15 _TESTS = [{
16 'url': 'https://app.veo.co/matches/20201027-last-period/',
17 'info_dict': {
18 'id': '20201027-last-period',
19 'ext': 'mp4',
20 'title': 'Akidemy u11s v Bradford Boys u11s (Game 3)',
21 'thumbnail': 're:https://c.veocdn.com/.+/thumbnail.jpg',
22 'upload_date': '20201028',
23 'timestamp': 1603847208,
24 'duration': 1916,
25 'view_count': int,
26 }
27 }, {
28 'url': 'https://app.veo.co/matches/20220313-2022-03-13_u15m-plsjq-vs-csl/',
29 'only_matching': True,
30 }]
31
32 def _real_extract(self, url):
33 video_id = self._match_id(url)
34
35 metadata = self._download_json(
36 'https://app.veo.co/api/app/matches/%s' % video_id, video_id)
37
38 video_data = self._download_json(
39 'https://app.veo.co/api/app/matches/%s/videos' % video_id, video_id, 'Downloading video data')
40
41 formats = []
42 for fmt in video_data:
43 mimetype = str_or_none(fmt.get('mime_type'))
44 format_url = url_or_none(fmt.get('url'))
45 # skip configuration file for panoramic video
46 if not format_url or mimetype == 'video/mp2t':
47 continue
48
49 height = int_or_none(fmt.get('height'))
50 render_type = str_or_none(fmt.get('render_type'))
51 format_id = f'{render_type}-{height}p' if render_type and height else None
52
53 # Veo returns panoramic video information even if panoramic video is not available.
54 # e.g. https://app.veo.co/matches/20201027-last-period/
55 if render_type == 'panorama':
56 if not self._is_valid_url(format_url, video_id, format_id):
57 continue
58
59 formats.append({
60 'url': format_url,
61 'format_id': format_id,
62 'ext': mimetype2ext(mimetype),
63 'width': int_or_none(fmt.get('width')),
64 'height': height,
65 'vbr': int_or_none(fmt.get('bit_rate'), scale=1000),
66 })
67
68 return {
69 'id': video_id,
70 'title': str_or_none(metadata.get('title')),
71 'formats': formats,
72 'thumbnail': url_or_none(metadata.get('thumbnail')),
73 'timestamp': unified_timestamp(metadata.get('created')),
74 'view_count': int_or_none(metadata.get('view_count')),
75 'duration': int_or_none(metadata.get('duration')),
76 }