|
|
|
@ -66,35 +66,41 @@ def modrinth(project, action, subAction):
|
|
|
|
|
print(parsers.modrinth.determine(project, "version_number"))
|
|
|
|
|
if subAction == "latest":
|
|
|
|
|
print(parsers.modrinth.getLatestVersion(project))
|
|
|
|
|
if subAction == "stable":
|
|
|
|
|
print(parsers.modrinth.getLatestStable(project))
|
|
|
|
|
if subAction == "get_URL":
|
|
|
|
|
print(parsers.modrinth.getDownloadURL(project, parsers.modrinth.getLatestVersion(project)))
|
|
|
|
|
|
|
|
|
|
if action == "download":
|
|
|
|
|
if subAction == "stable":
|
|
|
|
|
download(project, parsers.modrinth.getLatestStable(project))
|
|
|
|
|
if subAction == "latest":
|
|
|
|
|
latestVersion = parsers.modrinth.getLatestVersion(project)
|
|
|
|
|
output = parsers.modrinth.getDownloadURL(project, parsers.modrinth.getLatestVersion(project))
|
|
|
|
|
response = requests.get(output[0], stream=True, timeout=1)
|
|
|
|
|
if args.o != None: # Check if user set an output filepath
|
|
|
|
|
output_file = args.o
|
|
|
|
|
else:
|
|
|
|
|
output_file = output[2]
|
|
|
|
|
with response as raw:
|
|
|
|
|
with open(output_file, 'wb') as file_object:
|
|
|
|
|
shutil.copyfileobj(raw.raw, file_object)
|
|
|
|
|
print("Downloaded "+latestVersion+" to "+output_file)
|
|
|
|
|
#Calculate hash, compare with API given hash
|
|
|
|
|
h_sha1 = hashlib.sha1()
|
|
|
|
|
with open(output_file, 'rb') as file_object:
|
|
|
|
|
chunk = 0
|
|
|
|
|
while chunk != b'':
|
|
|
|
|
chunk = file_object.read(1024)
|
|
|
|
|
h_sha1.update(chunk)
|
|
|
|
|
print("API SHA 1: "+str(output[1]))
|
|
|
|
|
print("Our calculated SHA 1: "+str(h_sha1.hexdigest()))
|
|
|
|
|
if h_sha1.hexdigest() == output[1]:
|
|
|
|
|
print("sha1sum of downloaded file matches the sum that the API gave, jar is safe to use")
|
|
|
|
|
else:
|
|
|
|
|
raise MismatchSHA1Error
|
|
|
|
|
download(project, parsers.modrinth.getLatestVersion(project))
|
|
|
|
|
def download(project, what):
|
|
|
|
|
versionToDownload = what
|
|
|
|
|
output = parsers.modrinth.getDownloadURL(project, what)
|
|
|
|
|
response = requests.get(output[0], stream=True, timeout=1)
|
|
|
|
|
if args.o != None: # Check if user set an output filepath
|
|
|
|
|
output_file = args.o
|
|
|
|
|
else:
|
|
|
|
|
output_file = output[2]
|
|
|
|
|
with response as raw:
|
|
|
|
|
with open(output_file, 'wb') as file_object:
|
|
|
|
|
shutil.copyfileobj(raw.raw, file_object)
|
|
|
|
|
print("Downloaded "+versionToDownload+" to "+output_file)
|
|
|
|
|
#Calculate hash, compare with API given hash
|
|
|
|
|
h_sha1 = hashlib.sha1()
|
|
|
|
|
with open(output_file, 'rb') as file_object:
|
|
|
|
|
chunk = 0
|
|
|
|
|
while chunk != b'':
|
|
|
|
|
chunk = file_object.read(1024)
|
|
|
|
|
h_sha1.update(chunk)
|
|
|
|
|
print("API SHA 1: "+str(output[1]))
|
|
|
|
|
print("Our calculated SHA 1: "+str(h_sha1.hexdigest()))
|
|
|
|
|
if h_sha1.hexdigest() == output[1]:
|
|
|
|
|
print("sha1sum of downloaded file matches the sum that the API gave, jar is safe to use")
|
|
|
|
|
else:
|
|
|
|
|
raise MismatchSHA1Error
|
|
|
|
|
|
|
|
|
|
# Determine which API parser to use:
|
|
|
|
|
if args.api == "paperMC":
|
|
|
|
|