Skip to content

Commit 4f7a7b7

Browse files
Fixed Crashes & Added Update Checker
Both Known issues which would lead to a crash have been fixed. Added an Update Checker
1 parent 99194ce commit 4f7a7b7

File tree

2 files changed

+71
-17
lines changed

2 files changed

+71
-17
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ __pycache__/
88
Huskos SteamWorkshop Downloader.spec
99

1010
configs/
11+
12+
update/

bot.py

+69-17
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@
1313
from alive_progress import alive_bar
1414
import datetime
1515
import sys
16+
import re
1617

1718
# Defined Variables
1819
global cfg
1920
cfg = configparser.RawConfigParser()
20-
version = "v1.3"
21+
version = "1.2"
2122
threads = 1
2223
get_date = datetime.datetime.now()
2324
month = get_date.month
2425

25-
client_id = '945401698401284116' # Put your Client ID here, this is a fake ID
26-
RPC = Presence(client_id) # Initialize the Presence class
27-
RPC.connect() # Start the handshake loop
26+
# Connect to Discord RPC
27+
client_id = '945401698401284116'
28+
RPC = Presence(client_id)
29+
RPC.connect()
2830

2931
# Check if folder exists else create it
3032
if os.path.exists('temp'):
@@ -38,11 +40,60 @@
3840
if not os.path.exists('configs'):
3941
os.makedirs('configs')
4042

43+
# Checking for updates on startup
44+
def update_checker():
45+
os.system('cls')
46+
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"
47+
git_up = "https://api.github.com/repos/Official-Husko/Husko-s-SteamWorkshop-Downloader/releases/latest"
48+
latest = requests.get(git_up,headers={"User-Agent":header}).text
49+
git_data = json.loads(latest)
50+
cv = str(git_data.get('tag_name'))
51+
u_info = str(git_data.get('body'))
52+
dir_url = str(git_data['assets'][0]['browser_download_url'])
53+
updt_name = str(git_data.get('name'))
54+
updt_rel = str(git_data.get('published_at'))
55+
if float(version) < float(cv):
56+
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")
57+
print(colored("A new Update is available!", "green"))
58+
print("")
59+
print("Name: " + colored(updt_name, "green"))
60+
print("Version: " + colored(cv, "green"))
61+
print("Released: " + colored(updt_rel.strip("tz"), "green"))
62+
print("")
63+
print("")
64+
print("==================<[ " + colored("What's New ", "green") + "]>==================")
65+
print(u_info)
66+
print("")
67+
sleep(3)
68+
print("Download Update? (Y/n)")
69+
fetch_u = input(">> ")
70+
if fetch_u == "y" or fetch_u == "Y":
71+
if not os.path.exists('update'):
72+
os.makedirs('update')
73+
fetch = requests.get(dir_url,headers={"User-Agent":header},stream=True)
74+
file_path = os.path.join("update/","Huskos SteamWorkshop Downloader.exe")
75+
file = open(file_path, 'wb')
76+
with alive_bar(int(int(fetch.headers.get('content-length')) / 1024 + 1), title="Downloading Update") as bar:
77+
for chunk in fetch.iter_content(chunk_size=1024):
78+
if chunk:
79+
file.write(chunk)
80+
file.flush()
81+
bar()
82+
file.close()
83+
print("")
84+
print("The Update has been downloaded into the downloads folder in your directory. Once you are ready you can close the bot and replace the old exe with the new one. This will not delete any of the configs!")
85+
sleep(5)
86+
sys.exit(0)
87+
else:
88+
print("Proceeding to Downloader")
89+
sleep(3)
90+
proxy_scraper(cfg)
91+
4192
# Set CMD Title
42-
ctypes.windll.kernel32.SetConsoleTitleW("Husko's Steam Workshop Downloader | " + version)
93+
ctypes.windll.kernel32.SetConsoleTitleW("Husko's Steam Workshop Downloader | v" + version)
4394

