mirror of
https://github.com/notwa/rc
synced 2024-11-05 02:29:06 -08:00
This commit is contained in:
parent
cea9e4a42f
commit
6a28f54c32
1 changed files with 36 additions and 10 deletions
46
danny.sh
46
danny.sh
|
@ -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[^"]+" >>>)' \
|
||||
$tempfile)
|
||||
pages=${pages:-1}
|
||||
echo $pages
|
||||
fi
|
||||
|
||||
let page++
|
||||
|
|
Loading…
Reference in a new issue