# coding: utf-8 from __future__ import unicode_literals import collections import itertools import json import random import re from .common import InfoExtractor from ..compat import ( compat_parse_qs, compat_str, compat_urlparse, compat_urllib_parse_urlencode, compat_urllib_parse_urlparse, ) from ..utils import ( clean_html, ExtractorError, float_or_none, int_or_none, 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|go|m)\.)?twitch\.tv' _API_BASE = 'https://api.twitch.tv' _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 _real_initialize(self): self._login() def _login(self): username, password = self._get_login_info() if username is None: return 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'