diff --git a/.gitignore b/.gitignore index 835e8dc..fb78377 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ .gradle .idea -build \ No newline at end of file +build +.settings +.project +.vscode +mods +mods.csv diff --git a/README.md b/README.md index 33003bc..7e5174a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,7 @@ -# anvilcraft3 -Execute gradlew buildTwitch to create the Twitch zip file in build/libs +# Anvilcraft3 tweaked fork by LordMZTE +- Execute `gradlew buildTwitch` + - To create the **Twitch Import** zip file in **build/lib** +- Execute `python downloadMods.py` + - To download all mods into **/mods/** +- Execute `python getModlist.py` + - To create a **mods.csv** file containing the names, authors, curseforge links, download count and ID of all mods diff --git a/downloadMods.py b/downloadMods.py new file mode 100644 index 0000000..ef2dbd6 --- /dev/null +++ b/downloadMods.py @@ -0,0 +1,51 @@ +import json +from urllib import request +import ntpath +import os + +#Constants: +manifestlocation="src/twitch/manifest.json" + +def tryGetLink(projectID: str, fileID: str): + while(True): + url = "https://addons-ecs.forgesvc.net/api/v2/addon/" + projectID + "/file/" + fileID + "/download-url" + try: + return request.urlopen(url, timeout=10000) + except: + print("Failed to get Download Link for " + url + " retrying...") + + +if os.path.exists("mods"): + if os.listdir("mods"): + print("mods directory is not empty, delete or empty") + quit() +else: + os.mkdir("mods") + + +try: + with open(manifestlocation, "r") as manifestfile: + manifestdata = manifestfile.read() +except: + print("manifest not found") + quit() +manifestobj = json.loads(manifestdata) + +downloadLinks = [] +filecount = len(manifestobj["files"]) + +i = 0 +for file in manifestobj["files"]: + i += 1 + with tryGetLink(str(file["projectID"]), str(file["fileID"])) as response: + responseLink = response.read().decode("utf-8") + downloadLinks.append(responseLink) + print("(" + str(i) + "/" + str(filecount) + ") Got Download Link For " + ntpath.basename(responseLink)) + +i = 0 +filecount = len(downloadLinks) +for link in downloadLinks: + i += 1 + filename = ntpath.basename(link) + request.urlretrieve(link.replace(" ", "%20"), "mods/" + filename) + print("(" + str(i) + "/" + str(filecount) + ") Downloaded " + filename) \ No newline at end of file diff --git a/getModlist.py b/getModlist.py new file mode 100644 index 0000000..05b045c --- /dev/null +++ b/getModlist.py @@ -0,0 +1,78 @@ +from urllib import request +import json +from os import path +import csv + + +#Constants +manifestlocation="src/twitch/manifest.json" + +if path.isfile("mods.csv"): + print("Delete mods.csv") + quit() + +try: + with open(manifestlocation, "r") as manifestfile: + manifestjson = json.loads(manifestfile.read()) +except: + print("manifest not found") + quit() + +projectIDs = [] + +for file in manifestjson["files"]: + projectIDs.append(file["projectID"]) + +filesInBytes = str(projectIDs).encode("utf-8") + +req = request.Request("https://addons-ecs.forgesvc.net/api/v2/addon", + data = filesInBytes, + headers = { + 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36', + "Content-Type": "application/json" + }) + +print("Getting Mod names from Twitch API") +with request.urlopen(req) as request: + response = request.read() + response = response.decode("ascii", "ignore") + apireturn = json.loads(response) + +print("Formatting") +mods = [] +for mod in apireturn: + modDict = {} + + modDict["name"] = mod["name"] + modDict["id"] = mod["id"] + modDict["url"] = mod["websiteUrl"] + modDict["downloads"] = mod["downloadCount"] + + authorStr = "" + for author in mod["authors"]: + authorStr += ", " + author["name"] + authorStr = authorStr.strip(", ") + modDict["authors"] = authorStr + + mods.append(modDict) + +with open("mods.csv", "w", newline = "") as modFile: + writer = csv.writer(modFile, delimiter=';', quoting=csv.QUOTE_MINIMAL) + + #Write Header + writer.writerow(["Mod Name", "Authors", "Link", "Downloads", "ID"]) + writer.writerow([]) + + #Write Data + print("Writing CSV") + for mod in mods: + toWrite = [] + + toWrite.append(mod["name"]) + toWrite.append(mod["authors"]) + toWrite.append(mod["url"]) + toWrite.append(str(int(mod["downloads"]))) + toWrite.append(str(int(mod["id"]))) + + writer.writerow(toWrite) +print("done") \ No newline at end of file diff --git a/src/twitch/manifest.json b/src/twitch/manifest.json index b7ed075..d5972c8 100644 --- a/src/twitch/manifest.json +++ b/src/twitch/manifest.json @@ -10,9 +10,9 @@ }, "manifestType": "minecraftModpack", "manifestVersion": 1, - "name": "Anvilcraft", + "name": "Anvilcraft MZTE Fork", "version": "3.0-BETA", - "author": "mpztilera", + "author": "mpztilera, LordMZTE", "files": [ { "projectID": 248425,