Merge pull request #1 from Vxrtrauter/main

Improve structure in main.py, create requirements.txt and update README.
This commit is contained in:
KeksNino
2025-10-12 15:12:04 +02:00
committed by GitHub
3 changed files with 78 additions and 28 deletions
+28 -5
View File
@@ -1,10 +1,33 @@
# Serverpack-Downloader # Serverpack-Downloader
CLI Downloader to download server packs from curseforge CLI Downloader to download server packs from CurseForge
# IMPORTANT # IMPORTANT
add your own api key to the .env file Add your own CurseForge API-Key to an .env file
```bash
CURSEFORGE_API_KEY=YOUR_API_KEY
```
You can get your own through https://console.curseforge.com/
# Dependencies # Dependencies
dotenv python library \ ```bash
inquirer python library \ python-dotenv
requests python library inquirer
requests
```
Install with `pip install -r requirements.txt`
# Notes
If you get the following error, the Modpack you're trying to download most likely doesn't have a serverpack.
```bash
Traceback (most recent call last):
File "Serverpack-Downloader\main.py", line 90, in <module>
download_modpack(selected_modpack_name, selected_modpack_id)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "Serverpack-Downloader\main.py", line 64, in download_modpack
server_file_id = file['serverPackFileId']
```
+39 -15
View File
@@ -10,42 +10,53 @@ headers = {
'x-api-key': os.getenv("CURSEFORGE_API_KEY") 'x-api-key': os.getenv("CURSEFORGE_API_KEY")
} }
input_name = input("Enter modpack name: ")
response = requests.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']: def search_modpacks(query):
global data
global found
response = requests.get(f'https://api.curseforge.com/v1/mods/search?gameId=432&searchFilter={query}', headers=headers)
data = response.json()
for mod in data['data']:
modpack_url = mod['links']['websiteUrl'] modpack_url = mod['links']['websiteUrl']
if modpack_url.startswith("https://www.curseforge.com/minecraft/modpacks/"): if modpack_url.startswith("https://www.curseforge.com/minecraft/modpacks/"):
modpack_names.append(mod['name']) modpack_names.append(mod['name'])
found = True found = True
else: if not found:
pass
if not found:
print("No modpack found with that name.") print("No modpack found with that name.")
else:
pass
if found == True: return modpack_names
def select_modpacks(modpack_names):
if found == True:
questions = [ questions = [
inquirer.List('name', inquirer.List('name',
message="Select a modpack", message="Select a modpack",
choices=modpack_names, 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
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) r = requests.get(f"https://api.curseforge.com/v1/mods/{selected_modpack_id}/files", headers = headers)
file_data = r.json() file_data = r.json()
@@ -66,3 +77,16 @@ if found == True:
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)
+3
View File
@@ -0,0 +1,3 @@
python-dotenv
inquirer
requests