pastebin_scraper.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/bash
  2. usage() {
  3. cat <<EOF
  4. Usage: $0 -ch -d [ DIRECTORY ] -- [ TERM ... ]
  5. Example:
  6. $0 cats
  7. $0 -h
  8. $0 -c -dl ~/pastes/ -- cats dogs
  9. EOF
  10. exit 0
  11. }
  12. err() {
  13. printf 'E: %s\n' "$@"
  14. exit 1
  15. }
  16. (( $# )) || usage
  17. while (( $# )); do
  18. case "$1" in
  19. (-d) [[ $2 ]] || err "-d requires an argument"
  20. dir="$2";
  21. shift
  22. ;;
  23. (-c) dl=1;;
  24. (-h) usage;;
  25. (--) shift; break;;
  26. (*) terms+=("$1");;
  27. esac
  28. shift
  29. done
  30. terms+=("$@")
  31. (( ${#terms[@]} )) || err "You forgot to give search terms."
  32. SAVE_DIR=${dir:-~/.paste_bin_scraper}
  33. mkdir -p -- "$SAVE_DIR"
  34. echo "Files will be saved to $SAVE_DIR"
  35. for term in "${terms[@]}"; do
  36. if (( dl )); then
  37. echo "Downloading files please wait"
  38. curl -s -- "https://psbdmp.ws/api/search/$term" \
  39. | jq -r '.data[].id' \
  40. | xargs -I{} -- wget -P "$SAVE_DIR" -nc -- https://pastebin.com/raw/{}
  41. else
  42. echo "Search term $term"
  43. echo "Total files: $(curl -s "https://psbdmp.ws/api/search/$term" | jq ".data" | wc -l)"
  44. fi
  45. done