1
0
mirror of https://github.com/l1ving/youtube-dl synced 2025-02-03 06:42:52 +08:00

[Tumblr] Add login support

This commit is contained in:
Zack Fernandes 2017-12-31 13:55:35 -08:00
parent 04cf1a191a
commit 11b9ebc2ed

View File

@ -4,11 +4,19 @@ 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_REQUIRED = False
_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 +105,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
})
post_data = urlencode_postdata(form)
login_request = sanitized_Request(self._LOGIN_URL, post_data)
login_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
login_request.add_header('Referer', self._LOGIN_URL)
login_response = self._download_webpage(login_request, 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 = \[(.*)\]', login_response, 'login errors', False, False)
if login_errors:
raise ExtractorError("Error logging in: %s" % login_errors)
def _real_extract(self, url):
m_url = re.match(self._VALID_URL, url)
video_id = m_url.group('id')