[kaltura] Add support for referrer protected videos (#7409)

pull/7583/head
Sergey M․ 9 years ago
parent c711383811
commit 01b06aedcf

@ -2,12 +2,17 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import re import re
import base64
from .common import InfoExtractor from .common import InfoExtractor
from ..compat import compat_urllib_parse from ..compat import (
compat_urllib_parse,
compat_urlparse,
)
from ..utils import ( from ..utils import (
ExtractorError, ExtractorError,
int_or_none, int_or_none,
unsmuggle_url,
) )
@ -121,13 +126,28 @@ class KalturaIE(InfoExtractor):
video_id, actions, note='Downloading video info JSON') video_id, actions, note='Downloading video info JSON')
def _real_extract(self, url): def _real_extract(self, url):
url, smuggled_data = unsmuggle_url(url, {})
mobj = re.match(self._VALID_URL, url) mobj = re.match(self._VALID_URL, url)
partner_id = mobj.group('partner_id_s') or mobj.group('partner_id') or mobj.group('partner_id_html5') partner_id = mobj.group('partner_id_s') or mobj.group('partner_id') or mobj.group('partner_id_html5')
entry_id = mobj.group('id_s') or mobj.group('id') or mobj.group('id_html5') entry_id = mobj.group('id_s') or mobj.group('id') or mobj.group('id_html5')
info, source_data = self._get_video_info(entry_id, partner_id) info, source_data = self._get_video_info(entry_id, partner_id)
formats = [{ source_url = smuggled_data.get('source_url')
if source_url:
referrer = base64.b64encode(
'://'.join(compat_urlparse.urlparse(source_url)[:2])
.encode('utf-8')).decode('utf-8')
else:
referrer = None
formats = []
for f in source_data['flavorAssets']:
video_url = '%s/flavorId/%s' % (info['dataUrl'], f['id'])
if referrer:
video_url += '?referrer=%s' % referrer
formats.append({
'format_id': '%(fileExt)s-%(bitrate)s' % f, 'format_id': '%(fileExt)s-%(bitrate)s' % f,
'ext': f['fileExt'], 'ext': f['fileExt'],
'tbr': f['bitrate'], 'tbr': f['bitrate'],
@ -137,8 +157,9 @@ class KalturaIE(InfoExtractor):
'vcodec': f.get('videoCodecId'), 'vcodec': f.get('videoCodecId'),
'height': f.get('height'), 'height': f.get('height'),
'width': f.get('width'), 'width': f.get('width'),
'url': '%s/flavorId/%s' % (info['dataUrl'], f['id']), 'url': video_url,
} for f in source_data['flavorAssets']] })
self._check_formats(formats, entry_id)
self._sort_formats(formats) self._sort_formats(formats)
return { return {

Loading…
Cancel
Save