Skip to content

Commit 8171e68

Browse files
1.6 Quick Release
Fixed some crashes Fixed the crash due to server changes from the website backend New App_config.ini for overall tool settings New Games Supported Display Progress of Collection Download
1 parent 4787b81 commit 8171e68

File tree

1 file changed

+130
-69
lines changed

1 file changed

+130
-69
lines changed

bot.py

+130-69
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# Defined Variables
2020
global cfg
2121
cfg = configparser.RawConfigParser()
22-
version = "1.5"
22+
version = "1.6"
2323
threads = 1
2424
get_date = datetime.datetime.now()
2525
month = get_date.month
@@ -44,54 +44,59 @@
4444
if not os.path.exists('configs'):
4545
os.makedirs('configs')
4646

47+
48+
4749
# Checking for updates on startup
4850
def update_checker():
49-
os.system('cls')
50-
header = "User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.108 Safari/537.36"
51-
git_up = "https://api.github.com/repos/Official-Husko/Husko-s-SteamWorkshop-Downloader/releases/latest"
52-
latest = requests.get(git_up,headers={"User-Agent":header}).text
53-
git_data = json.loads(latest)
54-
cv = str(git_data.get('tag_name'))
55-
u_info = str(git_data.get('body'))
56-
dir_url = str(git_data['assets'][0]['browser_download_url'])
57-
updt_name = str(git_data.get('name'))
58-
updt_rel = str(git_data.get('published_at'))
59-
if float(version) < float(cv):
60-
if discord_active == 1:
61-
RPC.update(state="Updating Downloader to " + cv,buttons=[{"label": "GitHub", "url": "https://github.com/Official-Husko/Husko-s-SteamWorkshop-Downloader"},],small_text="Updating",small_image="update",large_image="bridge")
62-
print(colored("A new Update is available!", "green"))
63-
print("")
64-
print("Name: " + colored(updt_name, "green"))
65-
print("Version: " + colored(cv, "green"))
66-
print("Released: " + colored(updt_rel.strip("tz"), "green"))
67-
print("")
68-
print("")
69-
print("==================<[ " + colored("What's New ", "green") + "]>==================")
70-
print(u_info)
71-
print("")
72-
sleep(3)
73-
print("Download Update? (Y/n)")
74-
fetch_u = input(">> ")
75-
if fetch_u == "y" or fetch_u == "Y":
76-
if not os.path.exists('update'):
77-
os.makedirs('update')
78-
fetch = requests.get(dir_url,headers={"User-Agent":header},stream=True)
79-
file_path = os.path.join("update/","Huskos SteamWorkshop Downloader.exe")
80-
file = open(file_path, 'wb')
81-
with alive_bar(int(int(fetch.headers.get('content-length')) / 1024 + 1), title="Downloading Update") as bar:
82-
for chunk in fetch.iter_content(chunk_size=1024):
83-
if chunk:
84-
file.write(chunk)
85-
file.flush()
86-
bar()
87-
file.close()
51+
if check_for_updates == "yes":
52+
os.system('cls')
53+
header = "User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.108 Safari/537.36"
54+
git_up = "https://api.github.com/repos/Official-Husko/Husko-s-SteamWorkshop-Downloader/releases/latest"
55+
latest = requests.get(git_up,headers={"User-Agent":header}).text
56+
git_data = json.loads(latest)
57+
cv = str(git_data.get('tag_name'))
58+
u_info = str(git_data.get('body'))
59+
dir_url = str(git_data['assets'][0]['browser_download_url'])
60+
updt_name = str(git_data.get('name'))
61+
updt_rel = str(git_data.get('published_at'))
62+
if float(version) < float(cv):
63+
if discord_active == 1:
64+
RPC.update(state="Updating Downloader to " + cv,buttons=[{"label": "GitHub", "url": "https://github.com/Official-Husko/Husko-s-SteamWorkshop-Downloader"},],small_text="Updating",small_image="update",large_image="bridge")
65+
print(colored("A new Update is available!", "green"))
66+
print("")
67+
print("Name: " + colored(updt_name, "green"))
68+
print("Version: " + colored(cv, "green"))
69+
print("Released: " + colored(updt_rel.strip("tz"), "green"))
70+
print("")
71+
print("")
72+
print("==================<[ " + colored("What's New ", "green") + "]>==================")
73+
print(u_info)
8874
print("")
89-
print("The Update has been downloaded into the update folder in your directory. the bot will close so you can replace the old exe with the new one. This will not delete any of the configs!")
90-
sleep(5)
91-
sys.exit(0)
92-
else:
93-
print("Proceeding to Downloader")
9475
sleep(3)
76+
print("Download Update? (Y/n)")
77+
fetch_u = input(">> ")
78+
if fetch_u == "y" or fetch_u == "Y":
79+
if not os.path.exists('update'):
80+
os.makedirs('update')
81+
fetch = requests.get(dir_url,headers={"User-Agent":header},stream=True)
82+
file_path = os.path.join("update/","Huskos SteamWorkshop Downloader.exe")
83+
file = open(file_path, 'wb')
84+
with alive_bar(int(int(fetch.headers.get('content-length')) / 1024 + 1), title="Downloading Update") as bar:
85+
for chunk in fetch.iter_content(chunk_size=1024):
86+
if chunk:
87+
file.write(chunk)
88+
file.flush()
89+
bar()
90+
file.close()
91+
print("")
92+
print("The Update has been downloaded into the update folder in your directory. the bot will close so you can replace the old exe with the new one. This will not delete any of the configs!")
93+
sleep(5)
94+
sys.exit(0)
95+
else:
96+
print("Proceeding to Downloader")
97+
sleep(3)
98+
proxy_scraper(cfg)
99+
else:
95100
proxy_scraper(cfg)
96101
else:
97102
proxy_scraper(cfg)
@@ -177,6 +182,7 @@ def config(cfg):
177182

