From bf2833ba7c90dc26decdaa3ae551d7f126a1e4d5 Mon Sep 17 00:00:00 2001 From: Tyler Romeo Date: Tue, 13 Sep 2016 16:26:48 -0400 Subject: [PATCH] [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 --- youtube_dl/extractor/funimation.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/youtube_dl/extractor/funimation.py b/youtube_dl/extractor/funimation.py index 0ad0d9b6a..e4f0d8bc3 100644 --- a/youtube_dl/extractor/funimation.py +++ b/youtube_dl/extractor/funimation.py @@ -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)]+id=["\']errorMessages["\'][^>]*>(.+?)', 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):