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

[Tumblr] Cleanup login support code after code review

- Removed unused _LOGIN_REQUIRED constant
- Moved data and headers into login_response _download_webpage call
- Made login_errors RegEx a little more versatile: relaxed whitespace,
support single and double quotes in the array, don’t match an empty
string.
- Use single quotes and add expected to ExtractorError
This commit is contained in:
Zack Fernandes 2018-01-06 14:33:05 -08:00
parent 11b9ebc2ed
commit b038ec285a

View File

@ -15,7 +15,6 @@ from ..utils import (
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',
@ -119,16 +118,16 @@ class TumblrIE(InfoExtractor):
'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')
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 = \[(.*)\]', login_response, 'login errors', False, False)
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)
raise ExtractorError('Error logging in: %s' % login_errors, expected=True)
def _real_extract(self, url):
m_url = re.match(self._VALID_URL, url)