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:
parent
8e7b75f817
commit
32c199af14
25
dandl.sh
25
dandl.sh
@ -4,7 +4,7 @@ USE_TOR=false
|
||||
DELAY=1
|
||||
|
||||
function usage {
|
||||
echo "./$(basename $0) [-t] [-s]"
|
||||
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"
|
||||
@ -40,21 +40,22 @@ while getopts ${optstring} arg; do
|
||||
esac
|
||||
done
|
||||
|
||||
while read f; do
|
||||
while read -r f; do
|
||||
echo "$f"
|
||||
# MODIFY URL TO API CALL
|
||||
JSON_URL=`echo $f | sed "s/\?q.*//g"`
|
||||
# shellcheck disable=SC2001
|
||||
JSON_URL=$(echo "$f" | sed "s/\?q.*//g")
|
||||
# DOWNLOAD JSON
|
||||
if $USE_TOR; then
|
||||
JSON=`torsocks curl -s "$JSON_URL.json"`
|
||||
JSON=$(torsocks curl -s "$JSON_URL.json")
|
||||
else
|
||||
JSON=`curl -s "$JSON_URL.json"`
|
||||
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_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
|
||||
@ -63,8 +64,8 @@ while read f; do
|
||||
curl -O -J "$FILE_URL"
|
||||
fi
|
||||
# ADD TAGS TO NEW IMAGE
|
||||
setfattr -n user.xdg.tags -v "$FILE_TAGS" "$FILE_MD5"*
|
||||
setfattr --name=user.checksum --value="$FILE_MD5" "$FILE_MD5"*
|
||||
setfattr -n user.xdg.tags -v "$FILE_TAGS" "$FILE"
|
||||
setfattr --name=user.checksum --value="$FILE_MD5" "$FILE"
|
||||
# DELAY BEFORE NEXT FETCH
|
||||
sleep $DELAY
|
||||
sleep "$DELAY"
|
||||
done < files.txt
|
12
dantag.sh
12
dantag.sh
@ -5,7 +5,7 @@ DELAY=1
|
||||
SEARCH_URL="https://danbooru.donmai.us/posts.json?tags=md5"
|
||||
|
||||
function usage {
|
||||
echo "./$(basename $0) [-t] [-s]"
|
||||
echo "./$(basename "$0") [-t] [-s]"
|
||||
echo "Mass tagger for Danbooru"
|
||||
echo "Tags existing pictures inside a folder"
|
||||
echo " -h shows this help message"
|
||||
@ -44,17 +44,17 @@ 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 "$SEARCH_URL:$FILE_MD5"`
|
||||
JSON=$(torsocks curl -s "$SEARCH_URL:$FILE_MD5")
|
||||
else
|
||||
JSON=`curl -s "$SEARCH_URL:$FILE_MD5"`
|
||||
JSON=$(curl -s "$SEARCH_URL:$FILE_MD5")
|
||||
fi
|
||||
# STORE TAGS INTO VARIABLES
|
||||
FILE_TAGS=`echo $JSON | jq -r '.[] | ."tag_string"' | sed 's/\ /,/g'`
|
||||
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
|
||||
sleep "$DELAY"
|
||||
done
|
34
e621dl.sh
34
e621dl.sh
@ -8,7 +8,7 @@ HAS_API_KEY=false
|
||||
|
||||
|
||||
function usage {
|
||||
echo "./$(basename $0) [-t] [-s]"
|
||||
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 e621 BLOCKS TOR WITH CLOUDFLARE, DOES NOT WORK"
|
||||
@ -55,35 +55,33 @@ while getopts ${optstring} arg; do
|
||||
esac
|
||||
done
|
||||
|
||||
while read f; do
|
||||
while read -r f; do
|
||||
echo "$f"
|
||||
# MODIFY URL TO API CALL
|
||||
JSON_URL=`echo $f | sed "s/\?q.*//g"`
|
||||
# shellcheck disable=SC2001
|
||||
JSON_URL=$(echo "$f" | sed "s/\?q.*//g")
|
||||
JSON_URL="$JSON_URL.json"
|
||||
# DOWNLOAD JSON
|
||||
if $HAS_USERNAME && $HAS_API_KEY ; then
|
||||
JSON_URL="$JSON_URL?login=$USERNAME&api_key=$API_KEY"
|
||||
fi
|
||||
echo $JSON_URL
|
||||
echo "$JSON_URL"
|
||||
if $USE_TOR; then
|
||||
#JSON=`torsocks curl -A "$UA" -s "$JSON_URL"`
|
||||
echo "e621 BLOCKS TOR WITH CLOUDFLARE"
|
||||
echo "EXITING SINCE SCRIPT WILL NOT WORK"
|
||||
exit
|
||||
else
|
||||
JSON=`curl -A "$UA" -s "$JSON_URL"`
|
||||
JSON=$(curl -A "$UA" -s "$JSON_URL")
|
||||
fi
|
||||
# STORE TAGS INTO VARIABLES (god what the hell)
|
||||
FILE_URL=`echo $JSON | jq -r '.post | .file."url"'`
|
||||
FILE_TAGS_GENERAL=`echo $JSON | jq -r '.post."tags"."general"' | sed 's/\"//g' | sed 's/\[//g' | sed 's/\]//g' | tr -d '[:space:]'`
|
||||
FILE_TAGS_ARTIST=`echo $JSON | jq -r '.post."tags"."artist"' | sed 's/\"//g' | sed 's/\[//g' | sed 's/\]//g' | tr -d '[:space:]'`
|
||||
FILE_TAGS_CHARACTER=`echo $JSON | jq -r '.post."tags"."character"' | sed 's/\"//g' | sed 's/\[//g' | sed 's/\]//g' | tr -d '[:space:]'`
|
||||
FILE_TAGS_SPECIES=`echo $JSON | jq -r '.post."tags"."species"' | sed 's/\"//g' | sed 's/\[//g' | sed 's/\]//g' | tr -d '[:space:]'`
|
||||
FILE_TAGS_META=`echo $JSON | jq -r '.post."tags"."meta"' | sed 's/\"//g' | sed 's/\[//g' | sed 's/\]//g' | tr -d '[:space:]'`
|
||||
FILE_DESCRIPTION=`echo $JSON | jq -r '.post'.'description'`
|
||||
FILE_MD5=`echo $JSON | jq -r '.post'.'file'.'md5'`
|
||||
FILE_EXT=`echo $JSON | jq -r '.post'.'file'.'ext'`
|
||||
FILE_TAGS=`echo "$FILE_TAGS_ARTIST,$FILE_TAGS_CHARACTER,$FILE_TAGS_GENERAL,$FILE_TAGS_SPECIES,$FILE_TAGS_META"`
|
||||
# STORE TAGS INTO VARIABLES
|
||||
#FILE_DESCRIPTION=`echo $JSON | jq -r '.post'.'description'`
|
||||
FILE_URL=$(echo "$JSON" | jq -r '.post | .file."url"')
|
||||
FILE_MD5=$(echo "$JSON" | jq -r '.post'.'file'.'md5')
|
||||
FILE_EXT=$(echo "$JSON" | jq -r '.post'.'file'.'ext')
|
||||
# ONE JQ TO RULE THEM ALL (thanks jon!)
|
||||
FILE_TAGS="$(jq -r '.post.tags | reduce to_entries[] as $arr ([]; . + [ $arr.value[] | gsub("[\"\\[\\]\\s]"; "", "g") ] ) | join(",")' - <<< "$JSON")"
|
||||
|
||||
#echo $FILE_TAGS
|
||||
# DOWNLOAD FILE
|
||||
if $USE_TOR; then
|
||||
@ -92,7 +90,7 @@ while read f; do
|
||||
echo "EXITING SINCE SCRIPT WILL NOT WORK"
|
||||
exit
|
||||
else
|
||||
curl -O -J $FILE_URL
|
||||
curl -O -J "$FILE_URL"
|
||||
fi
|
||||
# ADD TAGS TO NEW IMAGE
|
||||
FILE="$FILE_MD5.$FILE_EXT"
|
||||
@ -101,5 +99,5 @@ while read f; do
|
||||
setfattr -n user.xdg.comment -v "$FILE_DESCRIPTION" "$FILE"
|
||||
setfattr --name=user.checksum --value="$FILE_MD5" "$FILE"
|
||||
# DELAY BEFORE NEXT FETCH
|
||||
sleep $DELAY
|
||||
sleep "$DELAY"
|
||||
done < files.txt
|
23
e621tag.sh
23
e621tag.sh
@ -5,7 +5,7 @@ DELAY=1
|
||||
UA="Booru-Tools/0.1"
|
||||
|
||||
function usage {
|
||||
echo "./$(basename $0) [-t] [-s]"
|
||||
echo "./$(basename "$0") [-t] [-s]"
|
||||
echo "Tags existing pictures inside a folder"
|
||||
echo " -h shows this help message"
|
||||
echo " -t e621 BLOCKS TOR WITH CLOUDFLARE, DOES NOT WORK"
|
||||
@ -44,29 +44,22 @@ done
|
||||
for FILE in *; do
|
||||
echo "$FILE"
|
||||
# GET MD5 HASH
|
||||
FILE_MD5=`md5sum "$FILE" | awk '{print $1}'`
|
||||
echo $FILE_MD5
|
||||
FILE_MD5=$(md5sum "$FILE" | awk '{print $1}')
|
||||
echo "$FILE_MD5"
|
||||
# DOWNLOAD JSON
|
||||
URL=https://e621.net/posts.json?tags=md5:
|
||||
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
|
||||
JSON=`curl -s -A "$UA" "https://e621.net/posts.json?tags=md5:$FILE_MD5"`
|
||||
JSON=$(curl -s -A "$UA" "https://e621.net/posts.json?limit=1&tags=md5:$FILE_MD5")
|
||||
fi
|
||||
# STORE TAGS INTO VARIABLES (god what the hell)
|
||||
FILE_TAGS_GENERAL=`echo $JSON | jq -r '.posts | .[] | ."tags"."general"' | sed 's/\"//g' | sed 's/\[//g' | sed 's/\]//g' | tr -d '[:space:]'`
|
||||
FILE_TAGS_ARTIST=`echo $JSON| jq -r '.posts | .[] | ."tags"."artist"' | sed 's/\"//g' | sed 's/\[//g' | sed 's/\]//g' | tr -d '[:space:]'`
|
||||
FILE_TAGS_CHARACTER=`echo $JSON| jq -r '.posts | .[] | ."tags"."character"' | sed 's/\"//g' | sed 's/\[//g' | sed 's/\]//g' | tr -d '[:space:]'`
|
||||
FILE_TAGS_SPECIES=`echo $JSON| jq -r '.posts | .[] | ."tags"."species"' | sed 's/\"//g' | sed 's/\[//g' | sed 's/\]//g' | tr -d '[:space:]'`
|
||||
FILE_TAGS_META=`echo $JSON| jq -r '.posts | .[] | ."tags"."meta"' | sed 's/\"//g' | sed 's/\[//g' | sed 's/\]//g' | tr -d '[:space:]'`
|
||||
FILE_TAGS=`echo "$FILE_TAGS_ARTIST,$FILE_TAGS_CHARACTER,$FILE_TAGS_GENERAL,$FILE_TAGS_SPECIES,$FILE_TAGS_META"`
|
||||
echo $FILE_TAGS
|
||||
# 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"
|
||||
# ADD TAGS TO IMAGE
|
||||
setfattr -n user.xdg.tags -v "$FILE_TAGS" "$FILE"
|
||||
setfattr -n user.xdg.creator -v "$FILE_TAGS_ARTIST" "$FILE"
|
||||
# DELAY BEFORE NEXT FETCH
|
||||
sleep $DELAY
|
||||
sleep "$DELAY"
|
||||
done
|
@ -2,17 +2,15 @@
|
||||
|
||||
USE_TOR=false
|
||||
DELAY=1
|
||||
LIMIT=200
|
||||
|
||||
function usage {
|
||||
echo "./$(basename $0) [-t] [-s] [-l] -a tag -a tag2"
|
||||
echo "./$(basename "$0") [-t] [-s] [-l] -a tag -a tag2"
|
||||
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)"
|
||||
echo " -s sets the delay after each request, defaults to 1"
|
||||
echo " -a tag or artist name"
|
||||
echo " -l limit of single json request (defaults to 100)"
|
||||
}
|
||||
|
||||
# list of arguments expected in the input
|
||||
@ -35,9 +33,6 @@ while getopts ${optstring} arg; do
|
||||
a)
|
||||
TAGS+=("$OPTARG")
|
||||
;;
|
||||
l)
|
||||
LIMIT="${OPTARG}"
|
||||
;;
|
||||
:)
|
||||
echo "$0: Must supply an argument to -$OPTARG." >&2
|
||||
exit 1
|
||||
@ -50,15 +45,15 @@ while getopts ${optstring} arg; do
|
||||
done
|
||||
|
||||
for TAG in "${TAGS[@]}"; do
|
||||
echo $TAG
|
||||
echo "$TAG"
|
||||
# CREATE FOLDER AND CD INTO IT
|
||||
mkdir -v $TAG
|
||||
cd $TAG
|
||||
# GET TAG TOTAL COUNT
|
||||
if $USE_TOR; then
|
||||
TAG_COUNT=`torsocks curl -s "https://gelbooru.com/index.php?page=dapi&s=tag&q=index&json=1&name=$TAG" | jq -r '."tag" | .[] | ."count"'`
|
||||
TAG_COUNT=$(torsocks curl -s "https://gelbooru.com/index.php?page=dapi&s=tag&q=index&json=1&name=$TAG" | jq -r '."tag" | .[] | ."count"')
|
||||
else
|
||||
TAG_COUNT=`curl -s "https://gelbooru.com/index.php?page=dapi&s=tag&q=index&json=1&name=$TAG" | jq -r '."tag" | .[] | ."count"'`
|
||||
TAG_COUNT=$(curl -s "https://gelbooru.com/index.php?page=dapi&s=tag&q=index&json=1&name=$TAG" | jq -r '."tag" | .[] | ."count"')
|
||||
fi
|
||||
|
||||
# NESTED LOOP TO GET ALL POSTS UNDER TAG
|
||||
@ -66,34 +61,34 @@ for TAG in "${TAGS[@]}"; do
|
||||
for (( PAGE = 0; PAGE <= $TAG_PAGES; PAGE++ ))
|
||||
do
|
||||
if $USE_TOR; then
|
||||
JSON+=`torsocks curl -s "https://gelbooru.com/index.php?page=dapi&s=post&q=index&json=1&pid=$PAGE&tags=$TAG" | jq -r '.post'`
|
||||
JSON+=$(torsocks curl -s "https://gelbooru.com/index.php?page=dapi&s=post&q=index&json=1&pid=$PAGE&tags=$TAG" | jq -r '.post')
|
||||
else
|
||||
JSON+=`curl -s "https://gelbooru.com/index.php?page=dapi&s=post&q=index&json=1&pid=$PAGE&tags=$TAG" | jq -r '.post'`
|
||||
JSON+=$(curl -s "https://gelbooru.com/index.php?page=dapi&s=post&q=index&json=1&pid=$PAGE&tags=$TAG" | jq -r '.post')
|
||||
fi
|
||||
sleep $DELAY
|
||||
sleep "$DELAY"
|
||||
done
|
||||
|
||||
# NESTED LOOP FOR IMAGES IN THIS TAG
|
||||
echo $JSON | jq -c '.[]' | while read i; do
|
||||
echo "$JSON" | jq -c '.[]' | while read i; do
|
||||
#echo $i | jq -r '."id"'
|
||||
FILE_DATE=`echo $i | jq -r '."created_at"'`
|
||||
FILE_URL=`echo $i | jq -r '."file_url"'`
|
||||
FILE_MD5=`echo $i | jq -r '."md5"'`
|
||||
FILE_TAGS=`echo $i | jq -r '."tags"' | sed 's/\ /,/g'`
|
||||
FILE=`echo $FILE_URL | sed 's/\// /g' | awk '{print $NF}'`
|
||||
FILE_DATE=$(echo "$i" | jq -r '."created_at"')
|
||||
FILE_URL=$(echo "$i" | jq -r '."file_url"')
|
||||
FILE_MD5=$(echo "$i" | jq -r '."md5"')
|
||||
FILE_TAGS=$(echo "$i" | jq -r '."tags"' | sed 's/\ /,/g')
|
||||
FILE=$(echo "$FILE_URL" | sed 's/\// /g' | awk '{print $NF}')
|
||||
|
||||
# DOWNLOAD FILE
|
||||
if $USE_TOR; then
|
||||
torsocks curl -O -J $FILE_URL
|
||||
torsocks curl -O -J "$FILE_URL"
|
||||
else
|
||||
curl -O -J $FILE_URL
|
||||
curl -O -J "$FILE_URL"
|
||||
fi
|
||||
# ADD TAGS TO NEW IMAGE
|
||||
setfattr -n user.xdg.tags -v "$FILE_TAGS" "$FILE"
|
||||
setfattr --name=user.checksum --value="$FILE_MD5" "$FILE"
|
||||
touch -d "$FILE_DATE" "$FILE"
|
||||
# DELAY BEFORE NEXT FETCH
|
||||
sleep $DELAY
|
||||
sleep "$DELAY"
|
||||
done
|
||||
# BACK OUT OF FOLDER
|
||||
cd ..
|
||||
|
26
gelbdl.sh
26
gelbdl.sh
@ -5,7 +5,7 @@ DELAY=1
|
||||
USE_DATE=false
|
||||
|
||||
function usage {
|
||||
echo "./$(basename $0) [-t] [-s 1] [-d]"
|
||||
echo "./$(basename "$0") [-t] [-s 1] [-d]"
|
||||
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"
|
||||
@ -46,27 +46,27 @@ while getopts ${optstring} arg; do
|
||||
esac
|
||||
done
|
||||
|
||||
while read f; do
|
||||
while read -r 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"`
|
||||
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 .`
|
||||
JSON=$(torsocks curl -s "$JSON_URL" | jq .)
|
||||
else
|
||||
JSON=`curl -s $JSON_URL | jq .`
|
||||
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_MD5=`echo $JSON | jq -r '.post | .[] | ."md5"'`
|
||||
FILE_DATE=`echo $JSON | jq -r '.post | .[] | ."created_at"'`
|
||||
FILE=`echo $FILE_URL | sed 's/\// /g' | awk '{print $NF}'`
|
||||
FILE_URL=$(echo "$JSON" | jq -r '.post | .[] | ."file_url"')
|
||||
FILE_TAGS=$(echo "$JSON" | jq -r '.post | .[] | ."tags"' | sed 's/\ /,/g')
|
||||
FILE_MD5=$(echo "$JSON" | jq -r '.post | .[] | ."md5"')
|
||||
FILE_DATE=$(echo "$JSON" | jq -r '.post | .[] | ."created_at"')
|
||||
FILE=$(echo "$FILE_URL" | sed 's/\// /g' | awk '{print $NF}')
|
||||
# DOWNLOAD FILE
|
||||
if $USE_TOR; then
|
||||
torsocks curl -O -J $FILE_URL
|
||||
torsocks curl -O -J "$FILE_URL"
|
||||
else
|
||||
curl -O -J $FILE_URL
|
||||
curl -O -J "$FILE_URL"
|
||||
fi
|
||||
# ADD TAGS TO NEW IMAGE
|
||||
setfattr -n user.xdg.tags -v "$FILE_TAGS" "$FILE"
|
||||
@ -75,5 +75,5 @@ while read f; do
|
||||
touch -d "$FILE_DATE" "$FILE"
|
||||
fi
|
||||
# DELAY BEFORE NEXT FETCH
|
||||
sleep $DELAY
|
||||
sleep "$DELAY"
|
||||
done < files.txt
|
14
gelbtag.sh
14
gelbtag.sh
@ -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
|
22
moedl.sh
22
moedl.sh
@ -4,7 +4,7 @@ USE_TOR=false
|
||||
DELAY=1
|
||||
|
||||
function usage {
|
||||
echo "./$(basename $0) [-t] [-s]"
|
||||
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"
|
||||
@ -40,22 +40,22 @@ while getopts ${optstring} arg; do
|
||||
esac
|
||||
done
|
||||
|
||||
while read f; do
|
||||
while read -r 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}'`
|
||||
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"`
|
||||
JSON=$(torsocks curl -s "https://$URL/post.json?tags=id:$IMAGE_ID")
|
||||
else
|
||||
JSON=`curl -s "https://$URL/post.json?tags=id:$IMAGE_ID"`
|
||||
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'`
|
||||
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"
|
||||
@ -66,5 +66,5 @@ while read f; do
|
||||
setfattr -n user.xdg.tags -v "$FILE_TAGS" "$FILE"
|
||||
mv "$FILE" "$FILE_WITHSPACE"
|
||||
# DELAY BEFORE NEXT FETCH
|
||||
sleep $DELAY
|
||||
sleep "$DELAY"
|
||||
done < files.txt
|
12
moetag.sh
12
moetag.sh
@ -5,7 +5,7 @@ DELAY=1
|
||||
REQ_URL=""
|
||||
|
||||
function usage {
|
||||
echo "./$(basename $0) [-t] [-s]"
|
||||
echo "./$(basename "$0") [-t] [-s]"
|
||||
echo "Mass tagger for moebooru imageboards"
|
||||
echo "Tags existing pictures inside a folder"
|
||||
echo " -h shows this help message"
|
||||
@ -63,17 +63,17 @@ fi
|
||||
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 "$REQ_URL$FILE_MD5"`
|
||||
JSON=$(torsocks curl -s "$REQ_URL$FILE_MD5")
|
||||
else
|
||||
JSON=`curl -s "$REQ_URL$FILE_MD5"`
|
||||
JSON=$(curl -s "$REQ_URL$FILE_MD5")
|
||||
fi
|
||||
# STORE TAGS INTO VARIABLES
|
||||
FILE_TAGS=`echo $JSON | jq -r '.[] | ."tags"' | sed 's/\ /,/g'`
|
||||
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
|
||||
sleep "$DELAY"
|
||||
done
|
||||
|
Loading…
Reference in New Issue
Block a user