]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/audimedia.py
debian/rules: Adapt to new upstream build system.
[youtubedl] / youtube_dl / extractor / audimedia.py
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,
8 sanitized_Request,
9 )
10
11
12 class AudiMediaIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:www\.)?audi-mediacenter\.com/(?:en|de)/audimediatv/(?P<id>[^/?#]+)'
14 _TEST = {
15 'url': 'https://www.audi-mediacenter.com/en/audimediatv/60-seconds-of-audi-sport-104-2015-wec-bahrain-rookie-test-1467',
16 'md5': '79a8b71c46d49042609795ab59779b66',
17 'info_dict': {
18 'id': '1565',
19 'ext': 'mp4',
20 'title': '60 Seconds of Audi Sport 104/2015 - WEC Bahrain, Rookie Test',
21 'description': 'md5:60e5d30a78ced725f7b8d34370762941',
22 'upload_date': '20151124',
23 'timestamp': 1448354940,
24 'duration': 74022,
25 'view_count': int,
26 }
27 }
28 # extracted from https://audimedia.tv/assets/embed/embedded-player.js (dataSourceAuthToken)
29 _AUTH_TOKEN = 'e25b42847dba18c6c8816d5d8ce94c326e06823ebf0859ed164b3ba169be97f2'
30
31 def _real_extract(self, url):
32 display_id = self._match_id(url)
33 webpage = self._download_webpage(url, display_id)
34
35 raw_payload = self._search_regex([
36 r'class="amtv-embed"[^>]+id="([^"]+)"',
37 r'class=\\"amtv-embed\\"[^>]+id=\\"([^"]+)\\"',
38 ], webpage, 'raw payload')
39 _, stage_mode, video_id, lang = raw_payload.split('-')
40
41 # TODO: handle s and e stage_mode (live streams and ended live streams)
42 if stage_mode not in ('s', 'e'):
43 request = sanitized_Request(
44 'https://audimedia.tv/api/video/v1/videos/%s?embed[]=video_versions&embed[]=thumbnail_image&where[content_language_iso]=%s' % (video_id, lang),
45 headers={'X-Auth-Token': self._AUTH_TOKEN})
46 json_data = self._download_json(request, video_id)['results']
47 formats = []
48
49 stream_url_hls = json_data.get('stream_url_hls')
50 if stream_url_hls:
51 formats.extend(self._extract_m3u8_formats(
52 stream_url_hls, video_id, 'mp4',
53 entry_protocol='m3u8_native', m3u8_id='hls', fatal=False))
54
55 stream_url_hds = json_data.get('stream_url_hds')
56 if stream_url_hds:
57 formats.extend(self._extract_f4m_formats(
58 stream_url_hds + '?hdcore=3.4.0',
59 video_id, f4m_id='hds', fatal=False))
60
61 for video_version in json_data.get('video_versions'):
62 video_version_url = video_version.get('download_url') or video_version.get('stream_url')
63 if not video_version_url:
64 continue
65 f = {
66 'url': video_version_url,
67 'width': int_or_none(video_version.get('width')),
68 'height': int_or_none(video_version.get('height')),
69 'abr': int_or_none(video_version.get('audio_bitrate')),
70 'vbr': int_or_none(video_version.get('video_bitrate')),
71 }
72 bitrate = self._search_regex(r'(\d+)k', video_version_url, 'bitrate', default=None)
73 if bitrate:
74 f.update({
75 'format_id': 'http-%s' % bitrate,
76 })
77 formats.append(f)
78 self._sort_formats(formats)
79
80 return {
81 'id': video_id,
82 'title': json_data['title'],
83 'description': json_data.get('subtitle'),
84 'thumbnail': json_data.get('thumbnail_image', {}).get('file'),
85 'timestamp': parse_iso8601(json_data.get('publication_date')),
86 'duration': int_or_none(json_data.get('duration')),
87 'view_count': int_or_none(json_data.get('view_count')),
88 'formats': formats,
89 }