]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/kaltura.py
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/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,
43 'url': 'https://cdnapisec.kaltura.com/index.php/kwidget/wid/_557781/uiconf_id/22845202/entry_id/1_plr1syf3',
44 'only_matching': True,
48 def _kaltura_api_call(self
, video_id
, actions
, *args
, **kwargs
):
51 for i
, a
in enumerate(actions
[1:], start
=1):
52 for k
, v
in a
.items():
53 params
['%d:%s' % (i
, k
)] = v
55 query
= compat_urllib_parse
.urlencode(params
)
56 url
= self
._API
_BASE
+ query
57 data
= self
._download
_json
(url
, video_id
, *args
, **kwargs
)
59 status
= data
if len(actions
) == 1 else data
[0]
60 if status
.get('objectType') == 'KalturaAPIException':
62 '%s said: %s' % (self
.IE_NAME
, status
['message']))
66 def _get_kaltura_signature(self
, video_id
, partner_id
):
72 'action': 'startWidgetSession',
73 'widgetId': '_%s' % partner_id
,
75 return self
._kaltura
_api
_call
(
76 video_id
, actions
, note
='Downloading Kaltura signature')['ks']
78 def _get_video_info(self
, video_id
, partner_id
):
79 signature
= self
._get
_kaltura
_signature
(video_id
, partner_id
)
83 'apiVersion': '3.1.5',
84 'clientTag': 'kdp:v3.8.5',
85 'format': 1, # JSON, 2 = XML, 3 = PHP
86 'service': 'multirequest',
92 'service': 'baseentry',
96 'action': 'getContextData',
97 'contextDataParams:objectType': 'KalturaEntryContextDataParams',
98 'contextDataParams:referrer': 'http://www.kaltura.com/',
99 'contextDataParams:streamerType': 'http',
101 'service': 'baseentry',
104 return self
._kaltura
_api
_call
(
105 video_id
, actions
, note
='Downloading video info JSON')
107 def _real_extract(self
, url
):
108 video_id
= self
._match
_id
(url
)
109 mobj
= re
.match(self
._VALID
_URL
, url
)
110 partner_id
, entry_id
= mobj
.group('partner_id'), mobj
.group('id')
112 info
, source_data
= self
._get
_video
_info
(entry_id
, partner_id
)
115 'format_id': '%(fileExt)s-%(bitrate)s' % f
,
118 'fps': f
.get('frameRate'),
119 'filesize_approx': int_or_none(f
.get('size'), invscale
=1024),
120 'container': f
.get('containerFormat'),
121 'vcodec': f
.get('videoCodecId'),
122 'height': f
.get('height'),
123 'width': f
.get('width'),
124 'url': '%s/flavorId/%s' % (info
['dataUrl'], f
['id']),
125 } for f
in source_data
['flavorAssets']]
126 self
._sort
_formats
(formats
)
130 'title': info
['name'],
132 'description': info
.get('description'),
133 'thumbnail': info
.get('thumbnailUrl'),
134 'duration': info
.get('duration'),
135 'timestamp': info
.get('createdAt'),
136 'uploader_id': info
.get('userId'),
137 'view_count': info
.get('plays'),