1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2025-01-27 02:00:29 +01:00

u_skins: cleanup scripts, make new Python one, compress textures

This commit is contained in:
Dorian Wouters 2016-07-04 18:51:11 +02:00
parent beb47c942f
commit 1b1f4b56ad
No known key found for this signature in database
GPG Key ID: 6E9DA8063322434B
74 changed files with 85 additions and 384 deletions

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,85 @@
#!/bin/env python2
from __future__ import print_function
import sys, os, subprocess
from os import listdir
from os.path import isfile, join, sep
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
def which(program):
import os
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"')
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
try:
from PIL import Image
except ImportError:
eprint("Could not import PIL, is it installed ?")
sys.exit(1)
uskins_path = "u_skins"
meta_path = join(uskins_path, "meta")
textures_path = join(uskins_path, "textures")
pngcrush = which('pngcrush')
optipng = which('optipng')
def process_copies(src, dst, copies):
for copy in copies:
srcrect = copy[0]
dstrect = copy[1]
flip = copy[2] if len(copy) > 2 else None
region = src.crop(srcrect)
if flip is not None:
region = region.transpose(flip)
dst.paste(region, dstrect)
def make_preview(src, dst):
skin = Image.open(src)
preview = Image.new('RGBA', (16, 32))
process_copies(skin, preview, [
[(8, 8, 16, 16), (4, 0)], # Head
[(44, 20, 48, 32), (0, 8)], # Left arm
[(44, 20, 48, 32), (12, 8), Image.FLIP_LEFT_RIGHT], # Right arm
[(20, 20, 28, 32), (4, 8)], # Body
[(4, 20, 8, 32), (4, 20)], # Left leg
[(4, 20, 8, 32), (8, 20), Image.FLIP_LEFT_RIGHT], # Right leg
])
overlay = Image.new('RGBA', (16, 32))
process_copies(skin, overlay, [
[(40, 8, 48, 16), (4, 0)], # Head
])
preview = Image.alpha_composite(preview, overlay)
preview.save(dst)
if optipng is not None:
p = subprocess.Popen([optipng, '-o7', '-quiet', dst])
p.wait()
elif pngcrush is not None:
p = subprocess.Popen([pngcrush, '-ow', '-s', dst])
p.wait()
if __name__ == '__main__':
metas = [f for f in listdir(meta_path) if
isfile(join(meta_path, f)) and
f.endswith(".txt")]
for meta in metas:
f = open(join(meta_path, meta), 'r')
metadata = f.read().splitlines()
f.close()
skin = meta[:-4]
print("Processing {} \"{}\" by {} ({})...".format(skin, metadata[0], metadata[1], metadata[2]))
make_preview(join(textures_path, skin + ".png"), join(textures_path, skin + "_preview.png"))

View File

@ -1,49 +0,0 @@
#!/bin/sh
# This script is used to generate the previews needed by the mod
# It requires blender with the latest python API (2.6x is tested)
# A script that works with older blenders and, maybe, without python, is available in older commits.
# This script can also use pngcrush and imagemagick to reduce output size,
# please enable them if you want to push to the git repository of the mod.
# Pngcrush output will be written to .previews/pngcrush_output
# Warning: any file in .previews/ and u_skins/textures might be deleted without asking.
PNGCRUSH=true
IMAGEMAGICK=true
cd .previews
rm ../u_skins/textures/character_*_preview*.png # Remove all previous previews
blender -b skin_previews.blend --python-text "Generate previews" > /dev/null
if $IMAGEMAGICK
then echo "Stripping metadata from generated files..."
else echo "Moving files..."
fi
rm -rf output # remove my output
mkdir -p output
for i in blender_out/character_*_00.png;
do
out_name=$(basename $i | sed -e 's/_00.png//g')
out_file=output/"$out_name"_preview.png
if $IMAGEMAGICK
then
convert -strip -resize 128x256 $i $out_file
else
mv $i $out_file
fi
done
#for i in blender_out/character_*_01.png;
#do
# out_name=$(basename $i | sed -e 's/_01.png//g')
# out_file=output/"$out_name"_preview_back.png
# if $IMAGEMAGICK
# then
# convert -strip -resize 32x64 $i $out_file
# else
# mv $i $out_file
# fi
#done
if $PNGCRUSH
then
echo "Running pngcrush..."
pngcrush -d ../u_skins/textures/ output/character_*_preview*.png 2> pngcrush_output
else mv output/character_*_preview*.png ../u_skins/textures/
fi
echo "Done !"

View File

