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 04:58:01 -07:00
parent cea9e4a42f
commit 6a28f54c32

View File

@ -1,11 +1,14 @@
#!/bin/bash
set -o nounset
set -o errexit
tags=$1
# danny wants $20 to search for more than 2 tags
# so we'll search for realtags and grep for faketags
# note that special tags like "score:>10" must be the first or second
realtags="$1"
faketags=${2:-}
ip="67.202.114.134" # danbooru.donmai.us
webpage="post/index?tags=$tags&limit=100&page="
webpage="post/index?tags=$realtags&limit=100&page="
pages=0
tempfile=`mktemp`
current=
@ -24,16 +27,40 @@ page=1
while true; do
$get "http://$ip/${webpage}${page}" > "$tempfile"
image_urls=$(grep -oP '(?<=file_url":")([^"]+)' $tempfile)
for url in $image_urls; do
posts=$(grep 'Post\.register({' "$tempfile")
IFS=$'\n'
for post in $posts; do
IFS=' '
tags=$(echo $post | grep -oP '(?<=tags":")([^"]+)')
if [ -z "$tags" ]; then continue; fi
nomatch=0
for faketag in $faketags; do
unwanted=0
if [[ $faketag == -* ]]; then
faketag=${faketag:1}
unwanted=1
fi
echo $tags | grep -F -- "$faketag" > /dev/null
result=$?
echo $faketag $result $unwanted
if [[ $result != $unwanted ]]; then
nomatch=1
break
fi
done
if (($nomatch)); then continue; fi
url=$(echo "$post" | grep -oP '(?<=file_url":")([^"]+)')
if [ -z "$url" ]; then continue; fi
name=$(echo "$url" | cut -d/ -f5)
current="$name"
if [ -e "$name" ]; then :
else
echo "$name"
$get $url > $name
if [ -n "$name" ]; then
echo $name
$get "$url" > $name
fi
done
IFS=' '
if (("$pages" == "0")); then
# first iteration, discover pagecount
@ -41,7 +68,6 @@ while true; do
'(?<=>)\d+(?=</a> <a href="/post/index[^"]+" >&gt;&gt;)' \
$tempfile)
pages=${pages:-1}
echo $pages
fi
let page++