mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-16 01:25:06 +00:00
[twitch] Renew authentication
This commit is contained in:
parent
e3f6b56909
commit
efe470e261
1 changed files with 26 additions and 12 deletions
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..compat import (
|
from ..compat import (
|
||||||
|
compat_HTTPError,
|
||||||
compat_parse_qs,
|
compat_parse_qs,
|
||||||
compat_str,
|
compat_str,
|
||||||
compat_urllib_parse_urlencode,
|
compat_urllib_parse_urlencode,
|
||||||
|
@ -14,6 +15,7 @@
|
||||||
compat_urlparse,
|
compat_urlparse,
|
||||||
)
|
)
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
|
clean_html,
|
||||||
ExtractorError,
|
ExtractorError,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
js_to_json,
|
js_to_json,
|
||||||
|
@ -62,9 +64,17 @@ def _login(self):
|
||||||
if username is None:
|
if username is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def fail(message):
|
||||||
|
raise ExtractorError(
|
||||||
|
'Unable to login. Twitch said: %s' % message, expected=True)
|
||||||
|
|
||||||
login_page, handle = self._download_webpage_handle(
|
login_page, handle = self._download_webpage_handle(
|
||||||
self._LOGIN_URL, None, 'Downloading login page')
|
self._LOGIN_URL, None, 'Downloading login page')
|
||||||
|
|
||||||
|
# Some TOR nodes and public proxies are blocked completely
|
||||||
|
if 'blacklist_message' in login_page:
|
||||||
|
fail(clean_html(login_page))
|
||||||
|
|
||||||
login_form = self._hidden_inputs(login_page)
|
login_form = self._hidden_inputs(login_page)
|
||||||
|
|
||||||
login_form.update({
|
login_form.update({
|
||||||
|
@ -81,20 +91,24 @@ def _login(self):
|
||||||
if not post_url.startswith('http'):
|
if not post_url.startswith('http'):
|
||||||
post_url = compat_urlparse.urljoin(redirect_url, post_url)
|
post_url = compat_urlparse.urljoin(redirect_url, post_url)
|
||||||
|
|
||||||
response = self._download_webpage(
|
headers = {'Referer': redirect_url}
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = self._download_json(
|
||||||
post_url, None, 'Logging in as %s' % username,
|
post_url, None, 'Logging in as %s' % username,
|
||||||
data=urlencode_postdata(login_form),
|
data=urlencode_postdata(login_form),
|
||||||
headers={'Referer': redirect_url})
|
headers=headers)
|
||||||
|
except ExtractorError as e:
|
||||||
|
if isinstance(e.cause, compat_HTTPError) and e.cause.code == 400:
|
||||||
|
response = self._parse_json(
|
||||||
|
e.cause.read().decode('utf-8'), None)
|
||||||
|
fail(response['message'])
|
||||||
|
raise
|
||||||
|
|
||||||
error_message = self._search_regex(
|
if response.get('redirect'):
|
||||||
r'<div[^>]+class="subwindow_notice"[^>]*>([^<]+)</div>',
|
self._download_webpage(
|
||||||
response, 'error message', default=None)
|
response['redirect'], None, 'Downloading login redirect page',
|
||||||
if error_message:
|
headers=headers)
|
||||||
raise ExtractorError(
|
|
||||||
'Unable to login. Twitch said: %s' % error_message, expected=True)
|
|
||||||
|
|
||||||
if '>Reset your password<' in response:
|
|
||||||
self.report_warning('Twitch asks you to reset your password, go to https://secure.twitch.tv/reset/submit')
|
|
||||||
|
|
||||||
def _prefer_source(self, formats):
|
def _prefer_source(self, formats):
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue