]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/audimedia.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / audimedia.py
CommitLineData
527ca1da 1from .common import InfoExtractor
2from ..utils import (
3 int_or_none,
4 parse_iso8601,
527ca1da 5)
6
7
8class AudiMediaIE(InfoExtractor):
c3f75e24
RA
9 _VALID_URL = r'https?://(?:www\.)?audi-mediacenter\.com/(?:en|de)/audimediatv/(?:video/)?(?P<id>[^/?#]+)'
10 _TESTS = [{
7760b9ff 11 'url': 'https://www.audi-mediacenter.com/en/audimediatv/60-seconds-of-audi-sport-104-2015-wec-bahrain-rookie-test-1467',
527ca1da 12 'md5': '79a8b71c46d49042609795ab59779b66',
13 'info_dict': {
c7224074 14 'id': '1565',
527ca1da 15 'ext': 'mp4',
16 'title': '60 Seconds of Audi Sport 104/2015 - WEC Bahrain, Rookie Test',
17 'description': 'md5:60e5d30a78ced725f7b8d34370762941',
18 'upload_date': '20151124',
19 'timestamp': 1448354940,
20 'duration': 74022,
21 'view_count': int,
add96eb9 22 },
c3f75e24
RA
23 }, {
24 'url': 'https://www.audi-mediacenter.com/en/audimediatv/video/60-seconds-of-audi-sport-104-2015-wec-bahrain-rookie-test-2991',
25 'only_matching': True,
26 }]
527ca1da 27
28 def _real_extract(self, url):
29 display_id = self._match_id(url)
30 webpage = self._download_webpage(url, display_id)
e5b4225f 31
7760b9ff 32 raw_payload = self._search_regex([
c3f75e24
RA
33 r'class="amtv-embed"[^>]+id="([0-9a-z-]+)"',
34 r'id="([0-9a-z-]+)"[^>]+class="amtv-embed"',
35 r'class=\\"amtv-embed\\"[^>]+id=\\"([0-9a-z-]+)\\"',
36 r'id=\\"([0-9a-z-]+)\\"[^>]+class=\\"amtv-embed\\"',
37 r'id=(?:\\)?"(amtve-[a-z]-\d+-[a-z]{2})',
7760b9ff 38 ], webpage, 'raw payload')
c3f75e24 39 _, stage_mode, video_id, _ = raw_payload.split('-')
527ca1da 40
41 # TODO: handle s and e stage_mode (live streams and ended live streams)
42 if stage_mode not in ('s', 'e'):
c3f75e24
RA
43 video_data = self._download_json(
44 'https://www.audimedia.tv/api/video/v1/videos/' + video_id,
45 video_id, query={
46 'embed[]': ['video_versions', 'thumbnail_image'],
47 })['results']
527ca1da 48 formats = []
49
c3f75e24 50 stream_url_hls = video_data.get('stream_url_hls')
527ca1da 51 if stream_url_hls:
eccde5e9 52 formats.extend(self._extract_m3u8_formats(
53 stream_url_hls, video_id, 'mp4',
54 entry_protocol='m3u8_native', m3u8_id='hls', fatal=False))
527ca1da 55
c3f75e24 56 stream_url_hds = video_data.get('stream_url_hds')
527ca1da 57 if stream_url_hds:
eccde5e9 58 formats.extend(self._extract_f4m_formats(
59 stream_url_hds + '?hdcore=3.4.0',
60 video_id, f4m_id='hds', fatal=False))
527ca1da 61
c3f75e24 62 for video_version in video_data.get('video_versions', []):
527ca1da 63 video_version_url = video_version.get('download_url') or video_version.get('stream_url')
64 if not video_version_url:
65 continue
7760b9ff 66 f = {
527ca1da 67 'url': video_version_url,
68 'width': int_or_none(video_version.get('width')),
69 'height': int_or_none(video_version.get('height')),
70 'abr': int_or_none(video_version.get('audio_bitrate')),
71 'vbr': int_or_none(video_version.get('video_bitrate')),
7760b9ff 72 }
73 bitrate = self._search_regex(r'(\d+)k', video_version_url, 'bitrate', default=None)
74 if bitrate:
75 f.update({
add96eb9 76 'format_id': f'http-{bitrate}',
7760b9ff 77 })
78 formats.append(f)
527ca1da 79
80 return {
81 'id': video_id,
c3f75e24
RA
82 'title': video_data['title'],
83 'description': video_data.get('subtitle'),
84 'thumbnail': video_data.get('thumbnail_image', {}).get('file'),
85 'timestamp': parse_iso8601(video_data.get('publication_date')),
86 'duration': int_or_none(video_data.get('duration')),
87 'view_count': int_or_none(video_data.get('view_count')),
527ca1da 88 'formats': formats,
89 }