@ -0,0 +1,138 @@ | |||
# coding: utf-8 | |||
from __future__ import unicode_literals | |||
import re | |||
from .common import InfoExtractor | |||
from ..compat import compat_urllib_parse | |||
from ..utils import ( | |||
ExtractorError, | |||
int_or_none, | |||
) | |||
class KalturaIE(InfoExtractor): | |||
_VALID_URL = r'''(?x) | |||
(?:kaltura:| | |||
https?://(:?(?:www|cdnapisec)\.)?kaltura\.com/index\.php/kwidget/(?:[^/]+/)*?wid/_ | |||
)(?P<partner_id>\d+) | |||
(?::| | |||
/(?:[^/]+/)*?entry_id/ | |||
)(?P<id>[0-9a-z_]+)''' | |||
_API_BASE = 'http://cdnapi.kaltura.com/api_v3/index.php?' | |||
_TESTS = [ | |||
{ | |||
'url': 'kaltura:269692:1_1jc2y3e4', | |||
'md5': '3adcbdb3dcc02d647539e53f284ba171', | |||
'info_dict': { | |||
'id': '1_1jc2y3e4', | |||
'ext': 'mp4', | |||
'title': 'Track 4', | |||
'upload_date': '20131219', | |||
'uploader_id': 'mlundberg@wolfgangsvault.com', | |||
'description': 'The Allman Brothers Band, 12/16/1981', | |||
'thumbnail': 're:^https?://.*/thumbnail/.*', | |||
'timestamp': int, | |||
}, | |||
}, | |||
{ | |||
'url': 'http://www.kaltura.com/index.php/kwidget/cache_st/1300318621/wid/_269692/uiconf_id/3873291/entry_id/1_1jc2y3e4', | |||
'only_matching': True, | |||
}, | |||
{ | |||
'url': 'https://cdnapisec.kaltura.com/index.php/kwidget/wid/_557781/uiconf_id/22845202/entry_id/1_plr1syf3', | |||
'only_matching': True, | |||
}, | |||
] | |||
def _kaltura_api_call(self, video_id, actions, *args, **kwargs): | |||
params = actions[0] | |||
if len(actions) > 1: | |||
for i, a in enumerate(actions[1:], start=1): | |||
for k, v in a.items(): | |||
params['%d:%s' % (i, k)] = v | |||
query = compat_urllib_parse.urlencode(params) | |||
url = self._API_BASE + query | |||
data = self._download_json(url, video_id, *args, **kwargs) | |||
status = data if len(actions) == 1 else data[0] | |||
if status.get('objectType') == 'KalturaAPIException': | |||
raise ExtractorError( | |||
'%s said: %s' % (self.IE_NAME, status['message'])) | |||
return data | |||
def _get_kaltura_signature(self, video_id, partner_id): | |||
actions = [{ | |||
'apiVersion': '3.1', | |||
'expiry': 86400, | |||
'format': 1, | |||
'service': 'session', | |||
'action': 'startWidgetSession', | |||
'widgetId': '_%s' % partner_id, | |||
}] | |||
return self._kaltura_api_call( | |||
video_id, actions, note='Downloading Kaltura signature')['ks'] | |||
def _get_video_info(self, video_id, partner_id): | |||
signature = self._get_kaltura_signature(video_id, partner_id) | |||
actions = [ | |||
{ | |||
'action': 'null', | |||
'apiVersion': '3.1.5', | |||
'clientTag': 'kdp:v3.8.5', | |||
'format': 1, # JSON, 2 = XML, 3 = PHP | |||
'service': 'multirequest', | |||
'ks': signature, | |||
}, | |||
{ | |||
'action': 'get', | |||
'entryId': video_id, | |||
'service': 'baseentry', | |||
'version': '-1', | |||
}, | |||
{ | |||
'action': 'getContextData', | |||
'contextDataParams:objectType': 'KalturaEntryContextDataParams', | |||
'contextDataParams:referrer': 'http://www.kaltura.com/', | |||
'contextDataParams:streamerType': 'http', | |||
'entryId': video_id, | |||
'service': 'baseentry', | |||
}, | |||
] | |||
return self._kaltura_api_call( | |||
video_id, actions, note='Downloading video info JSON') | |||
def _real_extract(self, url): | |||
video_id = self._match_id(url) | |||
mobj = re.match(self._VALID_URL, url) | |||
partner_id, entry_id = mobj.group('partner_id'), mobj.group('id') | |||
info, source_data = self._get_video_info(entry_id, partner_id) | |||
formats = [{ | |||
'format_id': '%(fileExt)s-%(bitrate)s' % f, | |||
'ext': f['fileExt'], | |||
'tbr': f['bitrate'], | |||
'fps': f.get('frameRate'), | |||
'filesize_approx': int_or_none(f.get('size'), invscale=1024), | |||
'container': f.get('containerFormat'), | |||
'vcodec': f.get('videoCodecId'), | |||
'height': f.get('height'), | |||
'width': f.get('width'), | |||
'url': '%s/flavorId/%s' % (info['dataUrl'], f['id']), | |||
} for f in source_data['flavorAssets']] | |||
self._sort_formats(formats) | |||
return { | |||
'id': video_id, | |||
'title': info['name'], | |||
'formats': formats, | |||
'description': info.get('description'), | |||
'thumbnail': info.get('thumbnailUrl'), | |||
'duration': info.get('duration'), | |||
'timestamp': info.get('createdAt'), | |||
'uploader_id': info.get('userId'), | |||
'view_count': info.get('plays'), | |||
} |
@ -0,0 +1,85 @@ | |||
# coding: utf-8 | |||
from __future__ import unicode_literals | |||
from .common import InfoExtractor | |||
from ..utils import ( | |||
unified_strdate, | |||
int_or_none, | |||
qualities, | |||
) | |||
class OdnoklassnikiIE(InfoExtractor): | |||
_VALID_URL = r'https?://(?:odnoklassniki|ok)\.ru/(?:video|web-api/video/moviePlayer)/(?P<id>\d+)' | |||
_TESTS = [{ | |||
'url': 'http://ok.ru/video/20079905452', | |||
'md5': '8e24ad2da6f387948e7a7d44eb8668fe', | |||
'info_dict': { | |||
'id': '20079905452', | |||
'ext': 'mp4', | |||
'title': 'Культура меняет нас (прекрасный ролик!))', | |||
'duration': 100, | |||
'upload_date': '20141207', | |||
'uploader_id': '330537914540', | |||
'uploader': 'Виталий Добровольский', | |||
'like_count': int, | |||
'age_limit': 0, | |||
}, | |||
}, { | |||
'url': 'http://ok.ru/web-api/video/moviePlayer/20079905452', | |||
'only_matching': True, | |||
}] | |||
def _real_extract(self, url): | |||
video_id = self._match_id(url) | |||
webpage = self._download_webpage(url, video_id) | |||
player = self._parse_json( | |||
self._search_regex( | |||
r"OKVideo\.start\(({.+?})\s*,\s*'VideoAutoplay_player'", webpage, 'player'), | |||
video_id) | |||
metadata = self._parse_json(player['flashvars']['metadata'], video_id) | |||
movie = metadata['movie'] | |||
title = movie['title'] | |||
thumbnail = movie.get('poster') | |||
duration = int_or_none(movie.get('duration')) | |||
author = metadata.get('author', {}) | |||
uploader_id = author.get('id') | |||
uploader = author.get('name') | |||
upload_date = unified_strdate(self._html_search_meta( | |||
'ya:ovs:upload_date', webpage, 'upload date')) | |||
age_limit = None | |||
adult = self._html_search_meta( | |||
'ya:ovs:adult', webpage, 'age limit') | |||
if adult: | |||
age_limit = 18 if adult == 'true' else 0 | |||
like_count = int_or_none(metadata.get('likeCount')) | |||
quality = qualities(('mobile', 'lowest', 'low', 'sd', 'hd')) | |||
formats = [{ | |||
'url': f['url'], | |||
'ext': 'mp4', | |||
'format_id': f['name'], | |||
'quality': quality(f['name']), | |||
} for f in metadata['videos']] | |||
return { | |||
'id': video_id, | |||
'title': title, | |||
'thumbnail': thumbnail, | |||
'duration': duration, | |||
'upload_date': upload_date, | |||
'uploader': uploader, | |||
'uploader_id': uploader_id, | |||
'like_count': like_count, | |||
'age_limit': age_limit, | |||
'formats': formats, | |||
} |
@ -0,0 +1,88 @@ | |||
# -*- coding: utf-8 -*- | |||
from __future__ import unicode_literals | |||
from .common import InfoExtractor | |||
from ..utils import ( | |||
ExtractorError, | |||
unified_strdate, | |||
int_or_none, | |||
) | |||
class Puls4IE(InfoExtractor): | |||
_VALID_URL = r'https?://(?:www\.)?puls4\.com/video/[^/]+/play/(?P<id>[0-9]+)' | |||
_TESTS = [{ | |||
'url': 'http://www.puls4.com/video/pro-und-contra/play/2716816', | |||
'md5': '49f6a6629747eeec43cef6a46b5df81d', | |||
'info_dict': { | |||
'id': '2716816', | |||
'ext': 'mp4', | |||
'title': 'Pro und Contra vom 23.02.2015', | |||
'description': 'md5:293e44634d9477a67122489994675db6', | |||
'duration': 2989, | |||
'upload_date': '20150224', | |||
'uploader': 'PULS_4', | |||
}, | |||
'skip': 'Only works from Germany', | |||
}, { | |||
'url': 'http://www.puls4.com/video/kult-spielfilme/play/1298106', | |||
'md5': '6a48316c8903ece8dab9b9a7bf7a59ec', | |||
'info_dict': { | |||
'id': '1298106', | |||
'ext': 'mp4', | |||
'title': 'Lucky Fritz', | |||
}, | |||
'skip': 'Only works from Germany', | |||
}] | |||
def _real_extract(self, url): | |||
video_id = self._match_id(url) | |||
webpage = self._download_webpage(url, video_id) | |||
error_message = self._html_search_regex( | |||
r'<div class="message-error">(.+?)</div>', | |||
webpage, 'error message', default=None) | |||
if error_message: | |||
raise ExtractorError( | |||
'%s returned error: %s' % (self.IE_NAME, error_message), expected=True) | |||
real_url = self._html_search_regex( | |||
r'\"fsk-button\".+?href=\"([^"]+)', | |||
webpage, 'fsk_button', default=None) | |||
if real_url: | |||
webpage = self._download_webpage(real_url, video_id) | |||
player = self._search_regex( | |||
r'p4_video_player(?:_iframe)?\("video_\d+_container"\s*,(.+?)\);\s*\}', | |||
webpage, 'player') | |||
player_json = self._parse_json( | |||
'[%s]' % player, video_id, | |||
transform_source=lambda s: s.replace('undefined,', '')) | |||
formats = None | |||
result = None | |||
for v in player_json: | |||
if isinstance(v, list) and not formats: | |||
formats = [{ | |||
'url': f['url'], | |||
'format': 'hd' if f.get('hd') else 'sd', | |||
'width': int_or_none(f.get('size_x')), | |||
'height': int_or_none(f.get('size_y')), | |||
'tbr': int_or_none(f.get('bitrate')), | |||
} for f in v] | |||
self._sort_formats(formats) | |||
elif isinstance(v, dict) and not result: | |||
result = { | |||
'id': video_id, | |||
'title': v['videopartname'].strip(), | |||
'description': v.get('videotitle'), | |||
'duration': int_or_none(v.get('videoduration') or v.get('episodeduration')), | |||
'upload_date': unified_strdate(v.get('clipreleasetime')), | |||
'uploader': v.get('channel'), | |||
} | |||
result['formats'] = formats | |||
return result |