mirror of
https://github.com/notwa/rc
synced 2025-02-05 07:43:22 -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
|
#!/bin/bash
|
||||||
set -o nounset
|
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
|
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
|
pages=0
|
||||||
tempfile=`mktemp`
|
tempfile=`mktemp`
|
||||||
current=
|
current=
|
||||||
|
@ -24,16 +27,40 @@ page=1
|
||||||
while true; do
|
while true; do
|
||||||
$get "http://$ip/${webpage}${page}" > "$tempfile"
|
$get "http://$ip/${webpage}${page}" > "$tempfile"
|
||||||
|
|
||||||
image_urls=$(grep -oP '(?<=file_url":")([^"]+)' $tempfile)
|
posts=$(grep 'Post\.register({' "$tempfile")
|
||||||
for url in $image_urls; do
|
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)
|
name=$(echo "$url" | cut -d/ -f5)
|
||||||
current="$name"
|
current="$name"
|
||||||
if [ -e "$name" ]; then :
|
if [ -n "$name" ]; then
|
||||||
else
|
echo $name
|
||||||
echo "$name"
|
$get "$url" > $name
|
||||||
$get $url > $name
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
IFS=' '
|
||||||
|
|
||||||
if (("$pages" == "0")); then
|
if (("$pages" == "0")); then
|
||||||
# first iteration, discover pagecount
|
# first iteration, discover pagecount
|
||||||
|
@ -41,7 +68,6 @@ while true; do
|
||||||
'(?<=>)\d+(?=</a> <a href="/post/index[^"]+" >>>)' \
|
'(?<=>)\d+(?=</a> <a href="/post/index[^"]+" >>>)' \
|
||||||
$tempfile)
|
$tempfile)
|
||||||
pages=${pages:-1}
|
pages=${pages:-1}
|
||||||
echo $pages
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
let page++
|
let page++
|
||||||
|
|
Loading…
Add table
Reference in a new issue