mirror of
https://github.com/minetest-mods/skinsdb.git
synced 2024-12-23 07:50:18 +01:00
updater/update_skins.py: Do not download preview files by default
This commit is contained in:
parent
b5ba66deca
commit
8799ba0bd5
@ -1,5 +1,8 @@
|
|||||||
import sys, requests, base64
|
import sys, requests, base64
|
||||||
|
|
||||||
|
download_preview = ( len (sys.argv) > 1 and sys.argv[1] == "with_preview" )
|
||||||
|
|
||||||
|
|
||||||
print("Downloading skins from minetest.fensta.bplaced.net ...")
|
print("Downloading skins from minetest.fensta.bplaced.net ...")
|
||||||
# Requesting all skins and their raw texture using the API
|
# Requesting all skins and their raw texture using the API
|
||||||
r = requests.get('http://minetest.fensta.bplaced.net/api/v2/get.json.php?getlist&page=1&per_page=999999999')
|
r = requests.get('http://minetest.fensta.bplaced.net/api/v2/get.json.php?getlist&page=1&per_page=999999999')
|
||||||
@ -10,35 +13,42 @@ if r.status_code != 200:
|
|||||||
data = r.json()
|
data = r.json()
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
print("Writing to file and downloading previews ...")
|
if download_preview:
|
||||||
|
print("Writing to file and downloading previews ...")
|
||||||
|
else:
|
||||||
|
print("Writing skins")
|
||||||
|
|
||||||
|
|
||||||
for json in data["skins"]:
|
for json in data["skins"]:
|
||||||
id = str(json["id"])
|
id = str(json["id"]).zfill(4)
|
||||||
# Downloading the preview of the skin
|
|
||||||
r2 = requests.get('http://minetest.fensta.bplaced.net/skins/1/' + id + ".png")
|
|
||||||
if r.status_code == 200:
|
|
||||||
preview = r2.content
|
|
||||||
# Read meta datas
|
|
||||||
name = str(json["name"])
|
|
||||||
author = str(json["author"])
|
|
||||||
license = str(json["license"])
|
|
||||||
# Texture file
|
# Texture file
|
||||||
raw_data = base64.b64decode(json["img"])
|
raw_data = base64.b64decode(json["img"])
|
||||||
file = open("../textures/character_" + id + ".png", "wb")
|
file = open("../textures/character_" + id + ".png", "wb")
|
||||||
file.write(bytearray(raw_data))
|
file.write(bytearray(raw_data))
|
||||||
file.close()
|
file.close()
|
||||||
# Preview file
|
|
||||||
file = open("../textures/character_" + id + "_preview.png", "wb")
|
|
||||||
file.write(bytearray(preview))
|
|
||||||
file.close()
|
|
||||||
# Meta file
|
# Meta file
|
||||||
|
name = str(json["name"])
|
||||||
|
author = str(json["author"])
|
||||||
|
license = str(json["license"])
|
||||||
file = open("../meta/character_" + id + ".txt", "w")
|
file = open("../meta/character_" + id + ".txt", "w")
|
||||||
file.write(name + "\n" + author + "\n" + license + "\n")
|
file.write(name + "\n" + author + "\n" + license + "\n")
|
||||||
file.close()
|
file.close()
|
||||||
print("Added #%s Name: %s Author: %s License: %s" % (id, name, author, license))
|
print("Added #%s Name: %s Author: %s License: %s" % (id, name, author, license))
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
|
if download_preview:
|
||||||
|
# Downloading the preview of the skin
|
||||||
|
r2 = requests.get('http://minetest.fensta.bplaced.net/skins/1/' + id + ".png")
|
||||||
|
if r2.status_code == 200:
|
||||||
|
# Preview file
|
||||||
|
preview = r2.content
|
||||||
|
file = open("../textures/character_" + id + "_preview.png", "wb")
|
||||||
|
file.write(bytearray(preview))
|
||||||
|
file.close()
|
||||||
else:
|
else:
|
||||||
print("Failed to download skin #" + id)
|
print("Failed to download skin preview #" + id)
|
||||||
|
|
||||||
|
|
||||||
print("Fetched " + str(count) + " skins!")
|
print("Fetched " + str(count) + " skins!")
|
||||||
|
Loading…
Reference in New Issue
Block a user