1
0
Fork 0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-11-23 02:32:16 +00:00

[udemy] Fix authentication (Closes #6224)

This commit is contained in:
Sergey M․ 2015-07-14 22:39:41 +06:00
parent cf61d96df0
commit dcd4d95c8e

View file

@ -15,7 +15,8 @@ from ..utils import (
class UdemyIE(InfoExtractor): class UdemyIE(InfoExtractor):
IE_NAME = 'udemy' IE_NAME = 'udemy'
_VALID_URL = r'https?://www\.udemy\.com/(?:[^#]+#/lecture/|lecture/view/?\?lectureId=)(?P<id>\d+)' _VALID_URL = r'https?://www\.udemy\.com/(?:[^#]+#/lecture/|lecture/view/?\?lectureId=)(?P<id>\d+)'
_LOGIN_URL = 'https://www.udemy.com/join/login-submit/' _LOGIN_URL = 'https://www.udemy.com/join/login-popup/?displayType=ajax&showSkipButton=1'
_ORIGIN_URL = 'https://www.udemy.com'
_NETRC_MACHINE = 'udemy' _NETRC_MACHINE = 'udemy'
_TESTS = [{ _TESTS = [{
@ -74,29 +75,34 @@ class UdemyIE(InfoExtractor):
expected=True) expected=True)
login_popup = self._download_webpage( login_popup = self._download_webpage(
'https://www.udemy.com/join/login-popup?displayType=ajax&showSkipButton=1', None, self._LOGIN_URL, None, 'Downloading login popup')
'Downloading login popup')
if login_popup == '<div class="run-command close-popup redirect" data-url="https://www.udemy.com/"></div>': if login_popup == '<div class="run-command close-popup redirect" data-url="https://www.udemy.com/"></div>':
return return
csrf = self._html_search_regex( login_form = self._form_hidden_inputs('login-form', login_popup)
r'<input type="hidden" name="csrf" value="(.+?)"',
login_popup, 'csrf token')
login_form = { login_form.update({
'email': username,
'password': password,
'csrf': csrf,
'displayType': 'json', 'displayType': 'json',
'isSubmitted': '1', 'email': username.encode('utf-8'),
} 'password': password.encode('utf-8'),
})
request = compat_urllib_request.Request( request = compat_urllib_request.Request(
self._LOGIN_URL, compat_urllib_parse.urlencode(login_form).encode('utf-8')) self._LOGIN_URL, compat_urllib_parse.urlencode(login_form).encode('utf-8'))
response = self._download_json( request.add_header('Referer', self._ORIGIN_URL)
request.add_header('Origin', self._ORIGIN_URL)
response = self._download_webpage(
request, None, 'Logging in as %s' % username) request, None, 'Logging in as %s' % username)
if 'returnUrl' not in response: if all(logout_pattern not in response
for logout_pattern in ['href="https://www.udemy.com/user/logout/', '>Logout<']):
error = self._html_search_regex(
r'(?s)<div[^>]+class="form-errors[^"]*">(.+?)</div>',
response, 'error message', default=None)
if error:
raise ExtractorError('Unable to login: %s' % error, expected=True)
raise ExtractorError('Unable to log in') raise ExtractorError('Unable to log in')
def _real_extract(self, url): def _real_extract(self, url):