mirror of
https://github.com/TeamMidnightDust/BetterLeavesLite.git
synced 2025-12-15 12:05:09 +01:00
feat: download packs from any link before compiling
This commit is contained in:
@@ -10,7 +10,7 @@ import time
|
|||||||
|
|
||||||
# Local imports
|
# Local imports
|
||||||
from src.generator import autoGen
|
from src.generator import autoGen
|
||||||
from src.download_helper import downloadFromModrinth
|
from src.download_helper import downloadPack
|
||||||
from src.zip_utils import makeZip
|
from src.zip_utils import makeZip
|
||||||
import src.json_utils
|
import src.json_utils
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ if __name__ == '__main__':
|
|||||||
print("https://github.com/TeamMidnightDust/BetterLeavesLite")
|
print("https://github.com/TeamMidnightDust/BetterLeavesLite")
|
||||||
print()
|
print()
|
||||||
if args.minify: src.json_utils.minify = True
|
if args.minify: src.json_utils.minify = True
|
||||||
if args.download != None: downloadFromModrinth(args.download)
|
if args.download != None: downloadPack(args.download)
|
||||||
|
|
||||||
# Loads overrides from the json file
|
# Loads overrides from the json file
|
||||||
f = open('./input/overrides.json')
|
f = open('./input/overrides.json')
|
||||||
|
|||||||
@@ -1,18 +1,28 @@
|
|||||||
from os import path
|
from os import path
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
import requests
|
import requests
|
||||||
|
import re
|
||||||
|
|
||||||
|
def downloadPack(input: str):
|
||||||
|
if re.search("(http://*)|(https://*)", input) != None and input.endswith(".zip"):
|
||||||
|
downloadZip(input)
|
||||||
|
else:
|
||||||
|
downloadFromModrinth(input)
|
||||||
|
|
||||||
def downloadFromModrinth(project_slug):
|
def downloadFromModrinth(project_slug):
|
||||||
response = requests.get(f'https://api.modrinth.com/v2/project/{project_slug}/version')
|
response = requests.get(f'https://api.modrinth.com/v2/project/{project_slug}/version')
|
||||||
latestFile = response.json()[0]['files'][0]
|
latestFile = response.json()[0]['files'][0]
|
||||||
latestFileURL = latestFile['url']
|
latestFileURL = latestFile['url']
|
||||||
if len(latestFileURL) < 1: raise Exception(f'Could not get the latest version URL for {project_slug}')
|
if len(latestFileURL) < 1: raise Exception(f'Could not get the latest version URL for {project_slug}')
|
||||||
|
downloadZip(latestFileURL, file_name=latestFile['filename'], pack_name=project_slug)
|
||||||
|
|
||||||
download_stream = requests.get(latestFileURL, stream=True)
|
def downloadZip(url, file_name="", pack_name=""):
|
||||||
file_name = latestFile['filename']
|
download_stream = requests.get(url, stream=True)
|
||||||
|
if file_name == "": file_name = url.split("/")[-1]
|
||||||
|
if pack_name == "": pack_name = url
|
||||||
file_path = 'input/texturepacks'
|
file_path = 'input/texturepacks'
|
||||||
|
|
||||||
print(f'Downloading texturepack: {project_slug} (Latest version: {file_name})')
|
print(f'Downloading texturepack: {pack_name} (Latest version: {file_name})')
|
||||||
location = path.join(file_path, file_name)
|
location = path.join(file_path, file_name)
|
||||||
total = int(download_stream.headers.get('content-length', 0))
|
total = int(download_stream.headers.get('content-length', 0))
|
||||||
with open(location, "wb") as handle, tqdm(
|
with open(location, "wb") as handle, tqdm(
|
||||||
|
|||||||
Reference in New Issue
Block a user