]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/redbulltv.py
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)/(?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 'url': 'https://www.redbull.tv/film/AP-1MSKKF5T92111/in-motion',
47 'only_matching': True,
50 def _real_extract(self
, url
):
51 video_id
= self
._match
_id
(url
)
53 session
= self
._download
_json
(
54 'https://api-v2.redbull.tv/session', video_id
,
55 note
='Downloading access token', query
={
57 'category': 'personal_computer',
61 if session
.get('code') == 'error':
62 raise ExtractorError('%s said: %s' % (
63 self
.IE_NAME
, session
['message']))
64 auth
= '%s %s' % (session
.get('token_type', 'Bearer'), session
['access_token'])
67 info
= self
._download
_json
(
68 'https://api-v2.redbull.tv/content/%s' % video_id
,
69 video_id
, note
='Downloading video information',
70 headers
={'Authorization': auth
}
72 except ExtractorError
as e
:
73 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 404:
74 error_message
= self
._parse
_json
(
75 e
.cause
.read().decode(), video_id
)['message']
76 raise ExtractorError('%s said: %s' % (
77 self
.IE_NAME
, error_message
), expected
=True)
80 video
= info
['video_product']
82 title
= info
['title'].strip()
84 formats
= self
._extract
_m
3u8_formats
(
85 video
['url'], video_id
, 'mp4', 'm3u8_native')
86 self
._sort
_formats
(formats
)
89 for _
, captions
in (try_get(
90 video
, lambda x
: x
['attachments']['captions'],
92 if not captions
or not isinstance(captions
, list):
94 for caption
in captions
:
95 caption_url
= caption
.get('url')
98 ext
= caption
.get('format')
101 subtitles
.setdefault(caption
.get('lang') or 'en', []).append({
106 subheading
= info
.get('subheading')
108 title
+= ' - %s' % subheading
113 'description': info
.get('long_description') or info
.get(
114 'short_description'),
115 'duration': float_or_none(video
.get('duration'), scale
=1000),
116 # 'timestamp': unified_timestamp(info.get('published')),
117 'series': info
.get('show_title'),
118 'season_number': int_or_none(info
.get('season_number')),
119 'episode_number': int_or_none(info
.get('episode_number')),
121 'subtitles': subtitles
,