]> gitweb @ CieloNegro.org - youtube-dl.git/blob - youtube_dl/extractor/redbull.py
e3d978a53e2731ab21bfd349458077f6d56dac2f
[youtube-dl.git] / youtube_dl / extractor / redbull.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3 import re
4
5 from .common import InfoExtractor
6
7
8 class RedBullIE(InfoExtractor):
9     _VALID_URL = r'https?://(?:www\.)?redbull\.tv/video/(?P<id>AP-\w+)'
10     _TEST = {
11         'url': 'https://www.redbull.tv/video/AP-1Q756YYX51W11/abc-of-wrc',
12         'md5': '78e860f631d7a846e712fab8c5fe2c38',
13         'info_dict': {
14             'id': 'AP-1Q756YYX51W11',
15             'ext': 'mp4',
16             'title': 'ABC of...WRC',
17             'description': 'Buckle up for a crash course in the terminology, rules, drivers, and courses of the World Rally Championship.'
18         }
19     }
20
21     def _real_extract(self, url):
22         mobj = re.match(self._VALID_URL, url)
23         video_id = mobj.group('id')
24
25         access_token = self._download_json(
26             'http://api-v2.redbull.tv/start?build=4.0.9&category=smartphone&os_version=23&os_family=android',
27             video_id, note='Downloading  access token',
28         )['auth']['access_token']
29
30         info = self._download_json(
31             'https://api-v2.redbull.tv/views/%s' % video_id,
32             video_id, note='Downloading video information',
33             headers={'Authorization': 'Bearer ' + access_token}
34         )['blocks'][0]['top'][0]
35
36         m3u8_url = info['video_product']['url']
37         title = info['title']
38
39         formats = self._extract_m3u8_formats(
40             m3u8_url, video_id, 'mp4', 'm3u8_native',
41             m3u8_id='hls')
42
43         return {
44             'id': video_id,
45             'title': title,
46             'formats': formats,
47             'description': info.get('short_description'),
48             'genre': info.get('genre'),
49             'duration': info.get('duration')
50         }