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