HO HO HOTFIX!

Thank you Jon for showing me what shellcheck is/does (LMAO)

Also some in depth jq wizardry
This commit is contained in:
2023-12-25 06:15:44 -05:00
parent 8e7b75f817
commit 32c199af14
9 changed files with 96 additions and 109 deletions

View File

@ -5,7 +5,7 @@ DELAY=1
USE_DATE=false
function usage {
echo "./$(basename $0) [-t] [-s]"
echo "./$(basename "$0") [-t] [-s]"
echo "Mass tagger for Gelbooru"
echo "Tags existing pictures inside a folder"
echo " -h shows this help message"
@ -49,21 +49,21 @@ done
for FILE in *; do
echo "$FILE"
# GET MD5 HASH
FILE_MD5=`md5sum "$FILE" | awk '{print $1}'`
FILE_MD5=$(md5sum "$FILE" | awk '{print $1}')
# DOWNLOAD JSON
if $USE_TOR; then
JSON=`torsocks curl -s "https://gelbooru.com/index.php?page=dapi&s=post&q=index&json=1&tags=md5:$FILE_MD5" | jq .`
JSON=$(torsocks curl -s "https://gelbooru.com/index.php?page=dapi&s=post&q=index&json=1&tags=md5:$FILE_MD5" | jq .)
else
JSON=`curl -s "https://gelbooru.com/index.php?page=dapi&s=post&q=index&json=1&tags=md5:$FILE_MD5" | jq .`
JSON=$(curl -s "https://gelbooru.com/index.php?page=dapi&s=post&q=index&json=1&tags=md5:$FILE_MD5" | jq .)
fi
# STORE TAGS INTO VARIABLES
FILE_TAGS=`echo $JSON | jq -r '.post | .[] | ."tags"' | sed 's/\ /,/g'`
FILE_DATE=`echo $JSON | jq -r '.post | .[] | ."created_at"'`
FILE_TAGS=$(echo "$JSON" | jq -r '.post | .[] | ."tags"' | sed 's/\ /,/g')
FILE_DATE=$(echo "$JSON" | jq -r '.post | .[] | ."created_at"')
# ADD TAGS TO IMAGE
setfattr -n user.xdg.tags -v "$FILE_TAGS" "$FILE"
if $USE_DATE; then
touch -d "$FILE_DATE" "$FILE"
fi
# DELAY BEFORE NEXT FETCH
sleep $DELAY
sleep "$DELAY"
done