]>
Commit | Line | Data |
---|---|---|
054a587d | 1 | from .common import InfoExtractor |
ba448445 | 2 | from ..compat import compat_HTTPError |
054a587d S |
3 | from ..utils import ( |
4 | float_or_none, | |
ba448445 | 5 | ExtractorError, |
054a587d S |
6 | ) |
7 | ||
8 | ||
9 | class RedBullTVIE(InfoExtractor): | |
1f767545 | 10 | _VALID_URL = r'https?://(?:www\.)?redbull(?:\.tv|\.com(?:/[^/]+)?(?:/tv)?)(?:/events/[^/]+)?/(?:videos?|live|(?:film|episode)s)/(?P<id>AP-\w+)' |
054a587d S |
11 | _TESTS = [{ |
12 | # film | |
e2e18694 | 13 | 'url': 'https://www.redbull.tv/video/AP-1Q6XCDTAN1W11', |
ba448445 | 14 | 'md5': 'fb0445b98aa4394e504b413d98031d1f', |
054a587d | 15 | 'info_dict': { |
e2e18694 | 16 | 'id': 'AP-1Q6XCDTAN1W11', |
054a587d | 17 | 'ext': 'mp4', |
e2e18694 | 18 | 'title': 'ABC of... WRC - ABC of... S1E6', |
054a587d S |
19 | 'description': 'md5:5c7ed8f4015c8492ecf64b6ab31e7d31', |
20 | 'duration': 1582.04, | |
054a587d S |
21 | }, |
22 | }, { | |
23 | # episode | |
e2e18694 | 24 | 'url': 'https://www.redbull.tv/video/AP-1PMHKJFCW1W11', |
054a587d | 25 | 'info_dict': { |
e2e18694 | 26 | 'id': 'AP-1PMHKJFCW1W11', |
054a587d | 27 | 'ext': 'mp4', |
e2e18694 | 28 | 'title': 'Grime - Hashtags S2E4', |
1f767545 RA |
29 | 'description': 'md5:5546aa612958c08a98faaad4abce484d', |
30 | 'duration': 904, | |
054a587d | 31 | }, |
27449ad8 S |
32 | 'params': { |
33 | 'skip_download': True, | |
34 | }, | |
4779420c RA |
35 | }, { |
36 | 'url': 'https://www.redbull.com/int-en/tv/video/AP-1UWHCAR9S1W11/rob-meets-sam-gaze?playlist=playlists::3f81040a-2f31-4832-8e2e-545b1d39d173', | |
37 | 'only_matching': True, | |
274519dd S |
38 | }, { |
39 | 'url': 'https://www.redbull.com/us-en/videos/AP-1YM9QCYE52111', | |
40 | 'only_matching': True, | |
41 | }, { | |
42 | 'url': 'https://www.redbull.com/us-en/events/AP-1XV2K61Q51W11/live/AP-1XUJ86FDH1W11', | |
43 | 'only_matching': True, | |
1f767545 RA |
44 | }, { |
45 | 'url': 'https://www.redbull.com/int-en/films/AP-1ZSMAW8FH2111', | |
46 | 'only_matching': True, | |
47 | }, { | |
48 | 'url': 'https://www.redbull.com/int-en/episodes/AP-1TQWK7XE11W11', | |
49 | 'only_matching': True, | |
054a587d S |
50 | }] |
51 | ||
1f767545 | 52 | def extract_info(self, video_id): |
ba448445 | 53 | session = self._download_json( |
e2e18694 | 54 | 'https://api.redbull.tv/v3/session', video_id, |
054a587d | 55 | note='Downloading access token', query={ |
ba448445 | 56 | 'category': 'personal_computer', |
ba448445 RA |
57 | 'os_family': 'http', |
58 | }) | |
59 | if session.get('code') == 'error': | |
60 | raise ExtractorError('%s said: %s' % ( | |
61 | self.IE_NAME, session['message'])) | |
e2e18694 | 62 | token = session['token'] |
054a587d | 63 | |
ba448445 | 64 | try: |
e2e18694 RA |
65 | video = self._download_json( |
66 | 'https://api.redbull.tv/v3/products/' + video_id, | |
ba448445 | 67 | video_id, note='Downloading video information', |
e2e18694 | 68 | headers={'Authorization': token} |
ba448445 RA |
69 | ) |
70 | except ExtractorError as e: | |
71 | if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404: | |
72 | error_message = self._parse_json( | |
e2e18694 | 73 | e.cause.read().decode(), video_id)['error'] |
ba448445 RA |
74 | raise ExtractorError('%s said: %s' % ( |
75 | self.IE_NAME, error_message), expected=True) | |
76 | raise | |
054a587d | 77 | |
e2e18694 | 78 | title = video['title'].strip() |
054a587d | 79 | |
a9f5f5d6 | 80 | formats, subtitles = self._extract_m3u8_formats_and_subtitles( |
e2e18694 RA |
81 | 'https://dms.redbull.tv/v3/%s/%s/playlist.m3u8' % (video_id, token), |
82 | video_id, 'mp4', entry_protocol='m3u8_native', m3u8_id='hls') | |
ba448445 | 83 | self._sort_formats(formats) |
054a587d | 84 | |
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 | } | |
2efefdda | 107 | |
1f767545 RA |
108 | def _real_extract(self, url): |
109 | video_id = self._match_id(url) | |
110 | return self.extract_info(video_id) | |
111 | ||
112 | ||
113 | class RedBullEmbedIE(RedBullTVIE): | |
114 | _VALID_URL = r'https?://(?:www\.)?redbull\.com/embed/(?P<id>rrn:content:[^:]+:[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}:[a-z]{2}-[A-Z]{2,3})' | |
115 | _TESTS = [{ | |
116 | # HLS manifest accessible only using assetId | |
117 | 'url': 'https://www.redbull.com/embed/rrn:content:episode-videos:f3021f4f-3ed4-51ac-915a-11987126e405:en-INT', | |
118 | 'only_matching': True, | |
119 | }] | |
120 | _VIDEO_ESSENSE_TMPL = '''... on %s { | |
121 | videoEssence { | |
122 | attributes | |
123 | } | |
124 | }''' | |
125 | ||
126 | def _real_extract(self, url): | |
127 | rrn_id = self._match_id(url) | |
128 | asset_id = self._download_json( | |
129 | 'https://edge-graphql.crepo-production.redbullaws.com/v1/graphql', | |
b73612a2 | 130 | rrn_id, headers={ |
131 | 'Accept': 'application/json', | |
132 | 'API-KEY': 'e90a1ff11335423998b100c929ecc866', | |
133 | }, query={ | |
1f767545 RA |
134 | 'query': '''{ |
135 | resource(id: "%s", enforceGeoBlocking: false) { | |
136 | %s | |
137 | %s | |
138 | } | |
139 | }''' % (rrn_id, self._VIDEO_ESSENSE_TMPL % 'LiveVideo', self._VIDEO_ESSENSE_TMPL % 'VideoResource'), | |
140 | })['data']['resource']['videoEssence']['attributes']['assetId'] | |
141 | return self.extract_info(asset_id) | |
142 | ||
2efefdda S |
143 | |
144 | class RedBullTVRrnContentIE(InfoExtractor): | |
1f767545 | 145 | _VALID_URL = r'https?://(?:www\.)?redbull\.com/(?P<region>[a-z]{2,3})-(?P<lang>[a-z]{2})/tv/(?:video|live|film)/(?P<id>rrn:content:[^:]+:[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})' |
2efefdda S |
146 | _TESTS = [{ |
147 | 'url': 'https://www.redbull.com/int-en/tv/video/rrn:content:live-videos:e3e6feb4-e95f-50b7-962a-c70f8fd13c73/mens-dh-finals-fort-william', | |
148 | 'only_matching': True, | |
149 | }, { | |
150 | 'url': 'https://www.redbull.com/int-en/tv/video/rrn:content:videos:a36a0f36-ff1b-5db8-a69d-ee11a14bf48b/tn-ts-style?playlist=rrn:content:event-profiles:83f05926-5de8-5389-b5e4-9bb312d715e8:extras', | |
151 | 'only_matching': True, | |
1f767545 RA |
152 | }, { |
153 | 'url': 'https://www.redbull.com/int-en/tv/film/rrn:content:films:d1f4d00e-4c04-5d19-b510-a805ffa2ab83/follow-me', | |
154 | 'only_matching': True, | |
2efefdda S |
155 | }] |
156 | ||
157 | def _real_extract(self, url): | |
5ad28e7f | 158 | region, lang, rrn_id = self._match_valid_url(url).groups() |
1f767545 RA |
159 | rrn_id += ':%s-%s' % (lang, region.upper()) |
160 | return self.url_result( | |
161 | 'https://www.redbull.com/embed/' + rrn_id, | |
162 | RedBullEmbedIE.ie_key(), rrn_id) | |
2efefdda | 163 | |
2efefdda | 164 | |
1f767545 RA |
165 | class RedBullIE(InfoExtractor): |
166 | _VALID_URL = r'https?://(?:www\.)?redbull\.com/(?P<region>[a-z]{2,3})-(?P<lang>[a-z]{2})/(?P<type>(?:episode|film|(?:(?:recap|trailer)-)?video)s|live)/(?!AP-|rrn:content:)(?P<id>[^/?#&]+)' | |
167 | _TESTS = [{ | |
168 | 'url': 'https://www.redbull.com/int-en/episodes/grime-hashtags-s02-e04', | |
169 | 'md5': 'db8271a7200d40053a1809ed0dd574ff', | |
170 | 'info_dict': { | |
171 | 'id': 'AA-1MT8DQWA91W14', | |
172 | 'ext': 'mp4', | |
173 | 'title': 'Grime - Hashtags S2E4', | |
174 | 'description': 'md5:5546aa612958c08a98faaad4abce484d', | |
175 | }, | |
176 | }, { | |
177 | 'url': 'https://www.redbull.com/int-en/films/kilimanjaro-mountain-of-greatness', | |
178 | 'only_matching': True, | |
179 | }, { | |
180 | 'url': 'https://www.redbull.com/int-en/recap-videos/uci-mountain-bike-world-cup-2017-mens-xco-finals-from-vallnord', | |
181 | 'only_matching': True, | |
182 | }, { | |
183 | 'url': 'https://www.redbull.com/int-en/trailer-videos/kings-of-content', | |
184 | 'only_matching': True, | |
185 | }, { | |
186 | 'url': 'https://www.redbull.com/int-en/videos/tnts-style-red-bull-dance-your-style-s1-e12', | |
187 | 'only_matching': True, | |
188 | }, { | |
189 | 'url': 'https://www.redbull.com/int-en/live/mens-dh-finals-fort-william', | |
190 | 'only_matching': True, | |
b03eebdb RA |
191 | }, { |
192 | # only available on the int-en website so a fallback is need for the API | |
193 | # https://www.redbull.com/v3/api/graphql/v1/v3/query/en-GB>en-INT?filter[uriSlug]=fia-wrc-saturday-recap-estonia&rb3Schema=v1:hero | |
194 | 'url': 'https://www.redbull.com/gb-en/live/fia-wrc-saturday-recap-estonia', | |
195 | 'only_matching': True, | |
1f767545 | 196 | }] |
b03eebdb RA |
197 | _INT_FALLBACK_LIST = ['de', 'en', 'es', 'fr'] |
198 | _LAT_FALLBACK_MAP = ['ar', 'bo', 'car', 'cl', 'co', 'mx', 'pe'] | |
1f767545 RA |
199 | |
200 | def _real_extract(self, url): | |
5ad28e7f | 201 | region, lang, filter_type, display_id = self._match_valid_url(url).groups() |
1f767545 RA |
202 | if filter_type == 'episodes': |
203 | filter_type = 'episode-videos' | |
204 | elif filter_type == 'live': | |
205 | filter_type = 'live-videos' | |
206 | ||
b03eebdb RA |
207 | regions = [region.upper()] |
208 | if region != 'int': | |
209 | if region in self._LAT_FALLBACK_MAP: | |
210 | regions.append('LAT') | |
211 | if lang in self._INT_FALLBACK_LIST: | |
212 | regions.append('INT') | |
213 | locale = '>'.join(['%s-%s' % (lang, reg) for reg in regions]) | |
214 | ||
1f767545 | 215 | rrn_id = self._download_json( |
b03eebdb | 216 | 'https://www.redbull.com/v3/api/graphql/v1/v3/query/' + locale, |
1f767545 RA |
217 | display_id, query={ |
218 | 'filter[type]': filter_type, | |
219 | 'filter[uriSlug]': display_id, | |
220 | 'rb3Schema': 'v1:hero', | |
221 | })['data']['id'] | |
2efefdda S |
222 | |
223 | return self.url_result( | |
1f767545 RA |
224 | 'https://www.redbull.com/embed/' + rrn_id, |
225 | RedBullEmbedIE.ie_key(), rrn_id) |