@ -1,49 +0,0 @@
#!/bin/sh
# This script is used to generate the previews needed by the mod
# It requires blender with the latest python API (2.6x is tested)
# A script that works with older blenders and, maybe, without python, is available in older commits.
# This script can also use pngcrush and imagemagick to reduce output size,
# please enable them if you want to push to the git repository of the mod.
# Pngcrush output will be written to .previews/pngcrush_output
# Warning: any file in .previews/ and u_skins/textures might be deleted without asking.
PNGCRUSH=true
IMAGEMAGICK=true
cd .previews
rm ../u_skins/textures/mff_*_preview*.png # Remove all previous previews
blender -b mff_skin_previews.blend --python-text "Generate previews" > /dev/null
if $IMAGEMAGICK
then echo "Stripping metadata from generated files..."
else echo "Moving files..."
fi
rm -rf output # remove my output
mkdir -p output
for i in blender_out/mff_character_*_00.png
do
out_name=$(basename $i | sed -e 's/_00.png//g')
out_file=output/"$out_name"_preview.png
if $IMAGEMAGICK
then
convert -strip -resize 128x256 $i $out_file
else
mv $i $out_file
fi
done
#for i in blender_out/mff_character_*_01.png
#do
# out_name=$(basename $i | sed -e 's/_01.png//g')
# out_file=output/"$out_name"_preview_back.png
# if $IMAGEMAGICK
# then
# convert -strip -resize 32x64 $i $out_file
# else
# mv $i $out_file
# fi
#done
if $PNGCRUSH
then
echo "Running pngcrush..."
pngcrush -d ../u_skins/textures/ output/mff_*_preview*.png 2> pngcrush_output
else mv output/mff_*_preview*.png ../u_skins/textures/
fi
echo "Done !"

View File

@ -1 +0,0 @@
Please run the update_from_db.py script to update the skins.

View File

@ -1,42 +0,0 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys, os
# if used on windows ??
# use os.path.join() -> path sep win "\" or linux "/"
p_textures = os.path.join("u_skins", "textures")
p_meta = os.path.join("u_skins", "meta")
try:
f = open("removed_skins.txt", "r")
skins_exclued = f.readlines()
except IOError as err:
sys.stderr.write("%s\n" % err)
sys.exit(1)
else:
f.close()
print("il y a %d skins exclus." % len(skins_exclued))
for skin in skins_exclued:
# if not int value, ignore
try:
skin = "character_%s" % int(skin.strip())
except ValueError as err:
sys.stderr.write("%s\n" % err)
continue
# for texture, preview and meta files
for f_skin in ( os.path.join(p_textures,"%s.png" % skin),
os.path.join(p_textures,"%s_preview.png" % skin),
os.path.join(p_meta, "%s.txt" % skin) ):
if os.path.exists(f_skin):
try:
os.remove(f_skin)
except exception as err:
print(err)
pass
else:
print('skin "%s" effacé' % f_skin)
sys.exit(0)

View File

@ -1,59 +0,0 @@
#!/bin/bash
SPRITES=$(find -regextype sed -regex '.*/player_[0-9]\{1,\}.png' | sort -V)
MODELS=$(find -regextype sed -regex '.*/character_[0-9]\{1,\}.png' | sort -V)
function ask_for_meta {
convert $2 -scale 100x200 /tmp/skins_set_meta
SNAME=$(basename $1)
SNAME=${SNAME%.*}
METAFILE=u_skins/meta/$SNAME.txt
FORCE=$3
if $FORCE || ! [ -f $METAFILE ]
then
echo $METAFILE
YADOUT=$(yad --form --image=/tmp/skins_set_meta --field $SNAME:LBL --field=Name --field=Author --field=Description --field=Comment)
if [ -z "$YADOUT" ]; then exit; fi # canceled
OIFS="$IFS"
IFS='|'
read -a VALUES <<< "$YADOUT"
IFS="$OIFS"
NAME=${VALUES[1]}
AUTHOR=${VALUES[2]}
DESCRIPTION=${VALUES[3]}
COMMENT=${VALUES[4]}
if [ -n "$NAME" ] && [ -n "$AUTHOR" ]
then
echo -n > $METAFILE # clear it
echo 'name = "'$NAME'",' >> $METAFILE
echo 'author = "'$AUTHOR'",' >> $METAFILE
# only write description and comment if they are specified
if [ -n "$DESCRIPTION" ]
then
echo 'description = "'$DESCRIPTION'",' >> $METAFILE
fi
if [ -n "$COMMENT" ]
then
echo 'comment = "'$COMMENT'",' >> $METAFILE
fi
echo "Saved !"
fi
fi
}
if [ -z $1 ]
then
for i in $SPRITES
do
ask_for_meta $i $i false
done
for i in $MODELS
do
ask_for_meta $i ${i%.*}_preview.png false
done
else
if [ -f ${1%.*}_preview.png ]
then
ask_for_meta $1 ${1%.*}_preview.png true
else
ask_for_meta $1 $1 true
fi
fi
rm /tmp/skins_set_meta

