Skip to content

Commit

Permalink
1.5.4 temporary login fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rdavydov committed Dec 16, 2022
1 parent ea2a47c commit 163d7de
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 16 deletions.
2 changes: 1 addition & 1 deletion TwitchChannelPointsMiner/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
__version__ = "1.5.3"
__version__ = "1.5.4"
from .TwitchChannelPointsMiner import TwitchChannelPointsMiner

__all__ = [
Expand Down
60 changes: 46 additions & 14 deletions TwitchChannelPointsMiner/classes/TwitchLogin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import os
import pickle

import browser_cookie3

import requests

from TwitchChannelPointsMiner.classes.Exceptions import (
Expand Down Expand Up @@ -43,7 +45,8 @@ class TwitchLogin(object):
"password",
"user_id",
"email",
"cookies"
"cookies",
"shared_cookies"
]

def __init__(self, client_id, device_id, username, user_agent, password=None):
Expand All @@ -61,6 +64,7 @@ def __init__(self, client_id, device_id, username, user_agent, password=None):
self.email = None

self.cookies = []
self.shared_cookies = []

def login_flow(self):
logger.info("You'll have to login to Twitch!")
Expand All @@ -71,8 +75,8 @@ def login_flow(self):
"remember_me": True,
}
# login-fix
use_backup_flow = False
#use_backup_flow = True
#use_backup_flow = False
use_backup_flow = True

for attempt in range(0, 25):
password = (
Expand Down Expand Up @@ -133,8 +137,8 @@ def login_flow(self):
# If the user didn't load the password from run.py we can just ask for it again.
break
# login-fix
elif err_code == 1000:
#elif err_code in [1000, 5022]:
#elif err_code == 1000:
elif err_code in [1000, 5022, 5023, 5024]:
logger.info(
"Console login unavailable (CAPTCHA solving required)."
)
Expand Down Expand Up @@ -235,8 +239,33 @@ def login_flow_backup(self, password = None):
return False
return self.get_cookie_value("auth-token")"""
logger.error("Backup login flow is not available. Use a VPN or wait a while to avoid the CAPTCHA.")
return False

#logger.error("Backup login flow is not available. Use a VPN or wait a while to avoid the CAPTCHA.")
#return False

"""Backup OAuth login flow in case manual captcha solving is required"""
browser = input(
"What browser do you use? Chrome (1), Firefox (2), Other (3): "
).strip()
if browser not in ("1", "2"):
logger.info("Your browser is unsupported, sorry.")
return None

input(
"Please login inside your browser of choice (NOT incognito mode) and press Enter..."
)
logger.info("Loading cookies saved on your computer...")
twitch_domain = ".twitch.tv"
if browser == "1": # chrome
cookie_jar = browser_cookie3.chrome(domain_name=twitch_domain)
else:
cookie_jar = browser_cookie3.firefox(domain_name=twitch_domain)
#logger.info(f"cookie_jar: {cookie_jar}")
cookies_dict = requests.utils.dict_from_cookiejar(cookie_jar)
#logger.info(f"cookies_dict: {cookies_dict}")
self.username = cookies_dict.get("login")
self.shared_cookies = cookies_dict
return cookies_dict.get("auth-token")

def check_login(self):
if self.login_check_result:
Expand All @@ -248,17 +277,20 @@ def check_login(self):
return self.login_check_result

def save_cookies(self, cookies_file):
#pickle.dump(self.cookies, open(cookies_file, "wb"))
# ^ only this line was needed with Selenium ^
cookies_dict = self.session.cookies.get_dict()
cookies_dict["auth-token"] = self.token
if "persistent" not in cookies_dict: # saving user id cookies
cookies_dict["persistent"] = self.user_id
#cookies_dict = self.session.cookies.get_dict()
#print(f"cookies_dict2pickle: {cookies_dict}")
#cookies_dict["auth-token"] = self.token
#if "persistent" not in cookies_dict: # saving user id cookies
# cookies_dict["persistent"] = self.user_id

# old way saves only 'auth-token' and 'persistent'
self.cookies = []
cookies_dict = self.shared_cookies
#print(f"cookies_dict2pickle: {cookies_dict}")
for cookie_name, value in cookies_dict.items():
self.cookies.append({"name": cookie_name, "value": value})
pickle.dump(self.cookies, open(cookies_file, "wb"))
#print(f"cookies2pickle: {self.cookies}")
pickle.dump(self.cookies, open(cookies_file, "wb"))

def get_cookie_value(self, key):
for cookie in self.cookies:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ colorama
flask
irc
pandas
browser_cookie3
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def read(fname):
"colorama",
"flask",
"irc",
"pandas"
"pandas",
"browser_cookie3"
],
long_description=read("README.md"),
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 163d7de

Please sign in to comment.