]>
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
 
  12 class RedBullTVIE(InfoExtractor
): 
  13     _VALID_URL 
= r
'https?://(?:www\.)?redbull\.tv/video/(?P<id>AP-\w+)' 
  16         'url': 'https://www.redbull.tv/video/AP-1Q6XCDTAN1W11', 
  17         'md5': 'fb0445b98aa4394e504b413d98031d1f', 
  19             'id': 'AP-1Q6XCDTAN1W11', 
  21             'title': 'ABC of... WRC - ABC of... S1E6', 
  22             'description': 'md5:5c7ed8f4015c8492ecf64b6ab31e7d31', 
  27         'url': 'https://www.redbull.tv/video/AP-1PMHKJFCW1W11', 
  29             'id': 'AP-1PMHKJFCW1W11', 
  31             'title': 'Grime - Hashtags S2E4', 
  32             'description': 'md5:b5f522b89b72e1e23216e5018810bb25', 
  36             'skip_download': True, 
  40     def _real_extract(self
, url
): 
  41         video_id 
= self
._match
_id
(url
) 
  43         session 
= self
._download
_json
( 
  44             'https://api.redbull.tv/v3/session', video_id
, 
  45             note
='Downloading access token', query
={ 
  46                 'category': 'personal_computer', 
  49         if session
.get('code') == 'error': 
  50             raise ExtractorError('%s said: %s' % ( 
  51                 self
.IE_NAME
, session
['message'])) 
  52         token 
= session
['token'] 
  55             video 
= self
._download
_json
( 
  56                 'https://api.redbull.tv/v3/products/' + video_id
, 
  57                 video_id
, note
='Downloading video information', 
  58                 headers
={'Authorization': token
} 
  60         except ExtractorError 
as e
: 
  61             if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code 
== 404: 
  62                 error_message 
= self
._parse
_json
( 
  63                     e
.cause
.read().decode(), video_id
)['error'] 
  64                 raise ExtractorError('%s said: %s' % ( 
  65                     self
.IE_NAME
, error_message
), expected
=True) 
  68         title 
= video
['title'].strip() 
  70         formats 
= self
._extract
_m
3u8_formats
( 
  71             'https://dms.redbull.tv/v3/%s/%s/playlist.m3u8' % (video_id
, token
), 
  72             video_id
, 'mp4', entry_protocol
='m3u8_native', m3u8_id
='hls') 
  73         self
._sort
_formats
(formats
) 
  76         for resource 
in video
.get('resources', []): 
  77             if resource
.startswith('closed_caption_'): 
  78                 splitted_resource 
= resource
.split('_') 
  79                 if splitted_resource
[2]: 
  80                     subtitles
.setdefault('en', []).append({ 
  81                         'url': 'https://resources.redbull.tv/%s/%s' % (video_id
, resource
), 
  82                         'ext': splitted_resource
[2], 
  85         subheading 
= video
.get('subheading') 
  87             title 
+= ' - %s' % subheading
 
  92             'description': video
.get('long_description') or video
.get( 
  94             'duration': float_or_none(video
.get('duration'), scale
=1000), 
  96             'subtitles': subtitles
,