2023-09-29 19:53:53 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
USE_TOR=false
|
|
|
|
DELAY=1
|
|
|
|
|
|
|
|
function usage {
|
2023-12-25 11:15:44 +00:00
|
|
|
echo "./$(basename "$0") [-t] [-s]"
|
2023-09-29 19:53:53 +00:00
|
|
|
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
|
|
|
|
|
2023-12-25 11:15:44 +00:00
|
|
|
while read -r f; do
|
2023-09-29 19:53:53 +00:00
|
|
|
echo "$f"
|
|
|
|
# get ID from the URL
|
2023-12-25 11:15:44 +00:00
|
|
|
URL=$(echo "$f" | sed 's/\// /g' | awk '{print $2}')
|
|
|
|
IMAGE_ID=$(echo "$f" | sed 's/\// /g' | awk '{print $5}')
|
2023-09-29 19:53:53 +00:00
|
|
|
# DOWNLOAD JSON
|
|
|
|
if $USE_TOR; then
|
2023-12-25 11:15:44 +00:00
|
|
|
JSON=$(torsocks curl -s "https://$URL/post.json?tags=id:$IMAGE_ID")
|
2023-09-29 19:53:53 +00:00
|
|
|
else
|
2023-12-25 11:15:44 +00:00
|
|
|
JSON=$(curl -s "https://$URL/post.json?tags=id:$IMAGE_ID")
|
2023-09-29 19:53:53 +00:00
|
|
|
fi
|
|
|
|
# STORE FILE URL AND TAGS INTO VARIABLES
|
2023-12-25 11:15:44 +00:00
|
|
|
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')
|
2023-09-29 19:53:53 +00:00
|
|
|
# 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
|
2023-12-25 11:15:44 +00:00
|
|
|
sleep "$DELAY"
|
2023-09-29 19:53:53 +00:00
|
|
|
done < files.txt
|