]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/amadeustv.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / amadeustv.py
CommitLineData
e641aab7
A
1from .common import InfoExtractor
2from ..utils import (
3 ExtractorError,
4 float_or_none,
5 int_or_none,
6 parse_iso8601,
7 url_or_none,
8)
9from ..utils.traversal import traverse_obj
10
11
12class AmadeusTVIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:www\.)?amadeus\.tv/library/(?P<id>[\da-f]+)'
14 _TESTS = [{
15 'url': 'http://www.amadeus.tv/library/65091a87ff85af59d9fc54c3',
16 'info_dict': {
17 'id': '5576678021301411311',
18 'ext': 'mp4',
19 'title': 'Jieon Park - 第五届珠海莫扎特国际青少年音乐周小提琴C组第三轮',
20 'thumbnail': 'http://1253584441.vod2.myqcloud.com/a0046a27vodtransbj1253584441/7db4af535576678021301411311/coverBySnapshot_10_0.jpg',
21 'duration': 1264.8,
22 'upload_date': '20230918',
23 'timestamp': 1695034800,
24 'display_id': '65091a87ff85af59d9fc54c3',
25 'view_count': int,
26 'description': 'md5:a0357b9c215489e2067cbae0b777bb95',
add96eb9 27 },
e641aab7
A
28 }]
29
30 def _real_extract(self, url):
31 display_id = self._match_id(url)
32 webpage = self._download_webpage(url, display_id)
33
34 nuxt_data = self._search_nuxt_data(webpage, display_id, traverse=('fetch', '0'))
35 video_id = traverse_obj(nuxt_data, ('item', 'video', {str}))
36
37 if not video_id:
38 raise ExtractorError('Unable to extract actual video ID')
39
40 video_data = self._download_json(
41 f'http://playvideo.qcloud.com/getplayinfo/v2/1253584441/{video_id}',
42 video_id, headers={'Referer': 'http://www.amadeus.tv/'})
43
44 formats = []
45 for video in traverse_obj(video_data, ('videoInfo', ('sourceVideo', ('transcodeList', ...)), {dict})):
46 if not url_or_none(video.get('url')):
47 continue
48 formats.append({
49 **traverse_obj(video, {
50 'url': 'url',
51 'format_id': ('definition', {lambda x: f'http-{x or "0"}'}),
52 'width': ('width', {int_or_none}),
53 'height': ('height', {int_or_none}),
54 'filesize': (('totalSize', 'size'), {int_or_none}),
55 'vcodec': ('videoStreamList', 0, 'codec'),
56 'acodec': ('audioStreamList', 0, 'codec'),
57 'fps': ('videoStreamList', 0, 'fps', {float_or_none}),
58 }, get_all=False),
59 'http_headers': {'Referer': 'http://www.amadeus.tv/'},
60 })
61
62 return {
63 'id': video_id,
64 'display_id': display_id,
65 'formats': formats,
66 **traverse_obj(video_data, {
67 'title': ('videoInfo', 'basicInfo', 'name', {str}),
68 'thumbnail': ('coverInfo', 'coverUrl', {url_or_none}),
69 'duration': ('videoInfo', 'sourceVideo', ('floatDuration', 'duration'), {float_or_none}),
70 }, get_all=False),
71 **traverse_obj(nuxt_data, ('item', {
72 'title': (('title', 'title_en', 'title_cn'), {str}),
73 'description': (('description', 'description_en', 'description_cn'), {str}),
74 'timestamp': ('date', {parse_iso8601}),
75 'view_count': ('view', {int_or_none}),
76 }), get_all=False),
77 }