178183

179184
def config2(cfg):
185+
ctypes.windll.kernel32.SetConsoleTitleW("Husko's Steam Workshop Downloader | v" + version)
180186
if discord_active == 1:
181187
RPC.update(state="Looking for a mod to Download",buttons=[{"label": "GitHub", "url": "https://github.com/Official-Husko/Husko-s-SteamWorkshop-Downloader"},],small_text=game_names.get(game),small_image=config_names.get(game),large_image="bridge")
182188
global id
@@ -188,6 +194,7 @@ def config2(cfg):
188194
xxid = xid.strip("https://steamcommunity.com/sharedfiles/filedetails/?id=")
189195
else:
190196
print(colored("Something Went Wrong! Either wrong workshop URL or another error.", "red"))
197+
print("")
191198
sleep(5)
192199
config2(cfg)
193200
id = re.match(r"(.*\d+)", xxid).group()
@@ -200,8 +207,15 @@ def config2(cfg):
200207
downloader(cfg)
201208

202209
def downloader(cfg):
210+
if create_mod_list == "yes":
211+
counter = 0
212+
filename = config_names.get(game) + "_modlist{}.txt"
213+
while os.path.isfile(filename.format(counter)):
214+
counter += 1
215+
filename = filename.format(counter)
216+
current_pos = 0
203217
for id in collection:
204-
backend = ["node01","node02","node03","node04","node05"]
218+
backend = ["node04","node05","node06","node07","node08"]
205219
bd = random.choice(backend)
206220
header = "User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.108 Safari/537.36"
207221
url = "https://" + bd + ".steamworkshopdownloader.io/prod/api/details/file"
@@ -299,22 +313,27 @@ def downloader(cfg):
299313
file.flush()
300314
bar()
301315
file.close()
302-
zip = "temp/" + safe_name + '.zip'
303-
destination = 'temp/' + safe_name
316+
if not_supported == True:
317+
destination = 'manual/' + safe_name
318+
if not os.path.exists('manual'):
319+
os.makedirs('manual')
320+
else:
321+
destination = 'temp/' + safe_name
304322
badzip = False
323+
zip = destination + '.zip'
305324
with zipfile.ZipFile(zip) as zf:
306325
try:
307326
zf.extractall(destination)
308327
except zipfile.BadZipFile:
309-
print(colored("Received Corrupt Zip File. Try to download the mod again. If the issue persists try to open it manually and if it works report this issue to the mod author else the server sent a corrupt file.", "red"))
328+
print(colored("Received Corrupt Zip File. Try to download the mod again. If the issue persists try to open it manually and if it works report this issue to me on github else the server sent a corrupt file.", "red"))
310329
badzip = True
311330
os.remove("temp/" + safe_name + ".zip")
312331
if not_supported == True:
313-
print("You can now proceed to manually install the mod " + colored(name, "green") + " located in the temp folder.")
332+
print("You can now proceed to manually install the mod " + colored(name, "green") + " located in the manual folder.")
314333
print("")
315334
collection.clear()
316335
config2(cfg)
317-
336+
318337
# Stormworks: Build and Rescue
319338
if int(game) == 573090:
320339

@@ -351,13 +370,16 @@ def downloader(cfg):
351370
# Project Zomboid
352371
elif int(game) == 108600:
353372
mod_path = mods + "/mods/"
354-
file_names = os.listdir(destination + '/mods')
355-
for file_name in file_names:
356-
shutil.rmtree(mod_path + file_name, ignore_errors=True)
357-
shutil.move(os.path.join(destination + '/mods', file_name), mod_path)
358-
359-
# Hunt and Snare
360-
elif int(game) == 944330:
373+
try:
374+
file_names = os.listdir(destination + '/mods')
375+
for file_name in file_names:
376+
shutil.rmtree(mod_path + file_name, ignore_errors=True)
377+
shutil.move(os.path.join(destination + '/mods', file_name), mod_path)
378+
except:
379+
yes = False
380+
381+
# Hunt and Snare & Call to Arms - Gates of Hell: Ostfront
382+
elif int(game) == 944330 or 400750 or 1118200:
361383
mod_path = mods + safe_name
362384
if os.path.exists(mod_path):
363385
shutil.rmtree(mod_path, ignore_errors=True)
@@ -377,13 +399,14 @@ def downloader(cfg):
377399
for file_name in file_names:
378400
shutil.move(os.path.join("temp/", file_name), mod_path)
379401

