From d736dde02f46bf0b86ed95064077616a06ca0385 Mon Sep 17 00:00:00 2001 From: Anonymous Date: Sun, 12 Aug 2012 14:30:47 +0400 Subject: [PATCH] Add http://gelbooru.com parser. --- gelbooru.com/gelbooru.sh | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 gelbooru.com/gelbooru.sh diff --git a/gelbooru.com/gelbooru.sh b/gelbooru.com/gelbooru.sh new file mode 100755 index 0000000..7e07f33 --- /dev/null +++ b/gelbooru.com/gelbooru.sh @@ -0,0 +1,38 @@ +#!/bin/bash +# Gelbooru parser +# Download pictures from http://gelbooru.com by tags +# Usage: ./gelbooru.sh [tags] [folder for pictures (will create if unset)] +# Depends: bash, wget, xmlstarlet +# License: Public Domain, http://creativecommons.org/publicdomain/mark/1.0/ + +# Check for parameters +if [[ ! $1 || "$1" == "-h" || "$1" == "--help" ]]; then + echo -e "Gelbooru parser\nDownload pictures from http://gelbooru.com by tags\nUsage: ./gelbooru.sh [tags] [folder for pictures (will create if there is no)]" + exit +fi +# Is wget installed? +if [[ ! $(wget -V) ]]; then + echo "This script requires wget. Please, read manual for your distro and install it." + exit +fi +# Is xmlstarlet installed? +if [[ ! $(xmlstarlet --version) ]]; then + echo "This script requires xmlstarlet. Please, read manual for your distro and install it." + exit +fi +folder="$2" +if [[ ! -d "$folder" ]]; then + mkdir "$folder" +fi +cd "$folder" +pagecount="0" +tags=$(echo "$1" | sed -e 's/ /%20/g') +count=$(wget -q -O - "http://gelbooru.com/index.php?page=dapi&s=post&q=index&limit=0&tags=$tags" | xmlstarlet sel -t -v /posts/@count[1]) +echo "Files in query \"$1\": $count" +while [ "$count" -ge "0" ] ; do + wget -q -O - "http://gelbooru.com/index.php?page=dapi&s=post&q=index&limit=100&pid=$pagecount&tags=$tags" | xmlstarlet sel -t -m /posts/post/@file_url -v "." -n | while read url; do + wget -nc "$url" + done + let count=count-100 + let pagecount++ +done -- 1.7.10.4