-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathall.py
394 lines (342 loc) · 9.96 KB
/
all.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
import argparse
import glob
import os
import re
import shutil
import subprocess
import sys
import time
import requests
def setup(extract, onlydownload):
if extract:
os.makedirs("temp", exist_ok=True)
if onlydownload:
os.makedirs("temp", exist_ok=True)
else:
os.makedirs("temp/output", exist_ok=True)
os.makedirs("temp/upload", exist_ok=True)
def get_session(devmode):
try:
import browser_cookie3
# Retrieve Firefox cookies for the domain
try:
cookies = browser_cookie3.firefox(domain_name="armconverter.com")
except browser_cookie3.BrowserCookieError:
print("Cookies do not exist or cannot be accessed.")
sys.exit(1)
except Exception as e:
print(f"An unexpected error occurred: {e}")
sys.exit(1)
# Filter for session cookies (non-expiring cookies)
session_cookies = [cookie for cookie in cookies if not cookie.expires]
# If no session cookies are found, exit
if not session_cookies:
print("No session cookies found.")
sys.exit(1)
# Extract and print session cookie values
session_cookie_values = [cookie.value for cookie in session_cookies]
if devmode:
for value in session_cookie_values:
print(value)
# Return the first session cookie value, or None if no cookies are present
return session_cookie_values[0] if session_cookie_values else None
except browser_cookie3.BrowserCookieError as e:
print(f"Error occurred: {e}")
sys.exit(1)
except Exception as e:
print(f"Error occurred getting session: {e}")
sys.exit(1)
def version():
url = "https://gplayapi.herrerde.xyz/api/apps/com.kiloo.subwaysurf"
response = requests.get(url)
data = response.json()
return data.get("version", "").replace(".", "-")
def get_rm(nodownload):
rm_file = [
"*.apk",
"subwaysurfers-*.zip",
"*_output.json",
"*_data_old.json",
"update.txt",
]
rm_dir = ["gamedata"]
if not nodownload:
ipa_file = "*.ipa"
rm_file.insert(0, ipa_file)
tmp_dir = "temp"
rm_dir.insert(0, tmp_dir)
return rm_file, rm_dir
def get_scripts(
type_,
version,
session,
nodownload,
onlydownload,
dlprogress,
limit,
checkversion,
extract,
skip,
):
skip_list = [script.strip() for script in skip.split(",") if script.strip()]
if type_ == "apk":
session = ""
if extract:
return [
[
f"script/down-{type_}.py",
version,
session,
str(dlprogress),
],
[f"misc/unpack-{type_}.py", version],
]
if onlydownload:
return [
[
f"script/down-{type_}.py",
version,
session,
str(dlprogress),
]
]
script_list = [
[f"misc/unpack-{type_}.py", version],
["script/fetch_links.py"],
["script/fetch_profile.py"],
["script/fetch_outfits.py", limit],
["script/fetch_characters.py"],
["script/fetch_boards.py"],
["script/playerprofile.py"],
["script/userstats.py"],
["script/collection.py"],
["script/challenges.py"],
["script/calender.py"],
["script/mailbox.py"],
["script/achievements.py"],
["script/chainoffers.py"],
["misc/sort_characters.py"],
["misc/sort_boards.py"],
["misc/sort_profile.py"],
["misc/check.py", checkversion],
]
if not nodownload:
download_script = [
f"script/down-{type_}.py",
version,
session,
str(dlprogress),
]
script_list.insert(0, download_script)
# Filter out skipped scripts
script_list = [
script
for script in script_list
if script[0].split("/")[-1].split(".")[0] not in skip_list
]
return script_list
def cleanup(nodownload, nocleanup):
if nocleanup:
print("No cleanup")
return
print("Starting cleanup")
rm_file, rm_dir = get_rm(nodownload)
try:
for pattern in rm_file:
for file in glob.glob(pattern):
if os.path.exists(file):
os.remove(file)
for directory in rm_dir:
if os.path.exists(directory):
shutil.rmtree(directory)
print("Finished cleanup\n")
except KeyboardInterrupt:
print("Cleanup interrupted by user.")
sys.exit(1)
except Exception as e:
print(f"An error occurred during cleanup: {e}")
sys.exit(1)
def run_scripts(
type_,
version,
nodownload,
onlydownload,
dlprogress,
delay,
session,
devmode,
checkversion,
extract,
skip,
):
limit = "0"
if devmode:
limit = "5"
if not nodownload:
if not session and not type_ == "apk":
session = get_session(devmode)
scripts = get_scripts(
type_,
version,
session,
nodownload,
onlydownload,
dlprogress,
limit,
checkversion,
extract,
skip,
)
try:
print(f"Choosing type: {type_}")
print(f"Choosing version: {version}\n")
for index, script in enumerate(scripts):
print(f"Running {script[0]}...")
if script[0].startswith("script/down-ipa.py"):
result = subprocess.run(
["python"] + script,
capture_output=True,
text=True,
check=True,
)
output = result.stdout.strip()
print(output)
if "quota" in output.lower():
sys.exit(1)
else:
subprocess.run(["python"] + script, check=True)
print(f"Finished running {script[0]}.")
# Sleep only if this is not the last script
if index < len(scripts) - 1:
time.sleep(delay)
print("\n")
except Exception as e:
print(f"Error occurred while running script: {e}")
sys.exit(1)
except KeyboardInterrupt:
print("Script execution interrupted by user.")
sys.exit(0)
def main():
parser = argparse.ArgumentParser(description="Run Subway Surfers scripts.")
parser.add_argument(
"-t",
"--type",
choices=["apk", "ipa"],
default="ipa",
help="Choose between type apk and ipa",
)
parser.add_argument(
"-v", "--version", type=str, default=None, help="Choose a specific version"
)
parser.add_argument(
"-c", "--cleanup", action="store_true", help="Run cleanup function only"
)
parser.add_argument(
"-nc", "--nocleanup", action="store_true", help="Prevents cleaning up any files"
)
parser.add_argument(
"-e",
"--extract",
action="store_true",
help="Download and extract the latest apk/ipa",
)
parser.add_argument(
"-ndl",
"--nodownload",
action="store_true",
help="Run scripts without downloading the game file (requires pre-downloaded file)",
)
parser.add_argument(
"-odl",
"--onlydownload",
action="store_true",
help="Only downloads the gamefile",
)
parser.add_argument(
"-dlp",
"--dlprogress",
action="store_true",
help="Enables the download progress bar",
)
parser.add_argument(
"-dly",
"--delay",
type=int,
default=5,
help="Change the delay between the running scripts",
)
parser.add_argument(
"-sess",
"--session",
type=str,
default="",
help="Set the iosGods session cookie",
)
parser.add_argument(
"-dev",
"--devmode",
action="store_true",
help="Enables dev mode, will e.g limit outfit fetch",
)
parser.add_argument(
"-cv",
"--checkversion",
type=str,
default="",
help="Compare updates to a version older than the latest",
)
parser.add_argument(
"-skp",
"--skip",
type=str,
default="",
help="Write a list of scripts that should be skipped, with or without extension. (Like this 'collection.py,playerprofile,calender')",
)
args = parser.parse_args()
# If version is not provided, set it using the version() function
if args.version is None:
args.version = version()
# Regex pattern
version_pattern = r"^\d{1,2}-\d{1,2}-\d{1,2}$"
# Validate 'version'
if args.version and not re.match(version_pattern, args.version):
print(
"Error: 'version' has the wrong format. Please use the format 'X-Y-Z' (e.g., '3-12-2')."
)
sys.exit(1)
# Validate 'checkversion'
if args.checkversion and not re.match(version_pattern, args.checkversion):
print(
"Error: 'checkversion' has the wrong format. Please use the format 'X-Y-Z' (e.g., '3-12-2')."
)
sys.exit(1)
try:
if args.cleanup:
cleanup(args.nodownload, args.nocleanup)
sys.exit(0)
setup(args.extract, args.onlydownload)
run_scripts(
args.type,
args.version,
args.nodownload,
args.onlydownload,
args.dlprogress,
args.delay,
args.session,
args.devmode,
args.checkversion,
args.extract,
args.skip,
)
except Exception as e:
print("Error:", e)
sys.exit(1)
except KeyboardInterrupt:
print("Script terminated by user.")
sys.exit(1)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("Script terminated by user.")
sys.exit(1)