summary refs log tree commit diff
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2015-01-15 21:43:35 +0600
committerSergey M․ <dstftw@gmail.com>2015-01-15 21:43:35 +0600
commitc8dfe360eb642b2957116814bfdef67686ab000d (patch)
tree3b06a20a813ec6e75acccc44931cba1679c84b7b
parent4cfaf85c65d1b00ee5b198acb44f1ac65366e0d8 (diff)
downloadyoutube-dl-c8dfe360eb642b2957116814bfdef67686ab000d.tar.gz
youtube-dl-c8dfe360eb642b2957116814bfdef67686ab000d.tar.xz
youtube-dl-c8dfe360eb642b2957116814bfdef67686ab000d.zip
[atresplayer] Add authentication support (Closes #4700)
-rw-r--r--youtube_dl/extractor/atresplayer.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/youtube_dl/extractor/atresplayer.py b/youtube_dl/extractor/atresplayer.py
index 72e83bfc2..5db1941b3 100644
--- a/youtube_dl/extractor/atresplayer.py
+++ b/youtube_dl/extractor/atresplayer.py
@@ -4,9 +4,12 @@ import time
 import hmac
 
 from .common import InfoExtractor
-from ..utils import (
+from ..compat import (
     compat_str,
+    compat_urllib_parse,
     compat_urllib_request,
+)
+from ..utils import (
     int_or_none,
     float_or_none,
     xpath_text,
@@ -44,6 +47,33 @@ class AtresPlayerIE(InfoExtractor):
     _PLAYER_URL_TEMPLATE = 'https://servicios.atresplayer.com/episode/getplayer.json?episodePk=%s'
     _EPISODE_URL_TEMPLATE = 'http://www.atresplayer.com/episodexml/%s'
 
+    _LOGIN_URL = 'https://servicios.atresplayer.com/j_spring_security_check'
+
+    def _real_initialize(self):
+        self._login()
+
+    def _login(self):
+        (username, password) = self._get_login_info()
+        if username is None:
+            return
+
+        login_form = {
+            'j_username': username,
+            'j_password': password,
+        }
+
+        request = compat_urllib_request.Request(
+            self._LOGIN_URL, compat_urllib_parse.urlencode(login_form).encode('utf-8'))
+        request.add_header('Content-Type', 'application/x-www-form-urlencoded')
+        response = self._download_webpage(
+            request, None, 'Logging in as %s' % username)
+
+        error = self._html_search_regex(
+            r'(?s)<ul class="list_error">(.+?)</ul>', response, 'error', default=None)
+        if error:
+            raise ExtractorError(
+                'Unable to login: %s' % error, expected=True)
+
     def _real_extract(self, url):
         video_id = self._match_id(url)