From 11ce6fa401e391292e1b95cd03757ecd10288f8f Mon Sep 17 00:00:00 2001 From: bronze Date: Fri, 29 Sep 2023 15:53:53 -0400 Subject: [PATCH] - Added Danbooru support - Added Moebooru (konachan and yande.re) support --- README.md | 26 +++++++++--------- dandl.sh | 69 +++++++++++++++++++++++++++++++++++++++++++++++ dantag.sh | 60 +++++++++++++++++++++++++++++++++++++++++ gelbdl.sh | 1 + gelbtag.sh | 1 + moedl.sh | 70 +++++++++++++++++++++++++++++++++++++++++++++++ moetag.sh | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 292 insertions(+), 14 deletions(-) create mode 100755 dandl.sh create mode 100644 dantag.sh create mode 100644 moedl.sh create mode 100755 moetag.sh diff --git a/README.md b/README.md index f9e2940..c2867ae 100644 --- a/README.md +++ b/README.md @@ -16,18 +16,16 @@ scripts for downloading and tagging images from booru websites `torsocks` if you're downloading through tor -``` -./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 -``` +## Scripts: -``` -./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 +`gelbdl.sh` downloads and tags files from every gelbooru link in files.txt + +`gelbtag.sh` hashes and looks up every image in a folder on gelbooru + +`dandl.sh` downloads and tags files from every danbooru link in files.txt + +`dantag.sh` hashes and looks up every image in a folder on danbooru + +`moedl.sh` downloads and tags files from moebooru imageboard (think konachan and yande.re) links in files.txt + +`moetag.sh` hashes and looks up every image in a folder (provided you specify the booru) \ No newline at end of file diff --git a/dandl.sh b/dandl.sh new file mode 100755 index 0000000..fc2897b --- /dev/null +++ b/dandl.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +USE_TOR=false +DELAY=1 + +function usage { + echo "./$(basename $0) [-t] [-s]" + echo "Mass downloader for Danbooru" + 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/\?q.*//g"` + # DOWNLOAD JSON + if $USE_TOR; then + JSON=`torsocks curl -s "$JSON_URL.json"` + else + JSON=`curl -s "$JSON_URL.json"` + fi + # STORE FILE URL AND TAGS INTO VARIABLES + FILE_URL=`echo $JSON | jq -r '."file_url"'` + FILE_TAGS=`echo $JSON | jq -r '."tag_string"' | sed 's/\ /,/g'` + FILE_MD5=`echo $JSON | jq -r '.md5'` + FILE_EXT=`echo $JSON | jq -r '.file_ext'` + FILE="$FILE_MD5.$FILE_EXT" + # 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/dantag.sh b/dantag.sh new file mode 100644 index 0000000..b4653c2 --- /dev/null +++ b/dantag.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +USE_TOR=false +DELAY=1 +SEARCH_URL="https://danbooru.donmai.us/posts.json?tags=md5" + +function usage { + echo "./$(basename $0) [-t] [-s]" + echo "Mass tagger for Danbooru" + 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 "$SEARCH_URL:$FILE_MD5"` + else + JSON=`curl -s "$SEARCH_URL:$FILE_MD5"` + fi + # STORE TAGS INTO VARIABLES + FILE_TAGS=`echo $JSON | jq -r '.[] | ."tag_string"' | sed 's/\ /,/g'` + # ADD TAGS TO IMAGE + setfattr -n user.xdg.tags -v "$FILE_TAGS" "$FILE" + # DELAY BEFORE NEXT FETCH + sleep $DELAY +done \ No newline at end of file diff --git a/gelbdl.sh b/gelbdl.sh index d92d380..9d8344c 100755 --- a/gelbdl.sh +++ b/gelbdl.sh @@ -5,6 +5,7 @@ DELAY=1 function usage { echo "./$(basename $0) [-t] [-s]" + echo "Mass downloader for Gelbooru" 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)" diff --git a/gelbtag.sh b/gelbtag.sh index f66b754..2cfdbcb 100755 --- a/gelbtag.sh +++ b/gelbtag.sh @@ -5,6 +5,7 @@ DELAY=1 function usage { echo "./$(basename $0) [-t] [-s]" + echo "Mass tagger for Gelbooru" echo "Tags existing pictures inside a folder" echo " -h shows this help message" echo " -t downloads using tor (requires torsocks)" diff --git a/moedl.sh b/moedl.sh new file mode 100644 index 0000000..6edd43e --- /dev/null +++ b/moedl.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +USE_TOR=false +DELAY=1 + +function usage { + echo "./$(basename $0) [-t] [-s]" + echo "Mass downloader for moebooru imageboards (think konachan and yande.re)" + 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" + # get ID from the URL + URL=`echo $f | sed 's/\// /g' | awk '{print $2}'` + IMAGE_ID=`echo $f | sed 's/\// /g' | awk '{print $5}'` + # DOWNLOAD JSON + if $USE_TOR; then + JSON=`torsocks curl -s "https://$URL/post.json?tags=id:$IMAGE_ID"` + else + JSON=`curl -s "https://$URL/post.json?tags=id:$IMAGE_ID"` + fi + # STORE FILE URL AND TAGS INTO VARIABLES + FILE_URL=`echo $JSON | jq -r '.[] | ."file_url"'` + FILE_TAGS=`echo $JSON | jq -r '.[] | ."tags"' | sed 's/\ /,/g'` + FILE=`echo $JSON | jq -r '.[] | ."file_url"' | sed 's/\// /g' | awk '{print $5}'` + FILE_WITHSPACE=`echo $JSON | jq -r '.[] | ."file_url"' | sed 's/\// /g' | awk '{print $5}' | sed 's/\%20/ /g'` + # 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" + mv "$FILE" "$FILE_WITHSPACE" + # DELAY BEFORE NEXT FETCH + sleep $DELAY +done < files.txt \ No newline at end of file diff --git a/moetag.sh b/moetag.sh new file mode 100755 index 0000000..12c3645 --- /dev/null +++ b/moetag.sh @@ -0,0 +1,79 @@ +#!/bin/bash + +USE_TOR=false +DELAY=1 +REQ_URL="" + +function usage { + echo "./$(basename $0) [-t] [-s]" + echo "Mass tagger for moebooru imageboards" + 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" + echo " -k uses konachan API for tagging" + echo " -y uses yande.re API for tagging" + echo " -c uses (CUSTOM.URL) API for tagging" +} + +# list of arguments expected in the input +optstring=":hts:kyc:" + +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 + ;; + k) + REQ_URL="https://konachan.com/post.json?tags=md5:" + echo "Using konachan API for tagging" + ;; + y) + REQ_URL="https://yande.re/post.json?tags=md5:" + echo "Using yande.re API for tagging" + ;; + c) + REQ_URL="https://$OPTARG/post.json?tags=md5:" + ;; + s) + DELAY="${OPTARG}" + ;; + :) + echo "$0: Must supply an argument to -$OPTARG." >&2 + exit 1 + ;; + ?) + echo "Invalid option: -${OPTARG}." + exit 2 + ;; + esac +done + +if [[ -z "$REQ_URL" ]]; then + echo "No imageboard selected. Exiting." + exit +fi + +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 "$REQ_URL$FILE_MD5"` + else + JSON=`curl -s "$REQ_URL$FILE_MD5"` + fi + # STORE TAGS INTO VARIABLES + FILE_TAGS=`echo $JSON | jq -r '.[] | ."tags"' | sed 's/\ /,/g'` + # ADD TAGS TO IMAGE + setfattr -n user.xdg.tags -v "$FILE_TAGS" "$FILE" + # DELAY BEFORE NEXT FETCH + sleep $DELAY +done