diff --git a/.gitignore b/.gitignore index 9b58f86..ad2363c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /.alt +/__pycache__ diff --git a/Better-Leaves-9.2.zip b/Better-Leaves-9.2.zip index ef674a6..23fef06 100644 Binary files a/Better-Leaves-9.2.zip and b/Better-Leaves-9.2.zip differ diff --git a/download_helper.py b/download_helper.py new file mode 100644 index 0000000..3703d37 --- /dev/null +++ b/download_helper.py @@ -0,0 +1,26 @@ +from os import path +from tqdm import tqdm +import requests + +def downloadFromModrinth(project_slug): + response = requests.get(f'https://api.modrinth.com/v2/project/{project_slug}/version') + latestFile = response.json()[0]['files'][0] + latestFileURL = latestFile['url'] + if len(latestFileURL) < 1: raise Exception(f'Could not get the latest version URL for {project_slug}') + + download_stream = requests.get(latestFileURL, stream=True) + file_name = latestFile['filename'] + file_path = 'input/texturepacks' + + print(f'Downloading texturepack: {project_slug} (Latest version: {file_name})') + location = path.join(file_path, file_name) + total = int(download_stream.headers.get('content-length', 0)) + with open(location, "wb") as handle, tqdm( + unit="kB", + desc=file_name, + total=total, + unit_scale=True, + unit_divisor=1024,) as progressbar: + for data in download_stream.iter_content(chunk_size=1024): + size = handle.write(data) + progressbar.update(size) diff --git a/gen_pack.py b/gen_pack.py index 05674e7..62be121 100644 --- a/gen_pack.py +++ b/gen_pack.py @@ -3,6 +3,7 @@ """This script can automatically generate blockstate and block model files, as well as textures for the Better Leaves Lite resourcepack.""" +# Depencency imports import argparse import json import os @@ -13,6 +14,9 @@ import random from PIL import Image from distutils.dir_util import copy_tree +# Local imports +from download_helper import downloadFromModrinth + minify = False # Utility functions @@ -517,6 +521,7 @@ if __name__ == '__main__': parser.add_argument('--legacy', '-l', action='store_true', help="Use legacy models (from 8.1) for all leaves") parser.add_argument('--programmer', '-p', action='store_true', help="Use programmer art textures") parser.add_argument('--minify', '-m', action='store_true', help="Minify all JSON output files") + parser.add_argument('--download', '-d', help="Downloads the requested resourcepack beforehand") args = parser.parse_args() print(f"Arguments: {args}") @@ -525,6 +530,7 @@ if __name__ == '__main__': print("https://github.com/TeamMidnightDust/BetterLeavesLite") print() if args.minify: minify = True + if args.download != None: downloadFromModrinth(args.download) # Loads overrides from the json file f = open('./input/overrides.json')