X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;ds=inline;f=youtube_dl%2Fextractor%2Ftwitch.py;h=46c2cfe7b251beb65422238a2158b48ad0a1d795;hb=6eb5503b12286ef9813ee22e95622f09dab2ebe5;hp=8af1361473ac338d45c0bc0f512953c684b9681b;hpb=938c3f65b6c1c1f5b8f7eb731a3eef00a06b6128;p=youtube-dl.git
diff --git a/youtube_dl/extractor/twitch.py b/youtube_dl/extractor/twitch.py
index 8af136147..46c2cfe7b 100644
--- a/youtube_dl/extractor/twitch.py
+++ b/youtube_dl/extractor/twitch.py
@@ -7,13 +7,22 @@ import random
from .common import InfoExtractor
from ..compat import (
+ compat_HTTPError,
+ compat_parse_qs,
compat_str,
- compat_urllib_parse,
- compat_urllib_request,
+ compat_urllib_parse_urlencode,
+ compat_urllib_parse_urlparse,
+ compat_urlparse,
)
from ..utils import (
+ clean_html,
ExtractorError,
+ int_or_none,
+ js_to_json,
+ orderedSet,
+ parse_duration,
parse_iso8601,
+ urlencode_postdata,
)
@@ -21,8 +30,9 @@ class TwitchBaseIE(InfoExtractor):
_VALID_URL_BASE = r'https?://(?:www\.)?twitch\.tv'
_API_BASE = 'https://api.twitch.tv'
- _USHER_BASE = 'http://usher.twitch.tv'
- _LOGIN_URL = 'https://secure.twitch.tv/user/login'
+ _USHER_BASE = 'https://usher.ttvnw.net'
+ _LOGIN_URL = 'http://www.twitch.tv/login'
+ _CLIENT_ID = 'jzkbprff40iqj646a697cyrvl0zt2m6'
_NETRC_MACHINE = 'twitch'
def _handle_error(self, response):
@@ -34,16 +44,10 @@ class TwitchBaseIE(InfoExtractor):
'%s returned error: %s - %s' % (self.IE_NAME, error, response.get('message')),
expected=True)
- def _download_json(self, url, video_id, note='Downloading JSON metadata'):
- headers = {
- 'Referer': 'http://api.twitch.tv/crossdomain/receiver.html?v=2',
- 'X-Requested-With': 'XMLHttpRequest',
- }
- 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)
- response = super(TwitchBaseIE, self)._download_json(request, video_id, note)
+ def _call_api(self, path, item_id, note):
+ response = self._download_json(
+ '%s/%s' % (self._API_BASE, path), item_id, note,
+ headers={'Client-ID': self._CLIENT_ID})
self._handle_error(response)
return response
@@ -55,47 +59,71 @@ class TwitchBaseIE(InfoExtractor):
if username is None:
return
- login_page = self._download_webpage(
+ def fail(message):
+ raise ExtractorError(
+ 'Unable to login. Twitch said: %s' % message, expected=True)
+
+ login_page, handle = self._download_webpage_handle(
self._LOGIN_URL, None, 'Downloading login page')
- authenticity_token = self._search_regex(
- r']*>(?P[^<]+)", response)
- if m:
- raise ExtractorError(
- 'Unable to login: %s' % m.group('msg').strip(), expected=True)
+ login_form.update({
+ 'username': username,
+ 'password': password,
+ })
+
+ redirect_url = handle.geturl()
+
+ post_url = self._search_regex(
+ r'