X-Git-Url: https://git.rapsys.eu/youtubedl/blobdiff_plain/d4ff594119bc679aa175947eb59a97bee8f966f4..27375a0e586f091b3366c9963a15304fee569a05:/youtube_dl/extractor/twitch.py diff --git a/youtube_dl/extractor/twitch.py b/youtube_dl/extractor/twitch.py index 87290d0..1981b4d 100644 --- a/youtube_dl/extractor/twitch.py +++ b/youtube_dl/extractor/twitch.py @@ -7,22 +7,34 @@ 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, ) from ..utils import ( + clean_html, ExtractorError, + int_or_none, + js_to_json, + orderedSet, + parse_duration, parse_iso8601, + update_url_query, + urlencode_postdata, + urljoin, ) class TwitchBaseIE(InfoExtractor): - _VALID_URL_BASE = r'https?://(?:www\.)?twitch\.tv' + _VALID_URL_BASE = r'https?://(?:(?:www|go)\.)?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 = 'https://www.twitch.tv/login' + _CLIENT_ID = 'jzkbprff40iqj646a697cyrvl0zt2m6' + _NETRC_MACHINE = 'twitch' def _handle_error(self, response): if not isinstance(response, dict): @@ -33,8 +45,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'): - response = super(TwitchBaseIE, self)._download_json(url, 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 @@ -46,47 +60,88 @@ 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) + + def login_step(page, urlh, note, data): + form = self._hidden_inputs(page) + form.update(data) + + page_url = urlh.geturl() + post_url = self._search_regex( + r'