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