X-Git-Url: https://git.rapsys.eu/youtubedl/blobdiff_plain/a6abd8dc822fb70852437ab5a77ced5f633739f8..a4e5dfe95bc8baaa961161b75ac623ce5831abf9:/youtube_dl/extractor/twitch.py?ds=sidebyside
diff --git a/youtube_dl/extractor/twitch.py b/youtube_dl/extractor/twitch.py
index 87290d0..0500e33 100644
--- a/youtube_dl/extractor/twitch.py
+++ b/youtube_dl/extractor/twitch.py
@@ -4,25 +4,42 @@ from __future__ import unicode_literals
import itertools
import re
import random
+import json
from .common import InfoExtractor
from ..compat import (
+ compat_kwargs,
+ compat_parse_qs,
compat_str,
- compat_urllib_parse,
- compat_urllib_request,
+ compat_urllib_parse_urlencode,
+ compat_urllib_parse_urlparse,
)
from ..utils import (
+ clean_html,
ExtractorError,
+ float_or_none,
+ int_or_none,
+ orderedSet,
+ parse_duration,
parse_iso8601,
+ qualities,
+ try_get,
+ unified_timestamp,
+ update_url_query,
+ url_or_none,
+ urljoin,
)
class TwitchBaseIE(InfoExtractor):
- _VALID_URL_BASE = r'https?://(?:www\.)?twitch\.tv'
+ _VALID_URL_BASE = r'https?://(?:(?:www|go|m)\.)?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_FORM_URL = 'https://www.twitch.tv/login'
+ _LOGIN_POST_URL = 'https://passport.twitch.tv/login'
+ _CLIENT_ID = 'kimne78kx3ncx6brgo4mv6wki5h1ko'
+ _NETRC_MACHINE = 'twitch'
def _handle_error(self, response):
if not isinstance(response, dict):
@@ -33,8 +50,13 @@ 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'):
- response = super(TwitchBaseIE, self)._download_json(url, video_id, note)
+ def _call_api(self, path, item_id, *args, **kwargs):
+ headers = kwargs.get('headers', {}).copy()
+ headers['Client-ID'] = self._CLIENT_ID
+ kwargs['headers'] = headers
+ response = self._download_json(
+ '%s/%s' % (self._API_BASE, path), item_id,
+ *args, **compat_kwargs(kwargs))
self._handle_error(response)
return response
@@ -42,51 +64,97 @@ class TwitchBaseIE(InfoExtractor):
self._login()
def _login(self):
- (username, password) = self._get_login_info()
+ username, password = self._get_login_info()
if username is None:
return
- login_page = self._download_webpage(
- 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)
+ page_url = urlh.geturl()
+ post_url = self._search_regex(
+ r'