2023-12-25 08:20:20 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
USE_TOR=false
|
|
|
|
DELAY=1
|
|
|
|
UA="Booru-Tools/0.1"
|
|
|
|
|
|
|
|
function usage {
|
2023-12-25 11:15:44 +00:00
|
|
|
echo "./$(basename "$0") [-t] [-s]"
|
2023-12-25 08:20:20 +00:00
|
|
|
echo "Tags existing pictures inside a folder"
|
|
|
|
echo " -h shows this help message"
|
|
|
|
echo " -t e621 BLOCKS TOR WITH CLOUDFLARE, DOES NOT WORK"
|
|
|
|
echo " -s sets the delay after each request, defaults to 1"
|
|
|
|
}
|
|
|
|
|
|
|
|
# list of arguments expected in the input
|
|
|
|
optstring=":hts:"
|
|
|
|
|
|
|
|
while getopts ${optstring} arg; do
|
|
|
|
case ${arg} in
|
|
|
|
h)
|
|
|
|
usage
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
t)
|
|
|
|
USE_TOR=true
|
|
|
|
echo "e621 BLOCKS TOR WITH CLOUDFLARE"
|
|
|
|
echo "EXITING SINCE SCRIPT WILL NOT WORK"
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
s)
|
|
|
|
DELAY="${OPTARG}"
|
|
|
|
;;
|
|
|
|
:)
|
|
|
|
echo "$0: Must supply an argument to -$OPTARG." >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
?)
|
|
|
|
echo "Invalid option: -${OPTARG}."
|
|
|
|
exit 2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
for FILE in *; do
|
|
|
|
echo "$FILE"
|
|
|
|
# GET MD5 HASH
|
2023-12-25 11:15:44 +00:00
|
|
|
FILE_MD5=$(md5sum "$FILE" | awk '{print $1}')
|
|
|
|
echo "$FILE_MD5"
|
2023-12-25 08:20:20 +00:00
|
|
|
# DOWNLOAD JSON
|
|
|
|
if $USE_TOR; then
|
|
|
|
#JSON=`torsocks curl -A "$UA" -s "https://e621.net/posts.json?tags=md5:$FILE_MD5"`
|
|
|
|
echo "e621 BLOCKS TOR WITH CLOUDFLARE"
|
|
|
|
echo "EXITING SINCE SCRIPT WILL NOT WORK"
|
|
|
|
exit
|
|
|
|
else
|
2023-12-25 11:15:44 +00:00
|
|
|
JSON=$(curl -s -A "$UA" "https://e621.net/posts.json?limit=1&tags=md5:$FILE_MD5")
|
2023-12-25 08:20:20 +00:00
|
|
|
fi
|
2023-12-25 11:15:44 +00:00
|
|
|
# ONE JQ TO RULE THEM ALL (modified)
|
|
|
|
FILE_TAGS=$(jq -r '.posts | .[] | ."tags" | reduce to_entries[] as $arr ([]; . + [ $arr.value[] | gsub("[\"\\[\\]\\s]"; "", "g") ] ) | join(",")' - <<< "$JSON")
|
|
|
|
#echo "$FILE_TAGS"
|
2023-12-25 08:20:20 +00:00
|
|
|
# ADD TAGS TO IMAGE
|
|
|
|
setfattr -n user.xdg.tags -v "$FILE_TAGS" "$FILE"
|
|
|
|
# DELAY BEFORE NEXT FETCH
|
2023-12-25 11:15:44 +00:00
|
|
|
sleep "$DELAY"
|
2023-12-25 08:20:20 +00:00
|
|
|
done
|