[safari] Respect kaltura session (Closes #7491)

pull/8/head
Sergey M․ 9 years ago
parent 9dce3c095b
commit 73cbd709f9

@ -21,13 +21,12 @@ class SafariBaseIE(InfoExtractor):
_SUCCESSFUL_LOGIN_REGEX = r'<a href="/accounts/logout/"[^>]*>Sign Out</a>' _SUCCESSFUL_LOGIN_REGEX = r'<a href="/accounts/logout/"[^>]*>Sign Out</a>'
_NETRC_MACHINE = 'safari' _NETRC_MACHINE = 'safari'
_API_BASE = 'https://www.safaribooksonline.com/api/v1/book' _API_BASE = 'https://www.safaribooksonline.com/api/v1'
_API_FORMAT = 'json' _API_FORMAT = 'json'
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()
@ -36,7 +35,7 @@ class SafariBaseIE(InfoExtractor):
def _login(self): def _login(self):
(username, password) = self._get_login_info() (username, password) = self._get_login_info()
if username is None: if username is None:
self.raise_login_required('safaribooksonline.com account is required') return
headers = std_headers.copy() headers = std_headers.copy()
if 'Referer' not in headers: if 'Referer' not in headers:
@ -116,11 +115,25 @@ class SafariIE(SafariBaseIE):
partner_id = self._search_regex(r'data-partner-id="([^"]+)"', webpage, 'kaltura widget id') 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') ui_id = self._search_regex(r'data-ui-id="([^"]+)"', webpage, 'kaltura uiconf id')
return self.url_result(update_url_query('https://cdnapisec.kaltura.com/html5/html5lib/v2.37.1/mwEmbedFrame.php', { query = {
'wid': '_%s' % partner_id, 'wid': '_%s' % partner_id,
'uiconf_id': ui_id, 'uiconf_id': ui_id,
'flashvars[referenceId]': reference_id, 'flashvars[referenceId]': reference_id,
}), 'Kaltura') }
if self.LOGGED_IN:
kaltura_session = self._download_json(
'%s/player/kaltura_session/?reference_id=%s' % (self._API_BASE, reference_id),
course_id, 'Downloading kaltura session JSON',
'Unable to download kaltura session JSON', fatal=False)
if kaltura_session:
session = kaltura_session.get('session')
if session:
query['flashvars[ks]'] = session
return self.url_result(update_url_query(
'https://cdnapisec.kaltura.com/html5/html5lib/v2.37.1/mwEmbedFrame.php', query),
'Kaltura')
class SafariCourseIE(SafariBaseIE): class SafariCourseIE(SafariBaseIE):
@ -146,7 +159,7 @@ class SafariCourseIE(SafariBaseIE):
course_id = self._match_id(url) course_id = self._match_id(url)
course_json = self._download_json( course_json = self._download_json(
'%s/%s/?override_format=%s' % (self._API_BASE, course_id, self._API_FORMAT), '%s/book/%s/?override_format=%s' % (self._API_BASE, course_id, self._API_FORMAT),
course_id, 'Downloading course JSON') course_id, 'Downloading course JSON')
if 'chapters' not in course_json: if 'chapters' not in course_json:

Loading…
Cancel
Save