]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/veo.py
[misc] Add `hatch`, `ruff`, `pre-commit` and improve dev docs (#7409)
[yt-dlp.git] / yt_dlp / extractor / veo.py
CommitLineData
2333ea10 1from .common import InfoExtractor
2333ea10 2from ..utils import (
3 int_or_none,
4 mimetype2ext,
f4ad9192 5 str_or_none,
2333ea10 6 unified_timestamp,
7 url_or_none,
8)
9
10
11class VeoIE(InfoExtractor):
5a373d97 12 _VALID_URL = r'https?://app\.veo\.co/matches/(?P<id>[0-9A-Za-z-_]+)'
2333ea10 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,
f4ad9192 24 'view_count': int,
2333ea10 25 }
5a373d97 26 }, {
27 'url': 'https://app.veo.co/matches/20220313-2022-03-13_u15m-plsjq-vs-csl/',
28 'only_matching': True,
2333ea10 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
2333ea10 40 formats = []
41 for fmt in video_data:
f4ad9192 42 mimetype = str_or_none(fmt.get('mime_type'))
43 format_url = url_or_none(fmt.get('url'))
2333ea10 44 # skip configuration file for panoramic video
f4ad9192 45 if not format_url or mimetype == 'video/mp2t':
2333ea10 46 continue
f4ad9192 47
2333ea10 48 height = int_or_none(fmt.get('height'))
f4ad9192 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
2333ea10 58 formats.append({
f4ad9192 59 'url': format_url,
60 'format_id': format_id,
2333ea10 61 'ext': mimetype2ext(mimetype),
62 'width': int_or_none(fmt.get('width')),
63 'height': height,
f4ad9192 64 'vbr': int_or_none(fmt.get('bit_rate'), scale=1000),
2333ea10 65 })
66
2333ea10 67 return {
68 'id': video_id,
f4ad9192 69 'title': str_or_none(metadata.get('title')),
2333ea10 70 'formats': formats,
f4ad9192 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')),
2333ea10 75 }