BIN
mods/u_skins/u_skins/textures/character_1.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 876 B

BIN
mods/u_skins/u_skins/textures/character_11_preview.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 762 B

BIN
mods/u_skins/u_skins/textures/character_12_preview.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 387 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 989 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 807 B

BIN
mods/u_skins/u_skins/textures/character_15_preview.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 325 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 662 B

BIN
mods/u_skins/u_skins/textures/character_17_preview.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 283 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 495 B

BIN
mods/u_skins/u_skins/textures/character_19_preview.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 600 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 800 B

BIN
mods/u_skins/u_skins/textures/character_2.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
mods/u_skins/u_skins/textures/character_20_preview.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 744 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 575 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 490 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
mods/u_skins/u_skins/textures/character_24.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 704 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 424 B

BIN
mods/u_skins/u_skins/textures/character_26_preview.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 744 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 471 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 854 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 705 B

BIN
mods/u_skins/u_skins/textures/character_3.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 604 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 808 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 928 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 386 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 446 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 599 B

BIN
mods/u_skins/u_skins/textures/character_38_preview.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 514 B

BIN
mods/u_skins/u_skins/textures/character_39_preview.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 406 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

BIN
mods/u_skins/u_skins/textures/character_4.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 232 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 604 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 485 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 744 B

BIN
mods/u_skins/u_skins/textures/character_8_preview.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 915 B

BIN
mods/u_skins/u_skins/textures/character_9_preview.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 890 B

BIN
mods/u_skins/u_skins/textures/mff_character_1.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 1010 B

BIN
mods/u_skins/u_skins/textures/mff_character_2.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 850 B

BIN
mods/u_skins/u_skins/textures/mff_character_2_preview.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 355 B

BIN
mods/u_skins/u_skins/textures/mff_character_3.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 976 B

BIN
mods/u_skins/u_skins/textures/mff_character_4.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 432 B

After

Width:  |  Height:  |  Size: 260 B

BIN
mods/u_skins/u_skins/textures/mff_character_4_preview.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 127 B

BIN
mods/u_skins/u_skins/textures/mff_character_5.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 772 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 394 B

BIN
mods/u_skins/u_skins/textures/mff_character_6.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

BIN
mods/u_skins/u_skins/textures/mff_character_6_preview.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

BIN
mods/u_skins/u_skins/textures/mff_character_7.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

BIN
mods/u_skins/u_skins/textures/mff_character_7_preview.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 987 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
mods/u_skins/u_skins/textures/mff_character_9_preview.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.6 KiB

After

Width:  |  Height:  |  Size: 339 B

View File

@ -1,61 +0,0 @@
#!/usr/bin/python3
from http.client import HTTPConnection
import json
import base64
server = "minetest.fensta.bplaced.net"
skinsdir = "u_skins/textures/"
metadir = "u_skins/meta/"
i = 1
pages = 1
c = HTTPConnection(server)
def addpage(page):
global i, pages
print("Page: " + str(page))
r = 0
try:
c.request("GET", "/api/get.json.php?getlist&page=" + str(page) + "&outformat=base64")
r = c.getresponse()
except Exception:
if r != 0:
if r.status != 200:
print("Error", r.status)
exit(r.status)
return
data = r.read().decode()
l = json.loads(data)
if not l["success"]:
print("Success != True")
exit(1)
r = 0
pages = int(l["pages"])
for s in l["skins"]:
f = open(skinsdir + "character_" + str(i) + ".png", "wb")
f.write(base64.b64decode(bytes(s["img"], 'utf-8')))
f.close()
f = open(metadir + "character_" + str(i) + ".txt", "w")
f.write(str(s["name"]) + '\n')
f.write(str(s["author"]) + '\n')
f.write(str(s["license"]))
f.close()
try:
c.request("GET", "/skins/1/" + str(s["id"]) + ".png")
r = c.getresponse()
except Exception:
if r != 0:
if r.status != 200:
print("Error", r.status)
continue
data = r.read()
f = open(skinsdir + "character_" + str(i) + "_preview.png", "wb")
f.write(data)
f.close()
i = i + 1
addpage(1)
if pages > 1:
for p in range(pages-1):
addpage(p+2)
print("Skins have been updated!")

View File

