1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-02 17:22:31 +01:00

[safari] Respect kaltura session (Closes #7491)

This commit is contained in:
Sergey M․ 2016-03-13 02:03:07 +06:00
parent 9dce3c095b
commit 73cbd709f9

View File

@ -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 @@ def _real_initialize(self):
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 @@ def _real_extract(self, url):
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 @@ def _real_extract(self, url):
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: