Advertisement
Guest User

gelbooru.sh

a guest
Jun 23rd, 2012
544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.48 KB | None | 0 0
  1. #!/bin/bash
  2. # Gelbooru parser
  3. # Download pictures from http://gelbooru.com by tags
  4. # Usage: ./gelbooru.sh [tags] [folder for pictures (will create if unset)]
  5. # Depends: bash, wget, xmlstarlet
  6. # License: Public Domain, http://creativecommons.org/publicdomain/mark/1.0/
  7.  
  8. # Check for parameters
  9. if [[ ! $1 || "$1" == "-h" || "$1" == "--help" ]]; then
  10.         echo -e "Gelbooru parser\nDownload pictures from http://gelbooru.com with tags\nUsage: ./gelbooru.sh [tags] [folder for pictures (will create if there is no)]"
  11.         exit
  12. fi
  13. # Is wget installed?
  14. if [[ ! $(wget -V) ]]; then
  15.         echo "This script requires wget. Please, read manual for your distro and install it."
  16.         exit
  17. fi
  18. # Is xmlstarlet installed?
  19. if [[ ! $(xmlstarlet --version) ]]; then
  20.         echo "This script requires xmlstarlet. Please, read manual for your distro and install it."
  21.         exit
  22. fi
  23. folder="$2"
  24. if [[ ! -d "$folder" ]]; then
  25.         mkdir "$folder"
  26. fi
  27. cd "$folder"
  28. pagecount="0"
  29. tags=$(echo "$1" | sed -e 's/ /%20/g')
  30. count=$(wget -q -O - "http://gelbooru.com/index.php?page=dapi&s=post&q=index&tags=$tags" | xmlstarlet sel -t -v /posts/@count[1])
  31. echo "Files in query \"$1\": $count"
  32. while [ "$count" -ge "0" ] ; do
  33.         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$
  34.                 wget -nc "$url"
  35.         done
  36.         let count=count-100
  37.         let pagecount++
  38. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement