switch to cloudscraper and add uv files

This commit is contained in:
2025-11-01 00:07:08 +01:00
parent bbcc40da08
commit 1726a268e9
2 changed files with 31 additions and 55 deletions
+2 -4
View File
@@ -1,5 +1,3 @@
.env .env
build .build
dist .dist
main.spec
venv
+29 -51
View File
@@ -1,72 +1,63 @@
import requests
import os import os
from dotenv import load_dotenv from dotenv import load_dotenv
import inquirer import inquirer
import zipfile import zipfile
import cloudscraper
load_dotenv() load_dotenv()
scraper = cloudscraper.create_scraper()
headers = { headers = {
'x-api-key': os.getenv("CURSEFORGE_API_KEY") 'x-api-key': os.getenv("CURSEFORGE_API_KEY")
} }
input_name = input("Enter modpack name: ")
response = scraper.get(f'https://api.curseforge.com/v1/mods/search?gameId=432&searchFilter={input_name}', headers=headers)
data = response.json()
modpack_names = []
found = False found = False
selected_modpack_id = -1 selected_modpack_id = -1
modpack_names = []
for mod in data['data']:
modpack_url = mod['links']['websiteUrl']
if modpack_url.startswith("https://www.curseforge.com/minecraft/modpacks/"):
modpack_names.append(mod['name'])
found = True
else:
pass
def search_modpacks(query): if not found:
global data print("No modpack found with that name.")
global found else:
pass
response = requests.get(f'https://api.curseforge.com/v1/mods/search?gameId=432&searchFilter={query}', headers=headers) if found == True:
data = response.json() questions = [
for mod in data['data']: inquirer.List('name',
modpack_url = mod['links']['websiteUrl'] message="Select a modpack",
if modpack_url.startswith("https://www.curseforge.com/minecraft/modpacks/"): choices=modpack_names,
modpack_names.append(mod['name']) ),
found = True ]
if not found:
print("No modpack found with that name.")
return modpack_names
def select_modpacks(modpack_names):
if found == True:
questions = [
inquirer.List('name',
message="Select a modpack",
choices=modpack_names
),
]
answers = inquirer.prompt(questions) answers = inquirer.prompt(questions)
selected_modpack_name = answers['name'] selected_modpack_name = answers['name']
for mod in data['data']: for mod in data['data']:
if mod['name'] == selected_modpack_name: if mod['name'] == selected_modpack_name:
selected_modpack_id = mod['id'] selected_modpack_id = mod['id']
selected_url = mod['links']['websiteUrl']
return selected_modpack_name, selected_modpack_id r = scraper.get(f"https://api.curseforge.com/v1/mods/{selected_modpack_id}/files", headers = headers)
def download_modpack(selected_modpack_name, selected_modpack_id):
r = requests.get(f"https://api.curseforge.com/v1/mods/{selected_modpack_id}/files", headers = headers)
file_data = r.json() file_data = r.json()
for file in file_data['data']: for file in file_data['data']:
server_file_id = file['serverPackFileId'] server_file_id = file['serverPackFileId']
file = requests.get(f"https://www.api.curseforge.com/v1/mods/{selected_modpack_id}/files/{server_file_id}", headers=headers) file = scraper.get(f"https://www.api.curseforge.com/v1/mods/{selected_modpack_id}/files/{server_file_id}", headers=headers)
download_url = file.json()['data']['downloadUrl'] download_url = file.json()['data']['downloadUrl']
print(f"Download Url: {download_url}") print(f"Download Url: {download_url}")
dl_response = requests.get(download_url, stream=True) dl_response = scraper.get(download_url, stream=True)
with open(f"{selected_modpack_name}-server.zip", 'wb') as f: with open(f"{selected_modpack_name}-server.zip", 'wb') as f:
for chunk in dl_response.iter_content(chunk_size=8192): for chunk in dl_response.iter_content(chunk_size=8192):
f.write(chunk) f.write(chunk)
@@ -77,16 +68,3 @@ def download_modpack(selected_modpack_name, selected_modpack_id):
break break
else: else:
print("No server pack found for this modpack.") print("No server pack found for this modpack.")
if __name__ == "__main__":
print("Serverpack Downloader")
query = input("Enter Search Query: ")
modpack_names = search_modpacks(query)
selected_modpack_name, selected_modpack_id = select_modpacks(modpack_names)
download_modpack(selected_modpack_name, selected_modpack_id)