X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=inline;f=youtube_dl%2Fextractor%2Ftwitch.py;h=f7b98e1908c9c011e8a7f091d9f636667dc63af7;hb=f0c96af9cb0edc69f9ba73d39e6e191994e31256;hp=73ce335b7f0a5b5790f8dd65e3ac170e9791b7d8;hpb=a56c1e38c77bdeae38143b057b1698a5ffb2b914;p=youtube-dl diff --git a/youtube_dl/extractor/twitch.py b/youtube_dl/extractor/twitch.py index 73ce335b7..f7b98e190 100644 --- a/youtube_dl/extractor/twitch.py +++ b/youtube_dl/extractor/twitch.py @@ -7,13 +7,20 @@ import random from .common import InfoExtractor from ..compat import ( + compat_parse_qs, compat_str, - compat_urllib_parse, - compat_urllib_request, + compat_urllib_parse_urlencode, + compat_urllib_parse_urlparse, + compat_urlparse, ) from ..utils import ( ExtractorError, + int_or_none, + orderedSet, + parse_duration, parse_iso8601, + sanitized_Request, + urlencode_postdata, ) @@ -22,8 +29,7 @@ class TwitchBaseIE(InfoExtractor): _API_BASE = 'https://api.twitch.tv' _USHER_BASE = 'http://usher.twitch.tv' - _LOGIN_URL = 'https://secure.twitch.tv/login' - _LOGIN_POST_URL = 'https://passport.twitch.tv/authorize' + _LOGIN_URL = 'http://www.twitch.tv/login' _NETRC_MACHINE = 'twitch' def _handle_error(self, response): @@ -43,7 +49,7 @@ class TwitchBaseIE(InfoExtractor): for cookie in self._downloader.cookiejar: if cookie.name == 'api_token': headers['Twitch-Api-Token'] = cookie.value - request = compat_urllib_request.Request(url, headers=headers) + request = sanitized_Request(url, headers=headers) response = super(TwitchBaseIE, self)._download_json(request, video_id, note) self._handle_error(response) return response @@ -56,19 +62,28 @@ class TwitchBaseIE(InfoExtractor): if username is None: return - login_page = self._download_webpage( + login_page, handle = self._download_webpage_handle( self._LOGIN_URL, None, 'Downloading login page') login_form = self._hidden_inputs(login_page) login_form.update({ - 'login': username.encode('utf-8'), - 'password': password.encode('utf-8'), + 'username': username, + 'password': password, }) - request = compat_urllib_request.Request( - self._LOGIN_POST_URL, compat_urllib_parse.urlencode(login_form).encode('utf-8')) - request.add_header('Referer', self._LOGIN_URL) + redirect_url = handle.geturl() + + post_url = self._search_regex( + r'