-
Notifications
You must be signed in to change notification settings - Fork 0
/
mcmod.py
60 lines (51 loc) · 2 KB
/
mcmod.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
import json
import os
import time
import requests
from ruamel.yaml import YAML
from log import log
if not os.path.exists("mods"):
os.makedirs("mods")
log.info("已创建 mods 文件夹")
yaml = YAML()
with open('id.yml', 'r', encoding='utf-8') as f:
yml = yaml.load(f)
cookie = 'XX' # 填入_uuid
def upload(cookies: str, file, classID, mcVerList, platformList, apiList, tagList):
start = time.time()
url = 'https://modfile-dl.mcmod.cn/action/upload/'
headers = {'Cookie': '_uuid=' + cookies}
file1 = open('mods/' + file, 'rb')
form = {
'file1': file1,
'classID': (None, classID),
'mcverList': (None, mcVerList),
'platformList': (None, platformList),
'apiList': (None, apiList),
'tagList': (None, tagList)
}
response = requests.post(url, headers=headers, files=form)
msg = json.loads(response.text[3:])
try:
if msg['success']['upload']:
log.info(f"文件 {file} 上传成功,{time.time() - start:.1f} s")
elif msg['success']['update']:
log.info(f"文件 {file} 覆盖成功,{time.time() - start:.1f} s")
else:
log.error(f"文件 {file} 上传失败,服务器返回信息如下:")
log.error(msg)
except KeyError:
log.error(f"文件 {file} 上传失败,服务器返回信息如下:")
log.error(msg)
file1.close()
for mod in os.listdir("mods"):
cache = os.path.splitext(mod)[0].split("-")
abs_path = os.path.abspath(mod)
if cache.__contains__("forge") or cache.__contains__("fabric") or cache.__contains__("quilt"):
y = yml[cache[0]]
upload(cookies=cookie, file=mod, classID=y["classID"], mcVerList=cache[2], platformList=y["platformList"],
apiList=y["apiList"], tagList=y["tagList"])
else:
y = yml[cache[0]]
upload(cookies=cookie, file=mod, classID=y["classID"], mcVerList=cache[1], platformList=y["platformList"],
apiList=y["apiList"], tagList=y["tagList"])