]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/redbulltv.py
5d6cc3610c4311ea637e137c87ac216e16c8e719
2 from __future__
import unicode_literals
4 from .common
import InfoExtractor
5 from ..compat
import compat_HTTPError
15 class RedBullTVIE(InfoExtractor
):
16 _VALID_URL
= r
'https?://(?:www\.)?redbull\.tv/(?:video|film|live)/(?:AP-\w+/segment/)?(?P<id>AP-\w+)'
19 'url': 'https://www.redbull.tv/video/AP-1Q756YYX51W11/abc-of-wrc',
20 'md5': 'fb0445b98aa4394e504b413d98031d1f',
22 'id': 'AP-1Q756YYX51W11',
24 'title': 'ABC of...WRC',
25 'description': 'md5:5c7ed8f4015c8492ecf64b6ab31e7d31',
27 # 'timestamp': 1488405786,
28 # 'upload_date': '20170301',
32 'url': 'https://www.redbull.tv/video/AP-1PMT5JCWH1W11/grime?playlist=shows:shows-playall:web',
34 'id': 'AP-1PMT5JCWH1W11',
36 'title': 'Grime - Hashtags S2 E4',
37 'description': 'md5:334b741c8c1ce65be057eab6773c1cf5',
39 # 'timestamp': 1487290093,
40 # 'upload_date': '20170217',
46 'skip_download': True,
50 'url': 'https://www.redbull.tv/live/AP-1R5DX49XS1W11/segment/AP-1QSAQJ6V52111/semi-finals',
52 'id': 'AP-1QSAQJ6V52111',
54 'title': 'Semi Finals - Vans Park Series Pro Tour',
55 'description': 'md5:306a2783cdafa9e65e39aa62f514fd97',
56 'duration': 11791.991,
59 'skip_download': True,
62 'url': 'https://www.redbull.tv/film/AP-1MSKKF5T92111/in-motion',
63 'only_matching': True,
66 def _real_extract(self
, url
):
67 video_id
= self
._match
_id
(url
)
69 session
= self
._download
_json
(
70 'https://api-v2.redbull.tv/session', video_id
,
71 note
='Downloading access token', query
={
73 'category': 'personal_computer',
77 if session
.get('code') == 'error':
78 raise ExtractorError('%s said: %s' % (
79 self
.IE_NAME
, session
['message']))
80 auth
= '%s %s' % (session
.get('token_type', 'Bearer'), session
['access_token'])
83 info
= self
._download
_json
(
84 'https://api-v2.redbull.tv/content/%s' % video_id
,
85 video_id
, note
='Downloading video information',
86 headers
={'Authorization': auth
}
88 except ExtractorError
as e
:
89 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 404:
90 error_message
= self
._parse
_json
(
91 e
.cause
.read().decode(), video_id
)['message']
92 raise ExtractorError('%s said: %s' % (
93 self
.IE_NAME
, error_message
), expected
=True)
96 video
= info
['video_product']
98 title
= info
['title'].strip()
100 formats
= self
._extract
_m
3u8_formats
(
101 video
['url'], video_id
, 'mp4', entry_protocol
='m3u8_native',
103 self
._sort
_formats
(formats
)
106 for _
, captions
in (try_get(
107 video
, lambda x
: x
['attachments']['captions'],
108 dict) or {}).items():
109 if not captions
or not isinstance(captions
, list):
111 for caption
in captions
:
112 caption_url
= caption
.get('url')
115 ext
= caption
.get('format')
118 subtitles
.setdefault(caption
.get('lang') or 'en', []).append({
123 subheading
= info
.get('subheading')
125 title
+= ' - %s' % subheading
130 'description': info
.get('long_description') or info
.get(
131 'short_description'),
132 'duration': float_or_none(video
.get('duration'), scale
=1000),
133 # 'timestamp': unified_timestamp(info.get('published')),
134 'series': info
.get('show_title'),
135 'season_number': int_or_none(info
.get('season_number')),
136 'episode_number': int_or_none(info
.get('episode_number')),
138 'subtitles': subtitles
,