From edc4b7d685a300b7dfda89ab01eb2d897ffac5ae Mon Sep 17 00:00:00 2001 From: bronze Date: Fri, 29 Sep 2023 00:51:25 -0400 Subject: [PATCH] first commit --- .gitignore | 6 +++++ README.md | 26 ++++++++++++++++++++- gelbdl.sh | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ gelbtag.sh | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100755 gelbdl.sh create mode 100755 gelbtag.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fa82e06 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +files.txt +*.jpg +*.png +*.gif +*.mp4 +*.webm \ No newline at end of file diff --git a/README.md b/README.md index df5fe22..39a3999 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,27 @@ # booru-tools -scripts for downloading and tagging images from booru websites \ No newline at end of file +scripts for downloading and tagging images from booru websites + +stores tags in `user.xdg.tags` xattr + +tags work with KDE dolphin / KDE's baloo file indexer, idk about other desktop environments + +see https://wiki.archlinux.org/title/Extended_attributes + +These took me a whole morning to write. Its very much WIP... + +``` +./gelbdl.sh [-t] [-s] +Simply make a files.txt inside a folder and paste all your links, then run this script to download them all! + -h shows this help message + -t downloads using tor (requires torsocks) + -s sets the delay after each request, defaults to 1 +``` + +``` +./gelbtag.sh [-t] [-s] +Tags existing pictures inside a folder + -h shows this help message + -t downloads using tor (requires torsocks) + -s sets the delay after each request, defaults to 1 +``` \ No newline at end of file diff --git a/gelbdl.sh b/gelbdl.sh new file mode 100755 index 0000000..d92d380 --- /dev/null +++ b/gelbdl.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +USE_TOR=false +DELAY=1 + +function usage { + echo "./$(basename $0) [-t] [-s]" + echo "Simply make a files.txt inside a folder and paste all your links, then run this script to download them all!" + echo " -h shows this help message" + echo " -t downloads using tor (requires torsocks)" + 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 -n "Using Tor with IP: " + torsocks curl ip.me + ;; + s) + DELAY="${OPTARG}" + ;; + :) + echo "$0: Must supply an argument to -$OPTARG." >&2 + exit 1 + ;; + ?) + echo "Invalid option: -${OPTARG}." + exit 2 + ;; + esac +done + +while read f; do + echo "$f" + # MODIFY URL TO API CALL + JSON_URL=`echo $f | sed 's/page=post/page=dapi\&json=1\&q=index/g' | sed 's/s=view/s=post/g' | sed "s/\&tags.*//g"` + # DOWNLOAD JSON + if $USE_TOR; then + JSON=`torsocks curl -s $JSON_URL | jq .` + else + JSON=`curl -s $JSON_URL | jq .` + fi + # STORE FILE URL AND TAGS INTO VARIABLES + FILE_URL=`echo $JSON | jq -r '.post | .[] | ."file_url"'` + FILE_TAGS=`echo $JSON | jq -r '.post | .[] | ."tags"' | sed 's/\ /,/g'` + FILE=`echo $JSON | jq -r '.post | .[] | ."image"'` + # DOWNLOAD FILE + if $USE_TOR; then + torsocks curl -O -J $FILE_URL + else + curl -O -J $FILE_URL + fi + # ADD TAGS TO NEW IMAGE + setfattr -n user.xdg.tags -v "$FILE_TAGS" "$FILE" + # DELAY BEFORE NEXT FETCH + sleep $DELAY +done < files.txt \ No newline at end of file diff --git a/gelbtag.sh b/gelbtag.sh new file mode 100755 index 0000000..f66b754 --- /dev/null +++ b/gelbtag.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +USE_TOR=false +DELAY=1 + +function usage { + echo "./$(basename $0) [-t] [-s]" + echo "Tags existing pictures inside a folder" + echo " -h shows this help message" + echo " -t downloads using tor (requires torsocks)" + 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 -n "Using Tor with IP: " + torsocks curl ip.me + ;; + 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 + 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 .` + else + 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'` + # ADD TAGS TO IMAGE + setfattr -n user.xdg.tags -v "$FILE_TAGS" "$FILE" + # DELAY BEFORE NEXT FETCH + sleep $DELAY +done