1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-05-18 17:53:23 -07:00
This commit is contained in:
notwa 2012-08-19 01:43:15 -07:00
commit cbca147b0b

39
danny.sh Normal file
View File

@ -0,0 +1,39 @@
#!/bin/bash
tags=$1
ip="67.202.114.134" # danbooru.donmai.us
webpage="post/index?tags=$tags&limit=100&page="
pages=0
tempfile=`mktemp`
# wget opts: less verbose, no directories, ignore robots.txt, output to stdout
# can be replaced with curl
get='wget -nvd -erobots=off -O-'
page=1
while true; do
$get "http://$ip/${webpage}${page}" > "$tempfile"
image_urls=$(grep -oP '(?<=file_url":")([^"]+)' $tempfile)
for url in $image_urls; do
name=$(echo "$url" | cut -d/ -f5)
if [ -e "$name" ]; then :
else
$get $url > $name
fi
done
if (("$pages" == "0")); then
# first iteration, discover pagecount
pages=$(grep -oPm1 \
'(?<=>)\d+(?=</a> <a href="/post/index[^"]+" >&gt;&gt;)' \
$tempfile)
pages=${pages:-1}
echo $pages
fi
let page++
if (("$page" > "$pages")); then break; fi
done
rm $tempfile