2024-06-05 17:55:55 +02:00
|
|
|
import os.path, sys, requests, base64
|
2020-09-06 13:29:59 +02:00
|
|
|
|
|
|
|
|
2023-09-06 16:39:11 +02:00
|
|
|
print("Downloading skins from skinsdb.terraqueststudio.net ...")
|
2020-06-07 13:39:57 +02:00
|
|
|
# Requesting all skins and their raw texture using the API
|
2023-09-06 16:39:11 +02:00
|
|
|
r = requests.get('http://skinsdb.terraqueststudios.net/api/v1/content?client=script&page=1&per_page=10000')
|
2020-06-07 13:39:57 +02:00
|
|
|
|
|
|
|
if r.status_code != 200:
|
|
|
|
sys.exit("Request failed!")
|
|
|
|
|
|
|
|
data = r.json()
|
|
|
|
count = 0
|
|
|
|
|
2023-09-06 16:39:11 +02:00
|
|
|
print("Writing skins")
|
2020-09-06 13:29:59 +02:00
|
|
|
|
|
|
|
|
2020-06-07 13:39:57 +02:00
|
|
|
for json in data["skins"]:
|
2020-09-10 11:08:49 +02:00
|
|
|
id = str(json["id"])
|
2020-09-06 13:29:59 +02:00
|
|
|
|
2024-06-05 17:55:55 +02:00
|
|
|
name = "character." + id
|
|
|
|
if True:
|
|
|
|
legacy_name = "character_" + id
|
|
|
|
if os.path.exists("../textures/" + legacy_name + ".png"):
|
|
|
|
name = legacy_name
|
|
|
|
|
|
|
|
|
2020-09-06 13:29:59 +02:00
|
|
|
# Texture file
|
|
|
|
raw_data = base64.b64decode(json["img"])
|
2024-06-05 17:55:55 +02:00
|
|
|
file = open("../textures/" + name + ".png", "wb")
|
2020-09-06 13:29:59 +02:00
|
|
|
file.write(bytearray(raw_data))
|
|
|
|
file.close()
|
|
|
|
|
|
|
|
# Meta file
|
2024-06-05 17:55:55 +02:00
|
|
|
meta_name = str(json["name"])
|
|
|
|
meta_author = str(json["author"])
|
|
|
|
meta_license = str(json["license"])
|
|
|
|
file = open("../meta/" + name + ".txt", "w")
|
|
|
|
file.write(meta_name + "\n" + meta_author + "\n" + meta_license + "\n")
|
2020-09-06 13:29:59 +02:00
|
|
|
file.close()
|
2024-06-05 17:55:55 +02:00
|
|
|
print("Added #%s Name: %s Author: %s License: %s" % (id, meta_name, meta_author, meta_license))
|
2020-09-06 13:29:59 +02:00
|
|
|
count += 1
|
|
|
|
|
2020-06-07 13:39:57 +02:00
|
|
|
print("Fetched " + str(count) + " skins!")
|