40 lines
926 B
Bash
Executable file
40 lines
926 B
Bash
Executable file
#!/bin/zsh
|
|
dir=$1
|
|
url='http://danbooru.donmai.us/data/'
|
|
|
|
curl=(curl -sS -m 900 --connect-timeout 8 --retry 3 --retry-delay 1)
|
|
|
|
cleanup() {
|
|
[ -e $dir/$md5e ] && {
|
|
rm -f $dir/$md5e
|
|
echo "\e[F\e[K$md5e - canceled"
|
|
}
|
|
exit 1
|
|
}
|
|
trap cleanup INT
|
|
|
|
mkdir -p $dir
|
|
while read -r; do
|
|
if [[ ${REPLY[1]} = "#" ]]; then
|
|
md5e=${REPLY:1}
|
|
echo "$md5e - downloading..."
|
|
${curl[@]} $url$md5e > $dir/$md5e || {
|
|
rm -f $dir/$md5e
|
|
echo "\e[F\e[K$md5e - failed"
|
|
}
|
|
echo "\e[F\e[K$md5e - downloaded!"
|
|
else
|
|
md5e=${REPLY##*/}
|
|
[ $REPLY -ef $dir/$md5e ] && {
|
|
echo "$md5e - skipping (ef)"
|
|
continue
|
|
}
|
|
[ -s $dir/$md5e ] && {
|
|
echo "$md5e - skipping (s)"
|
|
continue
|
|
}
|
|
echo "$md5e - copying..."
|
|
cp $REPLY $dir
|
|
echo "\e[F\e[K$md5e - copied!"
|
|
fi
|
|
done
|