diff --git a/pyinstalive/api.py b/pyinstalive/api.py index b90ee20..1aea731 100644 --- a/pyinstalive/api.py +++ b/pyinstalive/api.py @@ -7,7 +7,8 @@ def get_csrf_token(): response = globals.session.session.get(Constants.LOGIN_PAGE) - return helpers.get_shared_data(response.text).get("csrf_token", None) + helper_res = helpers.get_shared_data(response.text) + return helper_res.get("csrf_token", None) def do_login(): now_epoch = int(datetime.now().timestamp()) diff --git a/pyinstalive/helpers.py b/pyinstalive/helpers.py index d35ac77..0d32bd5 100644 --- a/pyinstalive/helpers.py +++ b/pyinstalive/helpers.py @@ -6,6 +6,7 @@ import shlex import shutil import requests +from bs4 import BeautifulSoup from urllib.parse import urlparse @@ -86,10 +87,23 @@ def get_shared_data(data): match_str = match.group(1) return json.loads(match_str).get("config") else: - match = re.search(r"\"raw\":\"({[^\n]*\\\"})", data) - if match: - match_str = string_escape(match.group(1)) - return json.loads(match_str) + response = {} + soup = BeautifulSoup(data, 'html.parser') + all_scripts = soup.find_all('script', {"data-content-len":True, "src": False}) + chnk_len = 100 + for script in all_scripts: + if int(script["data-content-len"]) > 30000: + lines = script.text + for idx in range(0, len(lines), chnk_len): + csrf_token_match = re.findall(r"csrf_token", lines[idx : idx + chnk_len]) + if csrf_token_match: + matches = re.findall(r'\{([^}]+)\}', lines[idx : idx + chnk_len]) + if len(matches)>0: + dict_value = "{" + matches[0] + "}" + response = json.loads(dict_value) + break + return response + def lock_exists(): return os.path.isfile(os.path.join(globals.config.download_path, globals.download.download_user + '.lock')) diff --git a/requirements.txt b/requirements.txt index 3d214e3..5564c55 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,4 @@ argparse>=1.4.0 -configparser>=4.0.2 \ No newline at end of file +configparser>=4.0.2 +requests==2.30.0 +beautifulsoup4==4.12.2 \ No newline at end of file