]> git.bitcoin.ninja Git - youtube-dl/commitdiff
[funimation] Improve login
authorSergey M․ <dstftw@gmail.com>
Sun, 13 Dec 2015 01:17:42 +0000 (07:17 +0600)
committerSergey M․ <dstftw@gmail.com>
Sun, 13 Dec 2015 01:17:42 +0000 (07:17 +0600)
youtube_dl/extractor/funimation.py

index 8a65343c59c6a84caec67865ea255cf3d11e8e3f..d1a95d87f14ab04b893b8cf239c2986ca0b602a4 100644 (file)
@@ -1,8 +1,6 @@
 # coding: utf-8
 from __future__ import unicode_literals
 
-import re
-
 from .common import InfoExtractor
 from ..utils import (
     clean_html,
@@ -18,6 +16,8 @@ from ..utils import (
 class FunimationIE(InfoExtractor):
     _VALID_URL = r'https?://(?:www\.)?funimation\.com/shows/[^/]+/videos/(?:official|promotional)/(?P<id>[^/?#&]+)'
 
+    _NETRC_MACHINE = 'funimation'
+
     _TESTS = [{
         'url': 'http://www.funimation.com/shows/air/videos/official/breeze',
         'info_dict': {
@@ -62,10 +62,16 @@ class FunimationIE(InfoExtractor):
             'User-Agent': 'Mozilla/5.0 (Windows NT 5.2; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0',
             'Content-Type': 'application/x-www-form-urlencoded'
         })
-        login = self._download_webpage(
+        login_page = self._download_webpage(
             login_request, None, 'Logging in as %s' % username)
-        if re.search(r'<meta property="og:url" content="http://www.funimation.com/login"/>', login) is not None:
-            raise ExtractorError('Unable to login, wrong username or password.', expected=True)
+        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):
         self._login()