380-
# Call to Arms - Gates of Hell: Ostfront
381-
elif int(game) == 400750:
382-
mod_path = mods + safe_name
383-
if os.path.exists(mod_path):
384-
shutil.rmtree(mod_path, ignore_errors=True)
402+
# Ravenfield
403+
elif int(game) == 636480:
404+
mod_path = mods
405+
if not os.path.exists(mod_path):
406+
os.makedirs(mod_path)
385407
source_dir = 'temp/'
386408
file_names = os.listdir(source_dir)
409+
shutil.rmtree(mod_path + "/" + safe_name, ignore_errors=True)
387410
for file_name in file_names:
388411
shutil.move(os.path.join("temp/", file_name), mod_path)
389412

@@ -393,6 +416,10 @@ def downloader(cfg):
393416
print("Mod " + colored(name, "red") + " Failed to Install!")
394417
else:
395418
print("Mod " + colored(name, "green") + " Successfully Installed!")
419+
with open(config_names.get(game) + "_modlist.txt", "a") as wmf:
420+
wmf.write(xid + '\n')
421+
current_pos += 1
422+
ctypes.windll.kernel32.SetConsoleTitleW("Husko's Steam Workshop Downloader | " + str(current_pos) + "/" + str(amount) + " | v" + version)
396423
print("")
397424
shutil.rmtree('temp', ignore_errors=True)
398425
os.makedirs('temp')
@@ -457,23 +484,35 @@ def downloader(cfg):
457484
108600,
458485
944330,
459486
294100,
460-
400750
487+
400750,
488+
824270,
489+
4000,
490+
1118200,
491+
636480
461492
]
462493

463494
config_names = {
464495
573090: "stormworks",
465496
108600: "pz",
466497
944330: "hunt_snare",
467498
294100: "rimworld",
468-
400750: "cta_goh"
499+
400750: "cta_goh",
500+
824270: "kovaaks",
501+
4000: "gmod",
502+
1118200: "people_pg",
503+
636480: "ravenfield"
469504
}
470505

471506
game_names = {
472507
573090: "Stormworks: Build and Rescue",
473508
108600: "Project Zomboid",
474509
944330: "Hunt and Snare",
475510
294100: "Rimworld",
476-
400750: "Call to Arms - Gates of Hell: Ostfront"
511+
400750: "Call to Arms - Gates of Hell: Ostfront",
512+
824270: "KovaaK's",
513+
4000: "Garry's Mod",
514+
1118200: "People Playground",
515+
636480: "Ravenfield"
477516
}
478517

479518
# Check if the stormworks_config.ini exists else create it
@@ -484,8 +523,6 @@ def check_config(cfg):
484523
cfg.set('Default', 'ModsPath', 'insert-path-here')
485524
cfg.set('Default', '# if proxies should be scraped and used', '')
486525
cfg.set('Default', 'Proxies', 'yes')
487-
cfg.set('Default', '# Seconds Wait time for each request (Default 5)', '')
488-
cfg.set('Default', 'WaitSeconds', '5')
489526
cfg.set('Default', '# Randomize User Agent', '')
490527
cfg.set('Default', 'RandomUserAgent', 'yes')
491528
cfg.set('Default', '# Request Timeout', '')
@@ -498,6 +535,29 @@ def check_config(cfg):
498535
sys.exit(0)
499536
config(cfg)
500537

538+
# Checks for a global app config
539+
def app_cfg_checker(cfg):
540+
if not os.path.exists("configs/app_config.ini"):
541+
cfg.add_section('Default')
542+
cfg.set('Default', '# Check if an update is available on each startup', '')
543+
cfg.set('Default', 'UpdatesChecker', 'yes')
544+
cfg.set('Default', '# Automatically Write Downloaded mods to a modlist', '')
545+
cfg.set('Default', 'MakeModlist', 'yes')
546+
with open(r"configs/app_config.ini", 'w') as configfile:
547+
cfg.write(configfile)
548+
configfile.close()
549+
print("New App Config file was generated! Please configure it and then start the bot again")
550+
sleep(5)
551+
sys.exit(0)
552+
else:
553+
configFilePath = "configs/app_config.ini"
554+
cfg.read(configFilePath)
555+
global check_for_updates
556+
check_for_updates = cfg.get('Default', 'UpdatesChecker')
557+
global create_mod_list
558+
create_mod_list = cfg.get('Default', 'MakeModlist')
559+
update_checker()
560+
501561
# scrape proxies from a given destination
502562
def proxy_scraper(cfg):
503563
proxy_source = random.choice(proxy_source_list)
@@ -510,9 +570,10 @@ def proxy_scraper(cfg):
510570
game_selection(cfg)
511571

512572
if __name__ == '__main__':
513-
update_checker()
573+
app_cfg_checker(cfg)
514574

515575
# Credits
516576
#
517577
# h110m - Helping and explaining on how to add a fancy download bar
578+
# Firecracker - Helping me solve a stupid issue that took longer than it should to solve. I'm sorry again
518579
#

0 commit comments

Comments
 (0)