Compare commits
No commits in common. "10745f79e212dd70673d21253fcfe2d54ece68e9" and "32c199af140d0d17d157bdf0a3cc21cb19141033" have entirely different histories.
10745f79e2
...
32c199af14
@ -1,11 +1,5 @@
|
|||||||
# CHANGELOG
|
# CHANGELOG
|
||||||
|
|
||||||
## 12/26/2023
|
|
||||||
|
|
||||||
### ADDED
|
|
||||||
- added `-r` resume option under `*-tag.sh` scripts
|
|
||||||
- added `dandl-tag.sh` and `moedl-tag.sh`
|
|
||||||
|
|
||||||
## 12/25/2023 (Merry Christmas!)
|
## 12/25/2023 (Merry Christmas!)
|
||||||
|
|
||||||
### FIXED
|
### FIXED
|
||||||
|
116
dandl-tag.sh
116
dandl-tag.sh
@ -1,116 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
USE_TOR=false
|
|
||||||
DELAY=1
|
|
||||||
RECENT=false
|
|
||||||
|
|
||||||
function usage {
|
|
||||||
echo "./$(basename "$0") [-t] [-s] [-r]"
|
|
||||||
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"
|
|
||||||
echo " -a tag or artist name"
|
|
||||||
echo " -r will download until it hits a file that already exists"
|
|
||||||
}
|
|
||||||
|
|
||||||
# list of arguments expected in the input
|
|
||||||
optstring=":hts:a:r"
|
|
||||||
|
|
||||||
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}"
|
|
||||||
;;
|
|
||||||
a)
|
|
||||||
TAGS+=("$OPTARG")
|
|
||||||
;;
|
|
||||||
r)
|
|
||||||
RECENT=true
|
|
||||||
;;
|
|
||||||
:)
|
|
||||||
echo "$0: Must supply an argument to -$OPTARG." >&2
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
?)
|
|
||||||
echo "Invalid option: -${OPTARG}."
|
|
||||||
exit 2
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
for TAG in "${TAGS[@]}"; do
|
|
||||||
echo "$TAG"
|
|
||||||
# CREATE FOLDER AND CD INTO IT
|
|
||||||
mkdir -v "$TAG"
|
|
||||||
cd "$TAG" || exit
|
|
||||||
# GET TAG TOTAL COUNT
|
|
||||||
if $USE_TOR; then
|
|
||||||
TAG_COUNT=$(torsocks curl -s "https://danbooru.donmai.us/tags.json?only=id,name,post_count&search\[name_matches\]=$TAG" | jq -r '.[].post_count')
|
|
||||||
else
|
|
||||||
TAG_COUNT=$(curl -s "https://danbooru.donmai.us/tags.json?only=id,name,post_count&search\[name_matches\]=$TAG" | jq -r '.[].post_count')
|
|
||||||
fi
|
|
||||||
# NESTED LOOP TO GET ALL POSTS UNDER TAG
|
|
||||||
TAG_PAGES=$((TAG_COUNT / 200))
|
|
||||||
for (( PAGE = 0; PAGE <= TAG_PAGES; PAGE++ ))
|
|
||||||
do
|
|
||||||
if $USE_TOR; then
|
|
||||||
JSON_URL+=$(torsocks curl -s "https://danbooru.donmai.us/posts.json?page=$PAGE&limit=200&tags=$TAG" | jq -r '.[].id')
|
|
||||||
if ((PAGE < TAG_PAGES)); then
|
|
||||||
JSON_URL+=$'\n'
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
JSON_URL+=$(curl -s "https://danbooru.donmai.us/posts.json?page=$PAGE&limit=200&tags=$TAG" | jq -r '.[].id')
|
|
||||||
if ((PAGE < TAG_PAGES)); then
|
|
||||||
JSON_URL+=$'\n'
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
sleep "$DELAY"
|
|
||||||
done
|
|
||||||
# NESTED LOOP FOR IMAGES IN THIS TAG
|
|
||||||
echo "$JSON_URL" | while read -r i; do
|
|
||||||
if $USE_TOR; then
|
|
||||||
JSON=$(torsocks curl -s "https://danbooru.donmai.us/posts/$i.json")
|
|
||||||
else
|
|
||||||
JSON=$(curl -s "https://danbooru.donmai.us/posts/$i.json")
|
|
||||||
fi
|
|
||||||
# STORE FILE URL AND TAGS INTO VARIABLES
|
|
||||||
FILE_DATE=$(echo "$JSON" | jq -r '."created_at"')
|
|
||||||
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"
|
|
||||||
if $RECENT; then
|
|
||||||
if [[ -f "$FILE" ]]; then
|
|
||||||
echo "$FILE exists."
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
# 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"
|
|
||||||
setfattr --name=user.checksum --value="$FILE_MD5" "$FILE"
|
|
||||||
# SET TIME TO TIME UPLOADED
|
|
||||||
touch -d "$FILE_DATE" "$FILE"
|
|
||||||
# DELAY BEFORE NEXT FETCH
|
|
||||||
sleep "$DELAY"
|
|
||||||
done
|
|
||||||
# BACK OUT OF FOLDER
|
|
||||||
cd ..
|
|
||||||
done
|
|
@ -2,21 +2,19 @@
|
|||||||
|
|
||||||
USE_TOR=false
|
USE_TOR=false
|
||||||
DELAY=1
|
DELAY=1
|
||||||
RECENT=false
|
|
||||||
|
|
||||||
function usage {
|
function usage {
|
||||||
echo "./$(basename "$0") [-t] [-s] [-r] -a tag -a tag2"
|
echo "./$(basename "$0") [-t] [-s] [-l] -a tag -a tag2"
|
||||||
echo "Mass downloader for Gelbooru"
|
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 "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 " -h shows this help message"
|
||||||
echo " -t downloads using tor (requires torsocks)"
|
echo " -t downloads using tor (requires torsocks)"
|
||||||
echo " -s sets the delay after each request, defaults to 1"
|
echo " -s sets the delay after each request, defaults to 1"
|
||||||
echo " -a tag or artist name"
|
echo " -a tag or artist name"
|
||||||
echo " -r will download until it hits a file that already exists"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# list of arguments expected in the input
|
# list of arguments expected in the input
|
||||||
optstring=":hts:a:r"
|
optstring=":hts:a:l:"
|
||||||
|
|
||||||
while getopts ${optstring} arg; do
|
while getopts ${optstring} arg; do
|
||||||
case ${arg} in
|
case ${arg} in
|
||||||
@ -35,9 +33,6 @@ while getopts ${optstring} arg; do
|
|||||||
a)
|
a)
|
||||||
TAGS+=("$OPTARG")
|
TAGS+=("$OPTARG")
|
||||||
;;
|
;;
|
||||||
r)
|
|
||||||
RECENT=true
|
|
||||||
;;
|
|
||||||
:)
|
:)
|
||||||
echo "$0: Must supply an argument to -$OPTARG." >&2
|
echo "$0: Must supply an argument to -$OPTARG." >&2
|
||||||
exit 1
|
exit 1
|
||||||
@ -52,8 +47,8 @@ done
|
|||||||
for TAG in "${TAGS[@]}"; do
|
for TAG in "${TAGS[@]}"; do
|
||||||
echo "$TAG"
|
echo "$TAG"
|
||||||
# CREATE FOLDER AND CD INTO IT
|
# CREATE FOLDER AND CD INTO IT
|
||||||
mkdir -v "$TAG"
|
mkdir -v $TAG
|
||||||
cd "$TAG" || exit
|
cd $TAG
|
||||||
# GET TAG TOTAL COUNT
|
# GET TAG TOTAL COUNT
|
||||||
if $USE_TOR; then
|
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"')
|
||||||
@ -63,7 +58,7 @@ for TAG in "${TAGS[@]}"; do
|
|||||||
|
|
||||||
# NESTED LOOP TO GET ALL POSTS UNDER TAG
|
# NESTED LOOP TO GET ALL POSTS UNDER TAG
|
||||||
TAG_PAGES=$((TAG_COUNT / 100))
|
TAG_PAGES=$((TAG_COUNT / 100))
|
||||||
for (( PAGE = 0; PAGE <= TAG_PAGES; PAGE++ ))
|
for (( PAGE = 0; PAGE <= $TAG_PAGES; PAGE++ ))
|
||||||
do
|
do
|
||||||
if $USE_TOR; then
|
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')
|
||||||
@ -74,7 +69,7 @@ for TAG in "${TAGS[@]}"; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
# NESTED LOOP FOR IMAGES IN THIS TAG
|
# NESTED LOOP FOR IMAGES IN THIS TAG
|
||||||
echo "$JSON" | jq -c '.[]' | while read -r i; do
|
echo "$JSON" | jq -c '.[]' | while read i; do
|
||||||
#echo $i | jq -r '."id"'
|
#echo $i | jq -r '."id"'
|
||||||
FILE_DATE=$(echo "$i" | jq -r '."created_at"')
|
FILE_DATE=$(echo "$i" | jq -r '."created_at"')
|
||||||
FILE_URL=$(echo "$i" | jq -r '."file_url"')
|
FILE_URL=$(echo "$i" | jq -r '."file_url"')
|
||||||
@ -82,13 +77,6 @@ for TAG in "${TAGS[@]}"; do
|
|||||||
FILE_TAGS=$(echo "$i" | jq -r '."tags"' | sed 's/\ /,/g')
|
FILE_TAGS=$(echo "$i" | jq -r '."tags"' | sed 's/\ /,/g')
|
||||||
FILE=$(echo "$FILE_URL" | sed 's/\// /g' | awk '{print $NF}')
|
FILE=$(echo "$FILE_URL" | sed 's/\// /g' | awk '{print $NF}')
|
||||||
|
|
||||||
if $RECENT; then
|
|
||||||
if [[ -f "$FILE" ]]; then
|
|
||||||
echo "$FILE exists."
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# DOWNLOAD FILE
|
# DOWNLOAD FILE
|
||||||
if $USE_TOR; then
|
if $USE_TOR; then
|
||||||
torsocks curl -O -J "$FILE_URL"
|
torsocks curl -O -J "$FILE_URL"
|
||||||
|
119
moedl-tag.sh
119
moedl-tag.sh
@ -1,119 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
USE_TOR=false
|
|
||||||
DELAY=1
|
|
||||||
RECENT=false
|
|
||||||
URL="konachan.com"
|
|
||||||
|
|
||||||
function usage {
|
|
||||||
echo "./$(basename "$0") [-t] [-s] [-r] [-c site.com]"
|
|
||||||
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"
|
|
||||||
echo " -a tag or artist name"
|
|
||||||
echo " -r will download until it hits a file that already exists"
|
|
||||||
echo " -c custom url (defaults to konachan if unset)"
|
|
||||||
}
|
|
||||||
|
|
||||||
# list of arguments expected in the input
|
|
||||||
optstring=":hts:a:rc:"
|
|
||||||
|
|
||||||
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}"
|
|
||||||
;;
|
|
||||||
a)
|
|
||||||
TAGS+=("$OPTARG")
|
|
||||||
;;
|
|
||||||
r)
|
|
||||||
RECENT=true
|
|
||||||
;;
|
|
||||||
c)
|
|
||||||
URL="${OPTARG}"
|
|
||||||
;;
|
|
||||||
:)
|
|
||||||
echo "$0: Must supply an argument to -$OPTARG." >&2
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
?)
|
|
||||||
echo "Invalid option: -${OPTARG}."
|
|
||||||
exit 2
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
for TAG in "${TAGS[@]}"; do
|
|
||||||
echo "$TAG"
|
|
||||||
# CREATE FOLDER AND CD INTO IT
|
|
||||||
mkdir -v "$TAG"
|
|
||||||
cd "$TAG" || exit
|
|
||||||
if $USE_TOR; then
|
|
||||||
TAG_COUNT=$(torsocks curl -s "https://$URL/tag.json?name=$TAG" | jq -r '.[]."count"')
|
|
||||||
else
|
|
||||||
TAG_COUNT=$(curl -s "https://$URL/tag.json?name=$TAG" | jq -r '.[]."count"')
|
|
||||||
fi
|
|
||||||
# NESTED LOOP TO GET ALL POSTS UNDER TAG
|
|
||||||
TAG_PAGES=$((TAG_COUNT / 100))
|
|
||||||
ID_LIST=""
|
|
||||||
for (( PAGE = 0; PAGE <= TAG_PAGES; PAGE++ ))
|
|
||||||
do
|
|
||||||
if $USE_TOR; then
|
|
||||||
ID_LIST+=$(torsocks curl -s "https://$URL/post.json?page=$PAGE&limit=100&tags=$TAG" | jq -r '.[]."id"')
|
|
||||||
if ((PAGE < TAG_PAGES)); then
|
|
||||||
ID_LIST+=$'\n'
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
ID_LIST+=$(curl -s "https://$URL/post.json?page=$PAGE&limit=100&tags=$TAG" | jq -r '.[]."id"')
|
|
||||||
if ((PAGE < TAG_PAGES)); then
|
|
||||||
ID_LIST+=$'\n'
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
sleep "$DELAY"
|
|
||||||
done
|
|
||||||
echo "$ID_LIST" | while read -r IMAGE_ID; do
|
|
||||||
# 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_DATE=$(echo "$JSON" | jq -r '.[]."created_at"')
|
|
||||||
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')
|
|
||||||
if $RECENT; then
|
|
||||||
if [[ -f "$FILE_WITHSPACE" ]]; then
|
|
||||||
echo "$FILE_WITHSPACE exists."
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
# 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
|
|
||||||
touch -d "@$FILE_DATE" "$FILE_WITHSPACE"
|
|
||||||
sleep "$DELAY"
|
|
||||||
done
|
|
||||||
# BACK OUT OF FOLDER
|
|
||||||
cd ..
|
|
||||||
done
|
|
Loading…
Reference in New Issue
Block a user