Merge pull request #8827 from remitamine/safari
[safari] extract free and preview videos(#7491)
This commit is contained in:
commit
0ec589fac3
|
@ -8,6 +8,7 @@ from .common import InfoExtractor
|
||||||
from ..compat import (
|
from ..compat import (
|
||||||
compat_urllib_parse,
|
compat_urllib_parse,
|
||||||
compat_urlparse,
|
compat_urlparse,
|
||||||
|
compat_parse_qs,
|
||||||
)
|
)
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
clean_html,
|
clean_html,
|
||||||
|
@ -20,21 +21,17 @@ from ..utils import (
|
||||||
class KalturaIE(InfoExtractor):
|
class KalturaIE(InfoExtractor):
|
||||||
_VALID_URL = r'''(?x)
|
_VALID_URL = r'''(?x)
|
||||||
(?:
|
(?:
|
||||||
kaltura:(?P<partner_id_s>\d+):(?P<id_s>[0-9a-z_]+)|
|
kaltura:(?P<partner_id>\d+):(?P<id>[0-9a-z_]+)|
|
||||||
https?://
|
https?://
|
||||||
(:?(?:www|cdnapi(?:sec)?)\.)?kaltura\.com/
|
(:?(?:www|cdnapi(?:sec)?)\.)?kaltura\.com/
|
||||||
(?:
|
(?:
|
||||||
(?:
|
(?:
|
||||||
# flash player
|
# flash player
|
||||||
index\.php/kwidget/
|
index\.php/kwidget|
|
||||||
(?:[^/]+/)*?wid/_(?P<partner_id>\d+)/
|
|
||||||
(?:[^/]+/)*?entry_id/(?P<id>[0-9a-z_]+)|
|
|
||||||
# html5 player
|
# html5 player
|
||||||
html5/html5lib/
|
html5/html5lib/[^/]+/mwEmbedFrame\.php
|
||||||
(?:[^/]+/)*?entry_id/(?P<id_html5>[0-9a-z_]+)
|
|
||||||
.*\?.*\bwid=_(?P<partner_id_html5>\d+)
|
|
||||||
)
|
)
|
||||||
)
|
)(?:/(?P<path>[^?]+))?(?:\?(?P<query>.*))?
|
||||||
)
|
)
|
||||||
'''
|
'''
|
||||||
_API_BASE = 'http://cdnapi.kaltura.com/api_v3/index.php?'
|
_API_BASE = 'http://cdnapi.kaltura.com/api_v3/index.php?'
|
||||||
|
@ -127,10 +124,43 @@ class KalturaIE(InfoExtractor):
|
||||||
url, smuggled_data = unsmuggle_url(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, entry_id = mobj.group('partner_id', 'id')
|
||||||
entry_id = mobj.group('id_s') or mobj.group('id') or mobj.group('id_html5')
|
info, flavor_assets = None, None
|
||||||
|
if partner_id and entry_id:
|
||||||
info, flavor_assets = self._get_video_info(entry_id, partner_id)
|
info, flavor_assets = self._get_video_info(entry_id, partner_id)
|
||||||
|
else:
|
||||||
|
path, query = mobj.group('path', 'query')
|
||||||
|
if not path and not query:
|
||||||
|
raise ExtractorError('Invalid URL', expected=True)
|
||||||
|
params = {}
|
||||||
|
if query:
|
||||||
|
params = compat_parse_qs(query)
|
||||||
|
if path:
|
||||||
|
splitted_path = path.split('/')
|
||||||
|
if not splitted_path[-1]:
|
||||||
|
splitted_path = splitted_path[:-1]
|
||||||
|
for i in range(0, len(splitted_path), 2):
|
||||||
|
params[splitted_path[i]] = [splitted_path[i + 1]]
|
||||||
|
if 'wid' in params:
|
||||||
|
partner_id = params['wid'][0][1:]
|
||||||
|
elif 'p' in params:
|
||||||
|
partner_id = params['p'][0]
|
||||||
|
else:
|
||||||
|
raise ExtractorError('Invalid URL', expected=True)
|
||||||
|
if 'entry_id' in params:
|
||||||
|
entry_id = params['entry_id'][0]
|
||||||
|
info, flavor_assets = self._get_video_info(entry_id, partner_id)
|
||||||
|
elif 'uiconf_id' in params and 'flashvars[referenceId]' in params:
|
||||||
|
reference_id = params['flashvars[referenceId]'][0]
|
||||||
|
webpage = self._download_webpage(url, reference_id)
|
||||||
|
entry_data = self._parse_json(self._search_regex(
|
||||||
|
r'window\.kalturaIframePackageData\s*=\s*({.*});',
|
||||||
|
webpage, 'kalturaIframePackageData'),
|
||||||
|
reference_id)['entryResult']
|
||||||
|
info, flavor_assets = entry_data['meta'], entry_data['contextData']['flavorAssets']
|
||||||
|
entry_id = info['id']
|
||||||
|
else:
|
||||||
|
raise ExtractorError('Invalid URL', expected=True)
|
||||||
|
|
||||||
source_url = smuggled_data.get('source_url')
|
source_url = smuggled_data.get('source_url')
|
||||||
if source_url:
|
if source_url:
|
||||||
|
|
|
@ -12,6 +12,7 @@ from ..utils import (
|
||||||
smuggle_url,
|
smuggle_url,
|
||||||
std_headers,
|
std_headers,
|
||||||
urlencode_postdata,
|
urlencode_postdata,
|
||||||
|
update_url_query,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,6 +27,7 @@ class SafariBaseIE(InfoExtractor):
|
||||||
LOGGED_IN = False
|
LOGGED_IN = False
|
||||||
|
|
||||||
def _real_initialize(self):
|
def _real_initialize(self):
|
||||||
|
return
|
||||||
# We only need to log in once for courses or individual videos
|
# We only need to log in once for courses or individual videos
|
||||||
if not self.LOGGED_IN:
|
if not self.LOGGED_IN:
|
||||||
self._login()
|
self._login()
|
||||||
|
@ -86,13 +88,15 @@ class SafariIE(SafariBaseIE):
|
||||||
|
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
'url': 'https://www.safaribooksonline.com/library/view/hadoop-fundamentals-livelessons/9780133392838/part00.html',
|
'url': 'https://www.safaribooksonline.com/library/view/hadoop-fundamentals-livelessons/9780133392838/part00.html',
|
||||||
'md5': '5b0c4cc1b3c1ba15dda7344085aa5592',
|
'md5': 'dcc5a425e79f2564148652616af1f2a3',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '2842601850001',
|
'id': '0_qbqx90ic',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Introduction',
|
'title': 'Introduction to Hadoop Fundamentals LiveLessons',
|
||||||
|
'timestamp': 1437758058,
|
||||||
|
'upload_date': '20150724',
|
||||||
|
'uploader_id': 'stork',
|
||||||
},
|
},
|
||||||
'skip': 'Requires safaribooksonline account credentials',
|
|
||||||
}, {
|
}, {
|
||||||
'url': 'https://www.safaribooksonline.com/api/v1/book/9780133392838/chapter/part00.html',
|
'url': 'https://www.safaribooksonline.com/api/v1/book/9780133392838/chapter/part00.html',
|
||||||
'only_matching': True,
|
'only_matching': True,
|
||||||
|
@ -107,15 +111,16 @@ class SafariIE(SafariBaseIE):
|
||||||
course_id = mobj.group('course_id')
|
course_id = mobj.group('course_id')
|
||||||
part = mobj.group('part')
|
part = mobj.group('part')
|
||||||
|
|
||||||
webpage = self._download_webpage(
|
webpage = self._download_webpage(url, '%s/%s' % (course_id, part))
|
||||||
'%s/%s/chapter-content/%s.html' % (self._API_BASE, course_id, part),
|
reference_id = self._search_regex(r'data-reference-id="([^"]+)"', webpage, 'kaltura reference id')
|
||||||
part)
|
partner_id = self._search_regex(r'data-partner-id="([^"]+)"', webpage, 'kaltura widget id')
|
||||||
|
ui_id = self._search_regex(r'data-ui-id="([^"]+)"', webpage, 'kaltura uiconf id')
|
||||||
|
|
||||||
bc_url = BrightcoveLegacyIE._extract_brightcove_url(webpage)
|
return self.url_result(update_url_query('https://cdnapisec.kaltura.com/html5/html5lib/v2.37.1/mwEmbedFrame.php', {
|
||||||
if not bc_url:
|
'wid': '_%s' % partner_id,
|
||||||
raise ExtractorError('Could not extract Brightcove URL from %s' % url, expected=True)
|
'uiconf_id': ui_id,
|
||||||
|
'flashvars[referenceId]': reference_id,
|
||||||
return self.url_result(smuggle_url(bc_url, {'Referer': url}), 'BrightcoveLegacy')
|
}), 'Kaltura')
|
||||||
|
|
||||||
|
|
||||||
class SafariCourseIE(SafariBaseIE):
|
class SafariCourseIE(SafariBaseIE):
|
||||||
|
|
Loading…
Reference in New Issue