From bc909621e709754a24b5611e24434c7a8485f0ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Mora?= Date: Mon, 1 Apr 2019 12:59:08 +0200 Subject: [PATCH 1/2] [twitch] 2fa fix --- youtube_dl/extractor/twitch.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/youtube_dl/extractor/twitch.py b/youtube_dl/extractor/twitch.py index 8c87f6dd3..7058eb9f7 100644 --- a/youtube_dl/extractor/twitch.py +++ b/youtube_dl/extractor/twitch.py @@ -40,6 +40,7 @@ class TwitchBaseIE(InfoExtractor): _LOGIN_POST_URL = 'https://passport.twitch.tv/login' _CLIENT_ID = 'kimne78kx3ncx6brgo4mv6wki5h1ko' _NETRC_MACHINE = 'twitch' + _AUTHY_ERROR_CODE = 3011 def _handle_error(self, response): if not isinstance(response, dict): @@ -92,7 +93,19 @@ class TwitchBaseIE(InfoExtractor): post_url, None, note, data=json.dumps(form).encode(), headers=headers, expected_status=400) error = response.get('error_description') or response.get('error_code') - if error: + + if response.get('error_code') == self._AUTHY_ERROR_CODE: + # Authy code request + tfa_token = self._get_tfa_info('two-factor authentication token') + response = self._download_json( + post_url, None, note, data=json.dumps({ + 'username': username, + 'password': password, + 'client_id': self._CLIENT_ID, + 'authy_token': tfa_token, + 'remember_2fa': 'true', + }).encode(), headers=headers, expected_status=400) + else: fail(error) if 'Authenticated successfully' in response.get('message', ''): @@ -123,14 +136,6 @@ class TwitchBaseIE(InfoExtractor): if not redirect_page: return - if re.search(r'(?i)]+id="two-factor-submit"', redirect_page) is not None: - # TODO: Add mechanism to request an SMS or phone call - tfa_token = self._get_tfa_info('two-factor authentication token') - login_step(redirect_page, handle, 'Submitting TFA token', { - 'authy_token': tfa_token, - 'remember_2fa': 'true', - }) - def _prefer_source(self, formats): try: source = next(f for f in formats if f['format_id'] == 'Source') From 2396faf72ee776de4fb63250b8b98668d792b7ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Mora?= Date: Mon, 1 Apr 2019 13:00:06 +0200 Subject: [PATCH 2/2] [twitch] keep TODO message --- youtube_dl/extractor/twitch.py | 1 + 1 file changed, 1 insertion(+) diff --git a/youtube_dl/extractor/twitch.py b/youtube_dl/extractor/twitch.py index 7058eb9f7..ebb03e78f 100644 --- a/youtube_dl/extractor/twitch.py +++ b/youtube_dl/extractor/twitch.py @@ -96,6 +96,7 @@ class TwitchBaseIE(InfoExtractor): if response.get('error_code') == self._AUTHY_ERROR_CODE: # Authy code request + # TODO: Add mechanism to request an SMS or phone call tfa_token = self._get_tfa_info('two-factor authentication token') response = self._download_json( post_url, None, note, data=json.dumps({