2014-10-08 16:31:14 +02:00
|
|
|
#!/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.
|
2016-09-05 21:02:53 +02:00
|
|
|
curpath="$(dirname $0)" # all path are relative to this script place
|
|
|
|
temp="$curpath"/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="$curpath"/../meta # This is the folder where the meta data will be saved
|
|
|
|
TEXTUREDEST="$curpath"/../textures # This is the folder where the skins and the previews will be saved
|
2014-10-08 16:31:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
# === 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
|
2016-10-18 23:23:10 +02:00
|
|
|
mkdir "$temp" # Make a new temp dir. Redundant? No. We will get rid of it later.
|
2014-10-08 16:31:14 +02:00
|
|
|
|
|
|
|
if [ ! -d "$METADEST" ]; then # Check to see if the meta dir exists, and if not, create it
|
2016-10-18 23:23:10 +02:00
|
|
|
mkdir "$METADEST"
|
2014-10-08 16:31:14 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d "$TEXTUREDEST" ]; then # Check to see if the textures dir exists, and if not, create it
|
2016-10-18 23:23:10 +02:00
|
|
|
mkdir "$TEXTUREDEST"
|
2014-10-08 16:31:14 +02:00
|
|
|
fi
|
|
|
|
|
2016-10-18 23:23:10 +02:00
|
|
|
wget "$JSONURL" -O "$temp"/rawdb.txt # Download the entire database
|
2014-10-08 16:31:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
# === 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
|
2016-10-18 23:23:10 +02:00
|
|
|
ID=$(cat "$temp"/rawdb.txt | jq ".skins[$i].id")
|
|
|
|
|
2014-10-08 16:31:14 +02:00
|
|
|
# The next lines are kinda complex. sed is being used to strip the quotes from the variables. I had help...
|
2016-10-18 23:23:10 +02:00
|
|
|
meta_name="$(jq ".skins[$i].name" < "$temp"/rawdb.txt | sed 's/^"//;s/"$//')"
|
|
|
|
meta_author="$(jq ".skins[$i].author" <"$temp"/rawdb.txt | sed 's/^"//;s/"$//')"
|
|
|
|
meta_license="$(jq ".skins[$i].license" <"$temp"/rawdb.txt | sed 's/^"//;s/"$//')"
|
|
|
|
|
2014-10-08 16:31:14 +02:00
|
|
|
if [[ "$ID" != "null" ]]; then # Check to see if ID has a value
|
2016-10-18 23:23:10 +02:00
|
|
|
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.
|
|
|
|
|
|
|
|
|
2014-10-08 16:31:14 +02:00
|
|
|
# === Extract and save the image from the JSON file ===
|
|
|
|
# ======================================================
|
2016-10-18 23:23:10 +02:00
|
|
|
skin=$(jq ".skins[$i].img" < "$temp"/rawdb.txt | sed 's/^"//;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
|
|
|
|
|
2014-10-08 16:31:14 +02:00
|
|
|
# === Download a preview image whilst we're at it ===
|
|
|
|
# ====================================================
|
2016-10-18 23:23:10 +02:00
|
|
|
wget -nv "$PREVIEWURL/$ID".png -O "$TEXTUREDEST"/character_"$ID"_preview.png # Downloads a preview of the skin that we just saved.
|
|
|
|
|
2014-10-08 16:31:14 +02:00
|
|
|
fi
|
|
|
|
i=$[$i+1] # Increase the counter by one.
|
|
|
|
done
|
|
|
|
|
|
|
|
# === Now we'll clean up the mess ===
|
|
|
|
# ===================================
|
2016-10-18 23:23:10 +02:00
|
|
|
rm -r "$temp" # Remove the temp dir and its contents.
|
2014-10-08 16:31:14 +02:00
|
|
|
|
|
|
|
exit # Not strictly needed, but i like to use it to wrap things up.
|