]>
jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/kaltura.py
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',
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': 'getContextData',
119 'contextDataParams:objectType': 'KalturaEntryContextDataParams',
120 'contextDataParams:referrer': 'http://www.kaltura.com/',
121 'contextDataParams:streamerType': 'http',
123 'service': 'baseentry',
126 return self
._kaltura
_api
_call
(
127 video_id
, actions
, note
='Downloading video info JSON')
129 def _real_extract(self
, url
):
130 url
, smuggled_data
= unsmuggle_url(url
, {})
132 mobj
= re
.match(self
._VALID
_URL
, url
)
133 partner_id
= mobj
.group('partner_id_s') or mobj
.group('partner_id') or mobj
.group('partner_id_html5')
134 entry_id
= mobj
.group('id_s') or mobj
.group('id') or mobj
.group('id_html5')
136 info
, source_data
= self
._get
_video
_info
(entry_id
, partner_id
)
138 source_url
= smuggled_data
.get('source_url')
140 referrer
= base64
.b64encode(
141 '://'.join(compat_urlparse
.urlparse(source_url
)[:2])
142 .encode('utf-8')).decode('utf-8')
147 for f
in source_data
['flavorAssets']:
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 self
._check
_formats
(formats
, entry_id
)
164 self
._sort
_formats
(formats
)
168 'title': info
['name'],
170 'description': clean_html(info
.get('description')),
171 'thumbnail': info
.get('thumbnailUrl'),
172 'duration': info
.get('duration'),
173 'timestamp': info
.get('createdAt'),
174 'uploader_id': info
.get('userId'),
175 'view_count': info
.get('plays'),