IsraelTorres

getimguralbum.sh

Mar 24th, 2012
86
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. :<<israeltorres_comment_block
  3.  
  4. ./getimguralbum.sh
  5. Israel Torres
  6. 2012-03-23
  7. Simple known methods to retrieve imgur albums
  8.  
  9. Mac OS X 10.7.3 11D50d
  10. Darwin Kernel Version 11.3.0
  11. GNU bash, version 3.2.48(1)-release
  12.  
  13. israeltorres_comment_block
  14.  
  15. #required app check
  16. rqdapp='curl'
  17. hash $rqdapp 2>&- || { echo >&2 "$rqdapp binary not found - aborting"; exit 1; }
  18. #
  19. if [ ! $# -lt 1 ]; then
  20. IMGURL=$1; DLDIR=$(date +%s); mkdir $DLDIR; cd $DLDIR
  21. echo "Trying Method 1"
  22. curl "$IMGURL#0" -s | grep 'alt="" src=' | sed 's/.*src="\(.*\)".*/\1/g;s/s\./\./g' | awk '{print $1 " -O -s";}' | xargs curl
  23. if  [ ! "$(ls -A .)" ]; then #check if $DLDIR is empty from the inside
  24.     echo -e "Method 1 Failed\nTrying Method 2"
  25.     curl "$IMGURL#0" -s | grep '<a class=\"zoom\" href=\"http:' | sed 's/\<a class=\"zoom\" href=\"//g;s/\"\>//g;s///g;s/s\./\./g' | awk '{print $1 " -O -s";}' | xargs curl
  26.     if  [ "$(ls -A .)" ]; then
  27.         echo "Method 2 Passed"
  28.     else
  29.         echo "Method 2 Failed"
  30.     fi
  31. else
  32.     echo "Method 1 Passed"
  33. fi
  34.  
  35. else
  36.     echo "usage: $0 'imgur url'"
  37.     echo "example: $0 https://imgur.com/a/hEbVS"
  38. fi
  39. #eof
RAW Paste Data