Skip to content

Instantly share code, notes, and snippets.

@Sultan-papagani
Created August 9, 2024 10:52
Show Gist options
  • Save Sultan-papagani/b62e00db887d703121301442eaf22762 to your computer and use it in GitHub Desktop.
Save Sultan-papagani/b62e00db887d703121301442eaf22762 to your computer and use it in GitHub Desktop.
Install curseforge mod packs with python
import json
from tkinter import filedialog
import shutil
import urllib.parse
import urllib.request
import os
def download(modId, fileId, fn):
url = f"https://www.curseforge.com/api/v1/mods/{modId}/files/{fileId}/download"
with urllib.request.urlopen(url) as response:
parsed_url_path = urllib.parse.urlparse(response.url).path
filename = os.path.basename(parsed_url_path)
if not os.path.exists(fn+"/"+filename):
with open(fn+"/"+filename, 'w+b') as f:
shutil.copyfileobj(response, f)
return fn+"/"+filename
else:
return f"skipping {filename}"
def find_manifest():
filename = filedialog.askopenfile(filetypes=[("manifest file","*.json")])
directory =filedialog.askdirectory(initialdir = "%APPDATA%/.minecraft/mods")
if filename != None and directory != None:
with open(filename.name, 'r') as file:
data = json.load(file)
for file_inf in data["files"]:
result = download(file_inf["projectID"], file_inf["fileID"], directory)
print(result)
find_manifest()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment