[funimation] establish session before logging in

Added an initial HTTP GET request with the login URL before attempting
to log in. This allows Funimation to set any session cookies it
requires. This request is necessary for Funimation to render the login
page or to accept login requests.

Fixes #10639
This commit is contained in:
Tyler Romeo 2016-09-13 16:26:48 -04:00
parent 8414c2da31
commit bf2833ba7c
No known key found for this signature in database
GPG Key ID: 405D34A7C86B42DF

View File

@ -87,26 +87,43 @@ class FunimationIE(InfoExtractor):
(username, password) = self._get_login_info()
if username is None:
return
data = urlencode_postdata({
'email_field': username,
'password_field': password,
})
user_agent = self._extract_cloudflare_session_ua(self._LOGIN_URL)
if not user_agent:
user_agent = 'Mozilla/5.0 (Windows NT 5.2; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0'
login_request = sanitized_Request(self._LOGIN_URL, data, headers={
headers = {
'User-Agent': user_agent,
'Content-Type': 'application/x-www-form-urlencoded'
})
}
# Request home page to establish initial session and cookies
self._download_webpage(
self._LOGIN_URL, None,
note='Starting session with Funimation',
headers=headers)
# Log in
login_page = self._download_webpage(
login_request, None, 'Logging in as %s' % username)
self._LOGIN_URL, None,
data=data,
note='Logging in as %s' % username,
headers=headers)
# Check for successful login
if any(p in login_page for p in ('funimation.com/logout', '>Log Out<')):
return
error = self._html_search_regex(
r'(?s)<div[^>]+id=["\']errorMessages["\'][^>]*>(.+?)</div>',
login_page, 'error messages', default=None)
if error:
raise ExtractorError('Unable to login: %s' % error, expected=True)
raise ExtractorError('Unable to log in')
def _real_initialize(self):