[ie/facebook] Support more groups URLs (#11576)
[yt-dlp3.git] / yt_dlp / extractor / audimedia.py
blobc5a9c7e294a35f31da6e5dcf20cb7cad95a692fd
1 from .common import InfoExtractor
2 from ..utils import (
3 int_or_none,
4 parse_iso8601,
8 class AudiMediaIE(InfoExtractor):
9 _VALID_URL = r'https?://(?:www\.)?audi-mediacenter\.com/(?:en|de)/audimediatv/(?:video/)?(?P<id>[^/?#]+)'
10 _TESTS = [{
11 'url': 'https://www.audi-mediacenter.com/en/audimediatv/60-seconds-of-audi-sport-104-2015-wec-bahrain-rookie-test-1467',
12 'md5': '79a8b71c46d49042609795ab59779b66',
13 'info_dict': {
14 'id': '1565',
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,
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,
28 def _real_extract(self, url):
29 display_id = self._match_id(url)
30 webpage = self._download_webpage(url, display_id)
32 raw_payload = self._search_regex([
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})',
38 ], webpage, 'raw payload')
39 _, stage_mode, video_id, _ = raw_payload.split('-')
41 # TODO: handle s and e stage_mode (live streams and ended live streams)
42 if stage_mode not in ('s', 'e'):
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']
48 formats = []
50 stream_url_hls = video_data.get('stream_url_hls')
51 if stream_url_hls:
52 formats.extend(self._extract_m3u8_formats(
53 stream_url_hls, video_id, 'mp4',
54 entry_protocol='m3u8_native', m3u8_id='hls', fatal=False))
56 stream_url_hds = video_data.get('stream_url_hds')
57 if stream_url_hds:
58 formats.extend(self._extract_f4m_formats(
59 stream_url_hds + '?hdcore=3.4.0',
60 video_id, f4m_id='hds', fatal=False))
62 for video_version in video_data.get('video_versions', []):
63 video_version_url = video_version.get('download_url') or video_version.get('stream_url')
64 if not video_version_url:
65 continue
66 f = {
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')),
73 bitrate = self._search_regex(r'(\d+)k', video_version_url, 'bitrate', default=None)
74 if bitrate:
75 f.update({
76 'format_id': f'http-{bitrate}',
78 formats.append(f)
80 return {
81 'id': video_id,
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')),
88 'formats': formats,