aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZack Fernandes <zack@ohnoco.com>2017-12-31 13:55:35 -0800
committerSergey M․ <dstftw@gmail.com>2018-05-26 19:56:01 +0700
commitc678192af3f004205b18a16b7418cbd937c1b584 (patch)
tree09c7996c22b7f79d8e67d89af983a3f520367139
parent0934c9d4faadbfd2b076d13c7e24f4bf039cdc79 (diff)
downloadyoutube-dl-c678192af3f004205b18a16b7418cbd937c1b584.tar.xz
[tumblr] Add support for authentication
-rw-r--r--youtube_dl/extractor/tumblr.py34
1 files changed, 33 insertions, 1 deletions
diff --git a/youtube_dl/extractor/tumblr.py b/youtube_dl/extractor/tumblr.py
index 786143525..58ac66755 100644
--- a/youtube_dl/extractor/tumblr.py
+++ b/youtube_dl/extractor/tumblr.py
@@ -4,11 +4,18 @@ from __future__ import unicode_literals
import re
from .common import InfoExtractor
-from ..utils import int_or_none
+from ..utils import (
+ ExtractorError,
+ int_or_none,
+ sanitized_Request,
+ urlencode_postdata
+)
class TumblrIE(InfoExtractor):
_VALID_URL = r'https?://(?P<blog_name>[^/?#&]+)\.tumblr\.com/(?:post|video)/(?P<id>[0-9]+)(?:$|[/?#])'
+ _NETRC_MACHINE = 'tumblr'
+ _LOGIN_URL = 'https://www.tumblr.com/login'
_TESTS = [{
'url': 'http://tatianamaslanydaily.tumblr.com/post/54196191430/orphan-black-dvd-extra-behind-the-scenes',
'md5': '479bb068e5b16462f5176a6828829767',
@@ -97,6 +104,31 @@ class TumblrIE(InfoExtractor):
'add_ie': ['Instagram'],
}]
+ def _real_initialize(self):
+ self._login()
+
+ def _login(self):
+ (username, password) = self._get_login_info()
+ if username is None:
+ return
+ self.report_login()
+ webpage = self._download_webpage(self._LOGIN_URL, None, False)
+ form = self._hidden_inputs(webpage)
+ form.update({
+ 'user[email]': username,
+ 'user[password]': password
+ })
+ login_response = self._download_webpage(
+ sanitized_Request(self._LOGIN_URL, urlencode_postdata(form), {
+ 'Content-Type': 'application/x-www-form-urlencoded',
+ 'Referer': self._LOGIN_URL
+ }), None, False, 'Wrong login info')
+
+ # Check the login response from Tumblr for an error message and fail the extraction if we find one.
+ login_errors = self._search_regex(r'Tumblr\.RegistrationForm\.errors\s*=\s*\[[\"|\'](.+)[\"|\']\]', login_response, 'login errors', False)
+ if login_errors:
+ raise ExtractorError('Error logging in: %s' % login_errors, expected=True)
+
def _real_extract(self, url):
m_url = re.match(self._VALID_URL, url)
video_id = m_url.group('id')