From 98b94536f785e9f881cc0a21a216812d1fdf4325 Mon Sep 17 00:00:00 2001 From: notwa Date: Mon, 29 Jul 2013 00:45:45 -0700 Subject: [PATCH 1/4] --- boorufind | 44 ++++++++++++++++++++++++++++++++++++++++++++ boorugrab | 18 ++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 boorufind create mode 100644 boorugrab diff --git a/boorufind b/boorufind new file mode 100644 index 0000000..bac9476 --- /dev/null +++ b/boorufind @@ -0,0 +1,44 @@ +#!/bin/zsh +q=$1 +url='http://danbooru.donmai.us/posts.xml' +de=--data-urlencode + +curl=(curl -sS -m 32 --connect-timeout 8 --retry 3 --retry-delay 1) + +die() { + echo -E "$@" >&2 + exit 1 +} + +push() { + if [ -z $md5 ] || [ -z $ext ] || [ -z $size ]; then + print missing value >&2 + return + fi + local fn=$md5.$ext + local s="$(find . -name $fn 2>/dev/null)" + [ -n "$s" ] && print $s || print \#$fn + md5= ext= size= +} + +page=1 +while; do + once=0 + ${curl[@]} -G -d page=search -d limit=100 -d page=$page $de tags=$q $url \ + | xml2 2>/dev/null \ + | while IFS== read -r tree val; do + [ $tree = /posts/post ] && push && continue + [ ${tree:0:12} = /posts/post/ ] && tree=${tree:12} || continue + once=1 + + case $tree in + (md5) md5=$val ;; + (file-ext) ext=$val ;; + (file-size) size=$val ;; + esac + done + [[ ${PIPESTATUS[1]} -eq 0 ]] || die "curl failed on page $page" + [[ $once -eq 0 ]] && exit 0 # no posts left, well done + push + let page++ +done diff --git a/boorugrab b/boorugrab new file mode 100644 index 0000000..95bd4a8 --- /dev/null +++ b/boorugrab @@ -0,0 +1,18 @@ +#!/bin/zsh +dir=$1 +url='http://danbooru.donmai.us/data/' + +curl=(curl -sS -m 900 --connect-timeout 8 --retry 3 --retry-delay 1) + +mkdir -p $dir +while read -r; do + if [[ ${REPLY[1]} = "#" ]]; then + md5e=${REPLY:1} + ${curl[@]} $url$md5e > $dir/$md5e || rm -f $dir/$md5e + else + md5e=${REPLY##*/} + [ -s $dir/$md5e ] && continue + [ $REPLY -ef $dir/$md5e ] || cp $REPLY $dir + fi +done +# zsh builtin md5 sum? From 20b8930ee6c5cadd153ca2ec9e0ac79ffeb4e8ec Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Mon, 29 Jul 2013 00:49:47 -0700 Subject: [PATCH 2/4] no such thing --- boorugrab | 1 - 1 file changed, 1 deletion(-) diff --git a/boorugrab b/boorugrab index 95bd4a8..15119c4 100644 --- a/boorugrab +++ b/boorugrab @@ -15,4 +15,3 @@ while read -r; do [ $REPLY -ef $dir/$md5e ] || cp $REPLY $dir fi done -# zsh builtin md5 sum? From e4732d88cd53d0f91cb0bde53ced0bddf5c32ee2 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Fri, 1 Nov 2013 20:08:34 -0700 Subject: [PATCH 3/4] whatever --- boorufind | 2 +- boorugrab | 29 ++++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) mode change 100644 => 100755 boorufind mode change 100644 => 100755 boorugrab diff --git a/boorufind b/boorufind old mode 100644 new mode 100755 index bac9476..778d94b --- a/boorufind +++ b/boorufind @@ -24,7 +24,7 @@ push() { page=1 while; do once=0 - ${curl[@]} -G -d page=search -d limit=100 -d page=$page $de tags=$q $url \ + ${curl[@]} -G -d limit=100 -d page=$page $de tags=$q $url \ | xml2 2>/dev/null \ | while IFS== read -r tree val; do [ $tree = /posts/post ] && push && continue diff --git a/boorugrab b/boorugrab old mode 100644 new mode 100755 index 15119c4..07343e1 --- a/boorugrab +++ b/boorugrab @@ -4,14 +4,37 @@ url='http://danbooru.donmai.us/data/' curl=(curl -sS -m 900 --connect-timeout 8 --retry 3 --retry-delay 1) +cleanup() { + [ -e $dir/$md5e ] && { + rm -f $dir/$md5e + echo "\e[F\e[K$md5e - canceled" + } + exit 1 +} +trap cleanup INT + mkdir -p $dir while read -r; do if [[ ${REPLY[1]} = "#" ]]; then md5e=${REPLY:1} - ${curl[@]} $url$md5e > $dir/$md5e || rm -f $dir/$md5e + 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!" else md5e=${REPLY##*/} - [ -s $dir/$md5e ] && continue - [ $REPLY -ef $dir/$md5e ] || cp $REPLY $dir + [ $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!" fi done From 9c69160563400621b9ea249552e4954bfd7d32f4 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sun, 8 Dec 2013 06:21:28 -0800 Subject: [PATCH 4/4] quit finding after one match --- boorufind | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boorufind b/boorufind index 778d94b..487d425 100755 --- a/boorufind +++ b/boorufind @@ -16,7 +16,7 @@ push() { return fi local fn=$md5.$ext - local s="$(find . -name $fn 2>/dev/null)" + local s="$(find . -name $fn -print -quit 2>/dev/null)" [ -n "$s" ] && print $s || print \#$fn md5= ext= size= }