-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
53 lines (45 loc) · 1.79 KB
/
main.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
import os
import requests
import hashlib
def main():
version = input('mc version: ')
path = os.path.expanduser('~/.minecraft/mods/')
backup_path = os.path.expanduser('~/.minecraft/mods.bak/')
if not os.path.exists(backup_path):
print(f"creating {backup_path}")
os.mkdir(backup_path)
files = os.listdir(path)
for file in files:
if file.endswith(".jar"):
src_path = os.path.join(path, file)
dst_path = os.path.join(backup_path, file)
os.rename(src_path, dst_path)
jar_file = os.path.join(backup_path, file)
with open(jar_file, 'rb') as mod:
data=mod.read()
hashed_files = hashlib.sha1(data).hexdigest()
r = requests.post(
url = "https://api.modrinth.com/v2/version_files/update",
headers = {
'User-Agent' : 'just updating mods',
'Content-Type' : 'application/json'
},
json = {
"hashes": [ f'{hashed_files}' ],
"algorithm": "sha1",
"loaders": [ "fabric" ],
"game_versions": [ f'{version}'
]
}
)
response = r.json()
for key, value in response.items():
urls = value["files"][0]["url"]
filename = value["files"][0]["filename"]
print("[+] downloading: ", urls)
r = requests.get(urls)
updated_mod = path + filename
with open(updated_mod, 'wb') as file:
file.write(r.content)
if __name__ == '__main__':
main()