commit initial working script

main
salpynx 2024-07-31 22:40:22 +00:00
parent 6cc792cd5e
commit b7f8df867a
2 changed files with 63 additions and 1 deletions

View File

@ -1,3 +1,3 @@
# mcskin
Bash script to tetch and display a minecraft user's skin in ANSI colours in your terminal.
Bash script to fetch and display a minecraft user's skin in ANSI colours in your terminal.

62
mcskin 100755
View File

@ -0,0 +1,62 @@
#!/bin/bash
name=$1
view=${2:-"body"}
datestamp=$(date -I)
slim=/tmp/${name}_slim_${datestamp}.png
classic=/tmp/${name}_classic_${datestamp}.png
if [ -f $slim ]; then
skin=$slim
style=slim
w=3
elif [ -f $classic ]; then
skin=$classic
style=classic
w=4
else
uuid=$(curl -s https://api.mojang.com/users/profiles/minecraft/$name | jq -r .id)
textures=$(curl -s https://sessionserver.mojang.com/session/minecraft/profile/$uuid | jq -r '.properties[] | select(.name=="textures") | .value' | base64 -d)
#echo $textures
read url style <<< $(echo $textures | jq -r '.textures.SKIN | [.url, .metadata.model]|@tsv')
style=${style:-classic}
skin=/tmp/${name}_${style}_${datestamp}.png
rm /tmp/${name}_${style}_*.png
wget $url -O $skin
fi
main="-crop 8x8+8+8"
case $view in
all) main="";;
head) head="( +clone -copy 8x8+40+8 +8+8 ) -composite";;
body) main="( +clone -copy 8x8+40+8 +8+8 ) -composite
( +clone -copy 8x12+20+20 +8+16 ) -composite
( +clone -copy 4x12+44+20 +4+16 ) -composite
( +clone -copy 4x12+36+52 +16+16 ) -composite
( +clone -copy 4x12+20+52 +12+28 ) -composite
( +clone -copy 4x12+24+52 +8+28 ) -composite
( +clone -copy 8x12+20+36 +8+16 ) -composite
( +clone -copy 4x12+44+36 +4+16 ) -composite
( +clone -copy 4x12+52+52 +16+16 ) -composite
( +clone -copy 4x12+4+52 +12+28 ) -composite
( +clone -copy 4x12+4+36 +8+28 ) -composite
-crop 16x32+4+8
";
crop="rectangle 0,0 3,7 rectangle 12,0 15,7
rectangle 0,20 3,31 rectangle 12,20 15,31";
esac
convert $skin $head $main -compress none -depth 8 -fill black -draw "$crop" PNM:- | tail -n+4 | while read row; do
read row2
paste <(sed 's/\(\(\w*\s\)\{3\}\)/\1\n/g' <<< $row) <(sed 's/\(\(\w*\s\)\{3\}\)/\1\n/g' <<< $row2) | while read r g b R G B; do
if [ $r = "0" ] && [ $g = "0" ] && [ $b = "0" ]; then
printf "\e[0m "
else
printf "\e[38;2;$r;$g;$b;48;2;$R;$G;${B}m▀"
fi
done
echo -e "\e[0m"
done