mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-26 02:55:17 +00:00
[twitch] Use better naming and simplify (closes #11974)
This commit is contained in:
parent
c64c03be35
commit
5316566edc
1 changed files with 12 additions and 19 deletions
|
@ -64,7 +64,7 @@ def fail(message):
|
||||||
raise ExtractorError(
|
raise ExtractorError(
|
||||||
'Unable to login. Twitch said: %s' % message, expected=True)
|
'Unable to login. Twitch said: %s' % message, expected=True)
|
||||||
|
|
||||||
def post_login_form(page, urlh, note, data):
|
def login_step(page, urlh, note, data):
|
||||||
form = self._hidden_inputs(page)
|
form = self._hidden_inputs(page)
|
||||||
form.update(data)
|
form.update(data)
|
||||||
|
|
||||||
|
@ -88,11 +88,10 @@ def post_login_form(page, urlh, note, data):
|
||||||
fail(response['message'])
|
fail(response['message'])
|
||||||
raise
|
raise
|
||||||
|
|
||||||
if response.get('redirect'):
|
redirect_url = urljoin(post_url, response['redirect'])
|
||||||
redirect_url = urljoin(post_url, response['redirect'])
|
return self._download_webpage_handle(
|
||||||
return self._download_webpage_handle(
|
redirect_url, None, 'Downloading login redirect page',
|
||||||
redirect_url, None, 'Downloading login redirect page',
|
headers=headers)
|
||||||
headers=headers)
|
|
||||||
|
|
||||||
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')
|
||||||
|
@ -101,25 +100,19 @@ def post_login_form(page, urlh, note, data):
|
||||||
if 'blacklist_message' in login_page:
|
if 'blacklist_message' in login_page:
|
||||||
fail(clean_html(login_page))
|
fail(clean_html(login_page))
|
||||||
|
|
||||||
login_data = {
|
redirect_page, handle = login_step(
|
||||||
'username': username,
|
login_page, handle, 'Logging in as %s' % username, {
|
||||||
'password': password,
|
'username': username,
|
||||||
}
|
'password': password,
|
||||||
redirect_res = post_login_form(
|
})
|
||||||
login_page, handle, 'Logging in as %s' % username, login_data)
|
|
||||||
|
|
||||||
if not redirect_res:
|
|
||||||
return
|
|
||||||
redirect_page, handle = redirect_res
|
|
||||||
|
|
||||||
if re.search(r'(?i)<form[^>]+id="two-factor-submit"', redirect_page) is not None:
|
if re.search(r'(?i)<form[^>]+id="two-factor-submit"', redirect_page) is not None:
|
||||||
# TODO: Add mechanism to request an SMS or phone call
|
# TODO: Add mechanism to request an SMS or phone call
|
||||||
tfa_token = self._get_tfa_info('two-factor authentication token')
|
tfa_token = self._get_tfa_info('two-factor authentication token')
|
||||||
tfa_data = {
|
login_step(redirect_page, handle, 'Submitting TFA token', {
|
||||||
'authy_token': tfa_token,
|
'authy_token': tfa_token,
|
||||||
'remember_2fa': 'true',
|
'remember_2fa': 'true',
|
||||||
}
|
})
|
||||||
post_login_form(redirect_page, handle, 'Submitting TFA token', tfa_data)
|
|
||||||
|
|
||||||
def _prefer_source(self, formats):
|
def _prefer_source(self, formats):
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue