Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Gelbooru parser
- # Download pictures from http://gelbooru.com by tags. Original script from https://pastebin.com/TXGfZFNX , modified to actually work again
- # Usage: ./gelbooru.sh [tags separated by +] [folder for pictures, if left empty creats a folder named after the tags]
- # Depends: bash, wget, xmlstarlet
- # License: Public Domain, http://creativecommons.org/publicdomain/mark/1.0/
- GR='\033[38;5;82m' ; PN='\033[38;5;171m' ; BL='\033[38;5;27m' ; RD='\033[0;31m' ; PR='\033[0;35m' ; CY='\033[0;36m' ; NC='\033[0m'
- # ${}
- # Check for parameters
- if [[ ! $1 || "$1" == "-h" || "$1" == "--help" ]]; then
- echo -e "${CY}Gelbooru parser${NC}\nDownload pictures from http://gelbooru.com by tags\nUsage: ./${CY}gelbooru.sh${NC} ${BL}[tags separated by +]${NC} ${PR}[OutputDir, if left empty, creates a folder named after the tags]${NC}"
- exit
- fi
- # Is wget installed?
- if [[ ! $(wget -V) ]]; then
- echo "This script requires wget. Please read the manual for your distro and install it."
- exit
- fi
- # Is xmlstarlet installed?
- if [[ ! $(xmlstarlet --version) ]]; then
- echo "This script requires xmlstarlet. Please read the manual for your distro and install it."
- exit
- fi
- # Are GelBooru cookies available?
- cookies=GelBooruCookies.txt
- if [[ ! -f "$cookies" ]]; then
- printf "gelbooru.com%s\tFALSE%s\t/%s\tFALSE%s\t0%s\tfringeBenefits%s\tyup" > GelBooruCookies.txt
- echo -e "\nprinted cookies"
- fi
- # Adjust folder name
- folder="$2"
- if [[ ! $folder ]]; then
- folder=$(echo "$1" | sed -e 's/+/\ /')
- fi
- # Get count of pages and images
- pagecount="0"
- tags=$(echo "$1" | sed -e 's/ /%20/g')
- count=$(wget -q -O - --load-cookies ../GelBooruCookies.txt "http://gelbooru.com/index.php?page=dapi&s=post&q=index&tags=$tags" | xmlstarlet sel -t -v /posts/@count[1])
- # Ask for confirmation
- echo -e "\nQuery${BL} \"$1\" ${NC}containing${CY} $count ${NC}Files will be saved to ${PR}"$folder"${NC}"
- read -p $'press [enter] to start download, ctrl+C to cancel\x0a'
- # Create folder
- if [[ ! -d "$folder" ]]; then
- mkdir "$folder"
- fi
- cd "$folder"
- # Download
- while [ "$count" -ge "0" ] ; do
- url=$(wget -nv -O - --load-cookies ../GelBooruCookies.txt "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$)
- wget -nc $url
- let count=count-100
- let pagecount++
- done
Add Comment
Please, Sign In to add comment