]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/kaltura.py
ccbc39c665412980e6b6104e83ffaf2e8574517f
2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
20 class KalturaIE(InfoExtractor
):
23 kaltura:(?P<partner_id_s>\d+):(?P<id_s>[0-9a-z_]+)|
25 (:?(?:www|cdnapi(?:sec)?)\.)?kaltura\.com/
30 (?:[^/]+/)*?wid/_(?P<partner_id>\d+)/
31 (?:[^/]+/)*?entry_id/(?P<id>[0-9a-z_]+)|
34 (?:[^/]+/)*?entry_id/(?P<id_html5>[0-9a-z_]+)
35 .*\?.*\bwid=_(?P<partner_id_html5>\d+)
40 _API_BASE
= 'http://cdnapi.kaltura.com/api_v3/index.php?'
43 'url': 'kaltura:269692:1_1jc2y3e4',
44 'md5': '3adcbdb3dcc02d647539e53f284ba171',
48 'title': 'Straight from the Heart',
49 'upload_date': '20131219',
50 'uploader_id': 'mlundberg@wolfgangsvault.com',
51 'description': 'The Allman Brothers Band, 12/16/1981',
52 'thumbnail': 're:^https?://.*/thumbnail/.*',
57 'url': 'http://www.kaltura.com/index.php/kwidget/cache_st/1300318621/wid/_269692/uiconf_id/3873291/entry_id/1_1jc2y3e4',
58 'only_matching': True,
61 'url': 'https://cdnapisec.kaltura.com/index.php/kwidget/wid/_557781/uiconf_id/22845202/entry_id/1_plr1syf3',
62 'only_matching': True,
65 'url': 'https://cdnapisec.kaltura.com/html5/html5lib/v2.30.2/mwEmbedFrame.php/p/1337/uiconf_id/20540612/entry_id/1_sf5ovm7u?wid=_243342',
66 'only_matching': True,
70 def _kaltura_api_call(self
, video_id
, actions
, *args
, **kwargs
):
73 for i
, a
in enumerate(actions
[1:], start
=1):
74 for k
, v
in a
.items():
75 params
['%d:%s' % (i
, k
)] = v
77 query
= compat_urllib_parse
.urlencode(params
)
78 url
= self
._API
_BASE
+ query
79 data
= self
._download
_json
(url
, video_id
, *args
, **kwargs
)
81 status
= data
if len(actions
) == 1 else data
[0]
82 if status
.get('objectType') == 'KalturaAPIException':
84 '%s said: %s' % (self
.IE_NAME
, status
['message']))
88 def _get_kaltura_signature(self
, video_id
, partner_id
):
94 'action': 'startWidgetSession',
95 'widgetId': '_%s' % partner_id
,
97 return self
._kaltura
_api
_call
(
98 video_id
, actions
, note
='Downloading Kaltura signature')['ks']
100 def _get_video_info(self
, video_id
, partner_id
):
101 signature
= self
._get
_kaltura
_signature
(video_id
, partner_id
)
105 'apiVersion': '3.1.5',
106 'clientTag': 'kdp:v3.8.5',
107 'format': 1, # JSON, 2 = XML, 3 = PHP
108 'service': 'multirequest',
114 'service': 'baseentry',
118 'action': 'getbyentryid',
120 'service': 'flavorAsset',
123 return self
._kaltura
_api
_call
(
124 video_id
, actions
, note
='Downloading video info JSON')
126 def _real_extract(self
, url
):
127 url
, smuggled_data
= unsmuggle_url(url
, {})
129 mobj
= re
.match(self
._VALID
_URL
, url
)
130 partner_id
= mobj
.group('partner_id_s') or mobj
.group('partner_id') or mobj
.group('partner_id_html5')
131 entry_id
= mobj
.group('id_s') or mobj
.group('id') or mobj
.group('id_html5')
133 info
, flavor_assets
= self
._get
_video
_info
(entry_id
, partner_id
)
135 source_url
= smuggled_data
.get('source_url')
137 referrer
= base64
.b64encode(
138 '://'.join(compat_urlparse
.urlparse(source_url
)[:2])
139 .encode('utf-8')).decode('utf-8')
144 for f
in flavor_assets
:
145 # Continue if asset is not ready
148 video_url
= '%s/flavorId/%s' % (info
['dataUrl'], f
['id'])
150 video_url
+= '?referrer=%s' % referrer
152 'format_id': '%(fileExt)s-%(bitrate)s' % f
,
153 'ext': f
.get('fileExt'),
154 'tbr': int_or_none(f
['bitrate']),
155 'fps': int_or_none(f
.get('frameRate')),
156 'filesize_approx': int_or_none(f
.get('size'), invscale
=1024),
157 'container': f
.get('containerFormat'),
158 'vcodec': f
.get('videoCodecId'),
159 'height': int_or_none(f
.get('height')),
160 'width': int_or_none(f
.get('width')),
163 m3u8_url
= info
['dataUrl'].replace('format/url', 'format/applehttp')
165 m3u8_url
+= '?referrer=%s' % referrer
166 formats
.extend(self
._extract
_m
3u8_formats
(
167 m3u8_url
, entry_id
, 'mp4', 'm3u8_native', m3u8_id
='hls', fatal
=False))
169 self
._check
_formats
(formats
, entry_id
)
170 self
._sort
_formats
(formats
)
174 'title': info
['name'],
176 'description': clean_html(info
.get('description')),
177 'thumbnail': info
.get('thumbnailUrl'),
178 'duration': info
.get('duration'),
179 'timestamp': info
.get('createdAt'),
180 'uploader_id': info
.get('userId'),
181 'view_count': info
.get('plays'),