mirror of
https://github.com/minetest-mods/skinsdb.git
synced 2024-12-22 23:40:18 +01:00
Add python skin update script (#48)
This commit is contained in:
parent
55704e1657
commit
1fcd3c4a8c
14
README.md
14
README.md
@ -18,7 +18,9 @@ This Minetest mod offers changeable player skins with a graphical interface for
|
||||
|
||||
## Installing skins
|
||||
|
||||
### Download from the database
|
||||
### Download from the [database](http://minetest.fensta.bplaced.net/)
|
||||
|
||||
#### Ingame Downloader
|
||||
|
||||
1) Get Minetest 5.1.0-dev-cb00632 or newer
|
||||
2) Start your world
|
||||
@ -28,6 +30,16 @@ This Minetest mod offers changeable player skins with a graphical interface for
|
||||
|
||||
You might want to run `minetest` in a Terminal/Console window to check the log output instantly.
|
||||
|
||||
#### Python Download script
|
||||
|
||||
**Requirements:**
|
||||
|
||||
* Python 3
|
||||
* `requests` library: `pip3 install requests`
|
||||
|
||||
Go to the updater folder of this mod and run `python3 update_skins.py`
|
||||
The Script will download all the skins from the database for you.
|
||||
|
||||
### Manual addition
|
||||
|
||||
1) Copy your skin textures to `textures` as documented in `textures/readme.txt`
|
||||
|
44
updater/update_skins.py
Normal file
44
updater/update_skins.py
Normal file
@ -0,0 +1,44 @@
|
||||
import sys, requests, base64
|
||||
|
||||
print("Downloading skins from minetest.fensta.bplaced.net ...")
|
||||
# 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')
|
||||
|
||||
if r.status_code != 200:
|
||||
sys.exit("Request failed!")
|
||||
|
||||
data = r.json()
|
||||
count = 0
|
||||
|
||||
print("Writing to file and downloading previews ...")
|
||||
for json in data["skins"]:
|
||||
id = str(json["id"])
|
||||
# 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
|
||||
raw_data = base64.b64decode(json["img"])
|
||||
file = open("../textures/character_" + id + ".png", "wb")
|
||||
file.write(bytearray(raw_data))
|
||||
file.close()
|
||||
# Preview file
|
||||
file = open("../textures/character_" + id + "_preview.png", "wb")
|
||||
file.write(bytearray(preview))
|
||||
file.close()
|
||||
# Meta file
|
||||
file = open("../meta/character_" + id + ".txt", "w")
|
||||
file.write(name + "\n" + author + "\n" + license + "\n")
|
||||
file.close()
|
||||
print("Added #%s Name: %s Author: %s License: %s" % (id, name, author, license))
|
||||
count += 1
|
||||
|
||||
else:
|
||||
print("Failed to download skin #" + id)
|
||||
|
||||
|
||||
print("Fetched " + str(count) + " skins!")
|
Loading…
Reference in New Issue
Block a user