4495
def game_selection(cfg):
45-
RPC.update(state="Selecting a Game",buttons=[{"label": "GitHub", "url": "https://github.com/Official-Husko"},],small_text="Game Selection",small_image="selection",large_image="bridge")
96+
RPC.update(state="Selecting a Game",buttons=[{"label": "GitHub", "url": "https://github.com/Official-Husko/Husko-s-SteamWorkshop-Downloader"},],small_text="Game Selection",small_image="selection",large_image="bridge")
4697
os.system('cls')
4798
print(colored("======================================================================================================================", "red"))
4899
print(colored("| |", "red"))
@@ -96,17 +147,17 @@ def config(cfg):
96147
print("Proxies Loaded: " + colored(str(len(proxy_list)), "green"))
97148
print("")
98149
print("Please Enter the Workshop Link")
99-
RPC.update(state="Looking for a mod to Download",buttons=[{"label": "GitHub", "url": "https://github.com/Official-Husko"},],small_text=game_names.get(game),small_image=config_names.get(game),large_image="bridge")
150+
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")
100151
config2(cfg)
101152

102153

103154
def config2(cfg):
104-
RPC.update(state="Looking for a mod to Download",buttons=[{"label": "GitHub", "url": "https://github.com/Official-Husko"},],small_text=game_names.get(game),small_image=config_names.get(game),large_image="bridge")
155+
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")
105156
global id
106157
global xid
107158
xid = input(colored(">> ", ))
108-
xxid = xid.strip("https://steamcommunity.com/sharedfiles/filedetails/?id=")
109-
id = xxid.strip("&searchtext=")
159+
xxid = re.match(r"(.*\d+)", xid).group()
160+
id = xxid.strip("https://steamcommunity.com/sharedfiles/filedetails/?id=")
110161
if id.isnumeric() == False:
111162
print(colored("Something Went Wrong! Either wrong workshop URL or another error.", "red"))
112163
sleep(5)
@@ -128,18 +179,22 @@ def downloader(cfg):
128179
page = requests.post(url,headers={"User-Agent":header},proxies=proxyy,timeout=timeout,data=mod_id).text
129180
else:
130181
page = requests.post(url,headers={"User-Agent":header},timeout=timeout,data=mod_id).text
182+
if page == "[]":
183+
print(colored("Mod Not Found. If this seems to be a mistake please open an issue report.", "red"))
184+
sleep(3)
185+
config2(cfg)
131186
data = json.loads(page)
132187
for i in data:
133188
pubid = str(i.get('publishedfileid'))
134189
safe_name = str(i.get('title_disk_safe'))
135190
name = str(i.get('title'))
136191
app_id = str(i.get('creator_appid'))
137192
if int(app_id) != int(game):
138-
print("You Tried to download a mod for a different game then you selected!")
193+
print(colored("You Tried to download a mod for a different game then you selected!", "red"))
139194
sleep(3)
140195
game_selection(cfg)
141196
print("Downloading: " + colored(name, "green"))
142-
RPC.update(details="Downloading " + name,buttons=[{"label": "GitHub", "url": "https://github.com/Official-Husko"},{"label": "Mod Page", "url": "" + xid +""}],small_text="Stormworks: Build and Rescue",small_image="stormworks",large_image="bridge")
197+
RPC.update(details="Downloading " + name,buttons=[{"label": "GitHub", "url": "https://github.com/Official-Husko/Husko-s-SteamWorkshop-Downloader"},{"label": "Mod Page", "url": "" + xid +""}],small_text="Stormworks: Build and Rescue",small_image="stormworks",large_image="bridge")
143198
url2 = "https://" + bd + ".steamworkshopdownloader.io/prod/api/download/request"
144199
req_data = '{"publishedFileId":' + pubid + ',"collectionId":null,"hidden":false,"downloadFormat":"raw","autodownload":false}'
145200
if proxies == "yes":
@@ -182,10 +237,7 @@ def downloader(cfg):
182237
r = requests.get(url4,headers={"User-Agent":header},timeout=timeout,stream=True)
183238
file_path = os.path.join("temp/", safe_name + ".zip")
184239
file = open(file_path, 'wb')
185-
style = "smooth"
186-
if month == 10:
187-
style = "halloween"
188-
with alive_bar(int(int(r.headers.get('content-length')) / 1024 + 1),bar=style) as bar:
240+
with alive_bar(int(int(r.headers.get('content-length')) / 1024 + 1)) as bar:
189241
for chunk in r.iter_content(chunk_size=1024):
190242
if chunk:
191243
file.write(chunk)
@@ -365,7 +417,7 @@ def proxy_scraper(cfg):
365417
game_selection(cfg)
366418

367419
if __name__ == '__main__':
368-
proxy_scraper(cfg)
420+
update_checker()
369421

370422
# Credits
371423
#

0 commit comments

Comments
 (0)