|
6 | 6 | import shlex |
7 | 7 | import shutil |
8 | 8 | import requests |
| 9 | +from bs4 import BeautifulSoup |
9 | 10 |
|
10 | 11 | from urllib.parse import urlparse |
11 | 12 |
|
@@ -86,13 +87,23 @@ def get_shared_data(data): |
86 | 87 | match_str = match.group(1) |
87 | 88 | return json.loads(match_str).get("config") |
88 | 89 | else: |
89 | | - match = re.search(r"\"raw\":\"({[^\n]*\\\"})", data) |
90 | | - if match: |
91 | | - match_str = string_escape(match.group(1)) |
92 | | - csrf_token = re.search(r'"csrf_token":\s*"([^"]+)"', match_str) |
93 | | - csrf_token_value = csrf_token.group(1) |
94 | | - response = {"csrf_token": csrf_token_value} |
95 | | - return response |
| 90 | + response = {} |
| 91 | + soup = BeautifulSoup(data, 'html.parser') |
| 92 | + all_scripts = soup.find_all('script', {"data-content-len":True, "src": False}) |
| 93 | + chnk_len = 100 |
| 94 | + for script in all_scripts: |
| 95 | + if int(script["data-content-len"]) > 30000: |
| 96 | + lines = script.text |
| 97 | + for idx in range(0, len(lines), chnk_len): |
| 98 | + csrf_token_match = re.findall(r"csrf_token", lines[idx : idx + chnk_len]) |
| 99 | + if csrf_token_match: |
| 100 | + matches = re.findall(r'\{([^}]+)\}', lines[idx : idx + chnk_len]) |
| 101 | + if len(matches)>0: |
| 102 | + dict_value = "{" + matches[0] + "}" |
| 103 | + response = json.loads(dict_value) |
| 104 | + break |
| 105 | + return response |
| 106 | + |
96 | 107 |
|
97 | 108 | def lock_exists(): |
98 | 109 | return os.path.isfile(os.path.join(globals.config.download_path, globals.download.download_user + '.lock')) |
|
0 commit comments