Skip to content

Commit

Permalink
Update cmpdl.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Advik-B committed May 21, 2024
1 parent f6408bc commit ad6ef2c
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions curseforge/cli/cmpdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import re

CURSEFORGE_URL_REGEX = re.compile(r"https?://(?:www\.)?curseforge\.com/minecraft/modpacks/([a-zA-Z0-9\-_]+)")
CURSEFORGE_URL_FILES = re.compile(r"https?://(?:www\.)?curseforge\.com/minecraft/modpacks/[a-zA-Z0-9\-_]+/files/([0-9]+)")


class Program():
def __init__(
Expand Down Expand Up @@ -45,9 +47,32 @@ def run(self) -> None:
if self.SOURCE_MODE == "curseforge":
self.dprintf("Downloading modpack from CurseForge")
modpack_id = CURSEFORGE_URL_REGEX.match(self.src).group(1)
file_iead = CURSEFORGE_URL_FILES.match(self.src).group(1)
self.dprintf("Modpack ID:", modpack_id)
mpack_id: int
file_id: int
if modpack_id.isalpha():
self.dprintf("Modpack ID is alpha, assuming slug")
mpack = self.client.addon_from_slug(modpack_id)
print(mpack)
self.dprintf("Modpack:", mpack)
self.dprintf("Modpack ID is a slug, converting to ID")
mpack_id = self.client.addon_from_slug(modpack_id).id

else:
mpack_id = int(modpack_id)

self.dprintf("Modpack ID:", mpack_id)
self.dprintf("Fetching modpack data")
if file_iead is not None:
file_id = int(file_iead)
else:
file_id = self.client.addon(mpack_id).latestFiles[0].id

self.dprintf("File ID:", file_id)
self.dprintf("Downloading modpack")
self.download_modpack(mpack_id, file_id)

elif self.SOURCE_MODE == "url":
self.dprintf("Downloading modpack from URL")
self.dprintf("Fetching URL")
self.dprintf("Downloading modpack")
self.download_modpack_from_url(self.src)

def download_modpack(self, modpack_id: int, file_id: int):

0 comments on commit ad6ef2c

Please sign in to comment.