2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..compat import compat_urllib_parse
14 class KalturaIE(InfoExtractor):
17 https?://(:?www\.)?kaltura\.com/index\.php/kwidget/(?:[^/]+/)*?wid/_
20 /(?:[^/]+/)*?entry_id/
21 )(?P<id>[0-9a-z_]+)'''
22 _API_BASE = 'http://cdnapi.kaltura.com/api_v3/index.php?'
25 'url': 'kaltura:269692:1_1jc2y3e4',
26 'md5': '3adcbdb3dcc02d647539e53f284ba171',
31 'upload_date': '20131219',
32 'uploader_id': 'mlundberg@wolfgangsvault.com',
33 'description': 'The Allman Brothers Band, 12/16/1981',
34 'thumbnail': 're:^https?://.*/thumbnail/.*',
39 'url': 'http://www.kaltura.com/index.php/kwidget/cache_st/1300318621/wid/_269692/uiconf_id/3873291/entry_id/1_1jc2y3e4',
40 'only_matching': True,
44 def _kaltura_api_call(self, video_id, actions, *args, **kwargs):
47 for i, a in enumerate(actions[1:], start=1):
48 for k, v in a.items():
49 params['%d:%s' % (i, k)] = v
51 query = compat_urllib_parse.urlencode(params)
52 url = self._API_BASE + query
53 data = self._download_json(url, video_id, *args, **kwargs)
55 status = data if len(actions) == 1 else data[0]
56 if status.get('objectType') == 'KalturaAPIException':
58 '%s said: %s' % (self.IE_NAME, status['message']))
62 def _get_kaltura_signature(self, video_id, partner_id):
68 'action': 'startWidgetSession',
69 'widgetId': '_%s' % partner_id,
71 return self._kaltura_api_call(
72 video_id, actions, note='Downloading Kaltura signature')['ks']
74 def _get_video_info(self, video_id, partner_id):
75 signature = self._get_kaltura_signature(video_id, partner_id)
79 'apiVersion': '3.1.5',
80 'clientTag': 'kdp:v3.8.5',
81 'format': 1, # JSON, 2 = XML, 3 = PHP
82 'service': 'multirequest',
88 'service': 'baseentry',
92 'action': 'getContextData',
93 'contextDataParams:objectType': 'KalturaEntryContextDataParams',
94 'contextDataParams:referrer': 'http://www.kaltura.com/',
95 'contextDataParams:streamerType': 'http',
97 'service': 'baseentry',
100 return self._kaltura_api_call(
101 video_id, actions, note='Downloading video info JSON')
103 def _real_extract(self, url):
104 video_id = self._match_id(url)
105 mobj = re.match(self._VALID_URL, url)
106 partner_id, entry_id = mobj.group('partner_id'), mobj.group('id')
108 info, source_data = self._get_video_info(entry_id, partner_id)
111 'format_id': '%(fileExt)s-%(bitrate)s' % f,
114 'fps': f.get('frameRate'),
115 'filesize_approx': int_or_none(f.get('size'), invscale=1024),
116 'container': f.get('containerFormat'),
117 'vcodec': f.get('videoCodecId'),
118 'height': f.get('height'),
119 'width': f.get('width'),
120 'url': '%s/flavorId/%s' % (info['dataUrl'], f['id']),
121 } for f in source_data['flavorAssets']]
122 self._sort_formats(formats)
126 'title': info['name'],
128 'description': info.get('description'),
129 'thumbnail': info.get('thumbnailUrl'),
130 'duration': info.get('duration'),
131 'timestamp': info.get('createdAt'),
132 'uploader_id': info.get('userId'),
133 'view_count': info.get('plays'),