[twitch] Modernize

This commit is contained in:
Sergey M․ 2016-08-21 21:28:02 +07:00
parent 92d4cfa358
commit b1e676fde8
No known key found for this signature in database
GPG key ID: 2C393E0F18A9236D

View file

@ -20,7 +20,6 @@
orderedSet, orderedSet,
parse_duration, parse_duration,
parse_iso8601, parse_iso8601,
sanitized_Request,
urlencode_postdata, urlencode_postdata,
) )
@ -50,8 +49,8 @@ def _download_json(self, url, video_id, note='Downloading JSON metadata'):
for cookie in self._downloader.cookiejar: for cookie in self._downloader.cookiejar:
if cookie.name == 'api_token': if cookie.name == 'api_token':
headers['Twitch-Api-Token'] = cookie.value headers['Twitch-Api-Token'] = cookie.value
request = sanitized_Request(url, headers=headers) response = super(TwitchBaseIE, self)._download_json(
response = super(TwitchBaseIE, self)._download_json(request, video_id, note) url, video_id, note, headers=headers)
self._handle_error(response) self._handle_error(response)
return response return response
@ -82,11 +81,10 @@ def _login(self):
if not post_url.startswith('http'): if not post_url.startswith('http'):
post_url = compat_urlparse.urljoin(redirect_url, post_url) post_url = compat_urlparse.urljoin(redirect_url, post_url)
request = sanitized_Request(
post_url, urlencode_postdata(login_form))
request.add_header('Referer', redirect_url)
response = self._download_webpage( response = self._download_webpage(
request, None, 'Logging in as %s' % username) post_url, None, 'Logging in as %s' % username,
data=urlencode_postdata(login_form),
headers={'Referer': redirect_url})
error_message = self._search_regex( error_message = self._search_regex(
r'<div[^>]+class="subwindow_notice"[^>]*>([^<]+)</div>', r'<div[^>]+class="subwindow_notice"[^>]*>([^<]+)</div>',