@ -1,45 +0,0 @@
#!/usr/bin/python3
#from http.client import HTTPConnection
import json
import base64
import requests
server = "minetest.fensta.bplaced.net"
skinsdir = "u_skins/textures/"
metadir = "u_skins/meta/"
i = 1
pages = 0
#c = HTTPConnection(server)
def addpage(page):
global i, pages
print( "Page: "+str(page))
try:
#c.request("GET","/api/get.json.php?getlist&page="+str(page)+"&outformat=base64")
#r = c.getresponse()
r = requests.get("http://"+str(server)+"/api/get.json.php?getlist&page="+str(page)+"&outformat=base64")
except StandardError:
print("Error", r.status)
exit(r.status)
data = r.text
l = json.loads(data)
if not l["success"]:
print("Success != True")
exit(1)
pages = int(l["pages"])
for s in l["skins"]:
f = open(skinsdir+"character_"+str(i)+".png",'wb')
f.write(base64.b64decode(s["img"]))
f.close()
f = open(metadir+"character_"+str(i)+".txt",'w')
f.write('name = "'+s["name"]+'",\n')
f.write('author = "'+s["author"]+'",\n')
f.write('comment = "'+s["license"]+'",\n')
f.close()
i = i + 1
addpage(1)
if pages > 1:
for p in range(pages-1):
addpage(p+2)
print("Skins have been updated. Please run ./generate_previews.sh")

View File

@ -1,78 +0,0 @@
#!/bin/bash
####
# Licenced under Attribution-NonCommercial-ShareAlike 4.0 International
# http://creativecommons.org/licenses/by-nc-sa/4.0/
#### ATTENTION ####
## This script requires that jq and coreutils are installed on your system ##
## In Debian-based distros, open a terminal and run
## sudo apt-get install jq coreutils
###################
# == Set variables ===
# ====================
NUMPAGES="1" # Number of pages. Default is 1 page
PERPAGE="2000" # Number of items per page. Default is 2000.
JSONURL="http://minetest.fensta.bplaced.net/api/get.json.php?getlist&page=$NUMPAGES&outformat=base64&per_page=$PERPAGE" # The URL to the database
PREVIEWURL="http://minetest.fensta.bplaced.net/skins/1/" # The url to the location of the previews.
temp=$PWD/tmp # Where the temp folder will be. Default is $PWD/tmp, which means that the tmp folder will be put in the current folder
METADEST=$PWD/u_skins/meta # This is the folder where the meta data will be saved
TEXTUREDEST=$PWD/u_skins/textures # This is the folder where the skins and the previews will be saved
# === Make a bunch of folders and download the db ===
# ===================================================
if [ -d "$temp" ]; then
rm -r $temp # If the temp dir exists we will remove it and its contents.
fi
mkdir $temp # Make a new temp dir. Redundant? No. We will get rid of it later.
if [ ! -d "$METADEST" ]; then # Check to see if the meta dir exists, and if not, create it
mkdir $METADEST
fi
if [ ! -d "$TEXTUREDEST" ]; then # Check to see if the textures dir exists, and if not, create it
mkdir $TEXTUREDEST
fi
wget $JSONURL -O $temp/rawdb.txt # Download the entire database
# === Do the JSON thing ===
# =========================
i="0" # This will be the counter.
while [ "$ID" != "null" ] # Repeat for as long as there is data to process
do
ID=$(cat $temp/rawdb.txt | jq ".skins[$i].id")
# The next lines are kinda complex. sed is being used to strip the quotes from the variables. I had help...
meta_name=$(echo $(cat $temp/rawdb.txt | jq ".skins[$i].name") | sed -e 's/^"//' -e 's/"$//')
meta_author=$(echo $(cat $temp/rawdb.txt | jq ".skins[$i].author") | sed -e 's/^"//' -e 's/"$//')
meta_license=$(echo $(cat $temp/rawdb.txt | jq ".skins[$i].license") | sed -e 's/^"//' -e 's/"$//')
if [[ "$ID" != "null" ]]; then # Check to see if ID has a value
echo "#"$ID "name:" $meta_name "author:" $meta_author "license:" $meta_license # Verbosity to show that the script is working.
echo $meta_name > $METADEST/character_$ID.txt # Save the meta data to files, this line overwrites the data inside the file
echo $meta_author >> $METADEST/character_$ID.txt # Save the meta data to files, this line is added to the file
echo $meta_license >> $METADEST/character_$ID.txt # Save the meta data to files, and this line is added to the file as well.
# === Extract and save the image from the JSON file ===
# ======================================================
skin=$(echo $(cat $temp/rawdb.txt | jq ".skins[$i].img") | sed -e 's/^"//' -e 's/"$//') # Strip the quotes from the base64 encoded string
echo $skin | base64 --decode > $TEXTUREDEST"/character_"$ID".png" # Decode the string, and save it as a .png file
# === Download a preview image whilst we're at it ===
# ====================================================
wget -nv $PREVIEWURL/$ID".png" -O $TEXTUREDEST"/character_"$ID"_preview.png" # Downloads a preview of the skin that we just saved.
fi
i=$[$i+1] # Increase the counter by one.
done
# === Now we'll clean up the mess ===
# ===================================
rm -r $temp # Remove the temp dir and its contents.
exit # Not strictly needed, but i like to use it to wrap things up.