]>
Commit | Line | Data |
---|---|---|
054a587d S |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | from .common import InfoExtractor | |
ba448445 | 5 | from ..compat import compat_HTTPError |
054a587d S |
6 | from ..utils import ( |
7 | float_or_none, | |
ba448445 | 8 | ExtractorError, |
054a587d S |
9 | ) |
10 | ||
11 | ||
12 | class RedBullTVIE(InfoExtractor): | |
274519dd | 13 | _VALID_URL = r'https?://(?:www\.)?redbull(?:\.tv|\.com(?:/[^/]+)?(?:/tv)?)(?:/events/[^/]+)?/(?:videos?|live)/(?P<id>AP-\w+)' |
054a587d S |
14 | _TESTS = [{ |
15 | # film | |
e2e18694 | 16 | 'url': 'https://www.redbull.tv/video/AP-1Q6XCDTAN1W11', |
ba448445 | 17 | 'md5': 'fb0445b98aa4394e504b413d98031d1f', |
054a587d | 18 | 'info_dict': { |
e2e18694 | 19 | 'id': 'AP-1Q6XCDTAN1W11', |
054a587d | 20 | 'ext': 'mp4', |
e2e18694 | 21 | 'title': 'ABC of... WRC - ABC of... S1E6', |
054a587d S |
22 | 'description': 'md5:5c7ed8f4015c8492ecf64b6ab31e7d31', |
23 | 'duration': 1582.04, | |
054a587d S |
24 | }, |
25 | }, { | |
26 | # episode | |
e2e18694 | 27 | 'url': 'https://www.redbull.tv/video/AP-1PMHKJFCW1W11', |
054a587d | 28 | 'info_dict': { |
e2e18694 | 29 | 'id': 'AP-1PMHKJFCW1W11', |
054a587d | 30 | 'ext': 'mp4', |
e2e18694 RA |
31 | 'title': 'Grime - Hashtags S2E4', |
32 | 'description': 'md5:b5f522b89b72e1e23216e5018810bb25', | |
054a587d | 33 | 'duration': 904.6, |
054a587d | 34 | }, |
27449ad8 S |
35 | 'params': { |
36 | 'skip_download': True, | |
37 | }, | |
4779420c RA |
38 | }, { |
39 | 'url': 'https://www.redbull.com/int-en/tv/video/AP-1UWHCAR9S1W11/rob-meets-sam-gaze?playlist=playlists::3f81040a-2f31-4832-8e2e-545b1d39d173', | |
40 | 'only_matching': True, | |
274519dd S |
41 | }, { |
42 | 'url': 'https://www.redbull.com/us-en/videos/AP-1YM9QCYE52111', | |
43 | 'only_matching': True, | |
44 | }, { | |
45 | 'url': 'https://www.redbull.com/us-en/events/AP-1XV2K61Q51W11/live/AP-1XUJ86FDH1W11', | |
46 | 'only_matching': True, | |
054a587d S |
47 | }] |
48 | ||
49 | def _real_extract(self, url): | |
50 | video_id = self._match_id(url) | |
51 | ||
ba448445 | 52 | session = self._download_json( |
e2e18694 | 53 | 'https://api.redbull.tv/v3/session', video_id, |
054a587d | 54 | note='Downloading access token', query={ |
ba448445 | 55 | 'category': 'personal_computer', |
ba448445 RA |
56 | 'os_family': 'http', |
57 | }) | |
58 | if session.get('code') == 'error': | |
59 | raise ExtractorError('%s said: %s' % ( | |
60 | self.IE_NAME, session['message'])) | |
e2e18694 | 61 | token = session['token'] |
054a587d | 62 | |
ba448445 | 63 | try: |
e2e18694 RA |
64 | video = self._download_json( |
65 | 'https://api.redbull.tv/v3/products/' + video_id, | |
ba448445 | 66 | video_id, note='Downloading video information', |
e2e18694 | 67 | headers={'Authorization': token} |
ba448445 RA |
68 | ) |
69 | except ExtractorError as e: | |
70 | if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404: | |
71 | error_message = self._parse_json( | |
e2e18694 | 72 | e.cause.read().decode(), video_id)['error'] |
ba448445 RA |
73 | raise ExtractorError('%s said: %s' % ( |
74 | self.IE_NAME, error_message), expected=True) | |
75 | raise | |
054a587d | 76 | |
e2e18694 | 77 | title = video['title'].strip() |
054a587d S |
78 | |
79 | formats = self._extract_m3u8_formats( | |
e2e18694 RA |
80 | 'https://dms.redbull.tv/v3/%s/%s/playlist.m3u8' % (video_id, token), |
81 | video_id, 'mp4', entry_protocol='m3u8_native', m3u8_id='hls') | |
ba448445 | 82 | self._sort_formats(formats) |
054a587d S |
83 | |
84 | subtitles = {} | |
e2e18694 RA |
85 | for resource in video.get('resources', []): |
86 | if resource.startswith('closed_caption_'): | |
87 | splitted_resource = resource.split('_') | |
88 | if splitted_resource[2]: | |
89 | subtitles.setdefault('en', []).append({ | |
90 | 'url': 'https://resources.redbull.tv/%s/%s' % (video_id, resource), | |
91 | 'ext': splitted_resource[2], | |
92 | }) | |
054a587d | 93 | |
e2e18694 | 94 | subheading = video.get('subheading') |
054a587d S |
95 | if subheading: |
96 | title += ' - %s' % subheading | |
97 | ||
98 | return { | |
99 | 'id': video_id, | |
100 | 'title': title, | |
e2e18694 | 101 | 'description': video.get('long_description') or video.get( |
054a587d S |
102 | 'short_description'), |
103 | 'duration': float_or_none(video.get('duration'), scale=1000), | |
054a587d S |
104 | 'formats': formats, |
105 | 'subtitles': subtitles, | |
106 | } |