2013-07-29 00:45:45 -07:00
|
|
|
#!/bin/zsh
|
|
|
|
dir=$1
|
|
|
|
url='http://danbooru.donmai.us/data/'
|
|
|
|
|
|
|
|
curl=(curl -sS -m 900 --connect-timeout 8 --retry 3 --retry-delay 1)
|
|
|
|
|
2013-11-01 20:08:34 -07:00
|
|
|
cleanup() {
|
|
|
|
[ -e $dir/$md5e ] && {
|
|
|
|
rm -f $dir/$md5e
|
|
|
|
echo "\e[F\e[K$md5e - canceled"
|
|
|
|
}
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
trap cleanup INT
|
|
|
|
|
2013-07-29 00:45:45 -07:00
|
|
|
mkdir -p $dir
|
|
|
|
while read -r; do
|
|
|
|
if [[ ${REPLY[1]} = "#" ]]; then
|
|
|
|
md5e=${REPLY:1}
|
2013-11-01 20:08:34 -07:00
|
|
|
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!"
|
2013-07-29 00:45:45 -07:00
|
|
|
else
|
|
|
|
md5e=${REPLY##*/}
|
2013-11-01 20:08:34 -07:00
|
|
|
[ $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!"
|
2013-07-29 00:45:45 -07:00
|
|
|
fi
|
|
|
|
done
|