Guest User

Imgur Downloader

a guest
Feb 27th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.81 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # ImgurAlbum.sh
  4. #
  5. # Bash script to download images for an Imgur album
  6. #
  7. if [ -z "$1" ]; then
  8. echo "ImgurAlbum: missing Album ID"
  9. echo "Usage: ImgurAlbum [Album ID]"
  10. exit
  11. else
  12.  
  13. #isolate the album id from the address
  14. albumID=$(echo $1 | sed -e "s|https://imgur.com/gallery/||g" | sed -e "s|http://imgur.com/gallery/||g")
  15.  
  16. wget https://api.imgur.com/3/album/$albumID.xml --header='Authorization: Client-ID 1b138bce405b2e0' --quiet --output-document album-temp.xml
  17.  
  18. albumName=$(xmllint --xpath "string(//title)" album-temp.xml)
  19. albumName=$(echo $albumName | sed -e "s|\s|_|g")
  20. albumDescription=$(xmllint --xpath "string(//description)" album-temp.xml)
  21.  
  22. rm album-temp.xml
  23.  
  24. echo "Creating directory: $albumName"
  25. mkdir $albumName
  26. cd $albumName
  27. echo $albumDescription > description.txt
  28.  
  29. echo "Fetching Album Images..."
  30. wget https://api.imgur.com/3/album/$albumID/images.xml --header='Authorization: Client-ID 1b138bce405b2e0' --quiet --output-document images-temp.xml
  31. imageCount=$(xmllint --xpath "count(/data/item)" images-temp.xml)
  32. echo "Downloading Images to: ${PWD}"
  33. for (( i=1; i<=$imageCount; i++ )); do
  34.         imageLink=$(xmllint --xpath "/data/item[$i]/link/text()" images-temp.xml)
  35.         imageTitle=$(xmllint --xpath "/data/item[$i]/title/text()" images-temp.xml)
  36.        
  37.         imageTitle=$(echo ${imageTitle::30} | sed -e "s|\s|_|g")
  38.         imageTitle=$i'_'$imageTitle
  39.         #echo $imageTitle
  40.  
  41.         httpsImageLink=$(echo $imageLink | sed -e "s|http|https|g")
  42.         #echo $httpsImageLink
  43.        
  44.         echo "Downloading Image $i of $imageCount: $httpsImageLink"
  45.         wget -N $httpsImageLink --quiet --secure-protocol=auto -O $imageTitle
  46. done
  47. echo "Removing temporary files..."
  48. rm images-temp.xml
  49. echo
  50. echo "DONE: $imageCount images saved to: ${PWD}"
  51. echo
  52. cd ..
  53. exit
  54. fi
Add Comment
Please, Sign In to add comment