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|cdnapisec)\.)?kaltura\.com/(?:
18 (?:index\.php/kwidget/(?:[^/]+/)*?wid/_)|
19 (?:html5/html5lib/v(?:[\d.]+)/mwEmbedFrame.php/p/\d+)
21 )(?P<partner_id>\d+)?(?::|/(?:[^/]+/)*?entry_id/)(?P<id>[0-9a-z_]+)
22 (?:\?wid=_(?P<partner_id_html5>\d+))?'''
23 _API_BASE = 'http://cdnapi.kaltura.com/api_v3/index.php?'
26 'url': 'kaltura:269692:1_1jc2y3e4',
27 'md5': '3adcbdb3dcc02d647539e53f284ba171',
32 'upload_date': '20131219',
33 'uploader_id': 'mlundberg@wolfgangsvault.com',
34 'description': 'The Allman Brothers Band, 12/16/1981',
35 'thumbnail': 're:^https?://.*/thumbnail/.*',
40 'url': 'http://www.kaltura.com/index.php/kwidget/cache_st/1300318621/wid/_269692/uiconf_id/3873291/entry_id/1_1jc2y3e4',
41 'only_matching': True,
44 'url': 'https://cdnapisec.kaltura.com/index.php/kwidget/wid/_557781/uiconf_id/22845202/entry_id/1_plr1syf3',
45 'only_matching': True,
48 'url': 'https://cdnapisec.kaltura.com/html5/html5lib/v2.30.2/mwEmbedFrame.php/p/1337/uiconf_id/20540612/entry_id/1_sf5ovm7u?wid=_243342',
49 'only_matching': True,
53 def _kaltura_api_call(self, video_id, actions, *args, **kwargs):
56 for i, a in enumerate(actions[1:], start=1):
57 for k, v in a.items():
58 params['%d:%s' % (i, k)] = v
60 query = compat_urllib_parse.urlencode(params)
61 url = self._API_BASE + query
62 data = self._download_json(url, video_id, *args, **kwargs)
64 status = data if len(actions) == 1 else data[0]
65 if status.get('objectType') == 'KalturaAPIException':
67 '%s said: %s' % (self.IE_NAME, status['message']))
71 def _get_kaltura_signature(self, video_id, partner_id):
77 'action': 'startWidgetSession',
78 'widgetId': '_%s' % partner_id,
80 return self._kaltura_api_call(
81 video_id, actions, note='Downloading Kaltura signature')['ks']
83 def _get_video_info(self, video_id, partner_id):
84 signature = self._get_kaltura_signature(video_id, partner_id)
88 'apiVersion': '3.1.5',
89 'clientTag': 'kdp:v3.8.5',
90 'format': 1, # JSON, 2 = XML, 3 = PHP
91 'service': 'multirequest',
97 'service': 'baseentry',
101 'action': 'getContextData',
102 'contextDataParams:objectType': 'KalturaEntryContextDataParams',
103 'contextDataParams:referrer': 'http://www.kaltura.com/',
104 'contextDataParams:streamerType': 'http',
106 'service': 'baseentry',
109 return self._kaltura_api_call(
110 video_id, actions, note='Downloading video info JSON')
112 def _real_extract(self, url):
113 video_id = self._match_id(url)
114 mobj = re.match(self._VALID_URL, url)
115 partner_id, entry_id = mobj.group('partner_id') or mobj.group('partner_id_html5'), mobj.group('id')
117 info, source_data = self._get_video_info(entry_id, partner_id)
120 'format_id': '%(fileExt)s-%(bitrate)s' % f,
123 'fps': f.get('frameRate'),
124 'filesize_approx': int_or_none(f.get('size'), invscale=1024),
125 'container': f.get('containerFormat'),
126 'vcodec': f.get('videoCodecId'),
127 'height': f.get('height'),
128 'width': f.get('width'),
129 'url': '%s/flavorId/%s' % (info['dataUrl'], f['id']),
130 } for f in source_data['flavorAssets']]
131 self._sort_formats(formats)
135 'title': info['name'],
137 'description': info.get('description'),
138 'thumbnail': info.get('thumbnailUrl'),
139 'duration': info.get('duration'),
140 'timestamp': info.get('createdAt'),
141 'uploader_id': info.get('userId'),
142 'view_count': info.get('plays'),