Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # ImgurAlbum.sh
- #
- # Bash script to download images for an Imgur album
- #
- if [ -z "$1" ]; then
- echo "ImgurAlbum: missing Album ID"
- echo "Usage: ImgurAlbum [Album ID]"
- exit
- else
- #isolate the album id from the address
- albumID=$(echo $1 | sed -e "s|https://imgur.com/gallery/||g" | sed -e "s|http://imgur.com/gallery/||g")
- wget https://api.imgur.com/3/album/$albumID.xml --header='Authorization: Client-ID 1b138bce405b2e0' --quiet --output-document album-temp.xml
- albumName=$(xmllint --xpath "string(//title)" album-temp.xml)
- albumName=$(echo $albumName | sed -e "s|\s|_|g")
- albumDescription=$(xmllint --xpath "string(//description)" album-temp.xml)
- rm album-temp.xml
- echo "Creating directory: $albumName"
- mkdir $albumName
- cd $albumName
- echo $albumDescription > description.txt
- echo "Fetching Album Images..."
- wget https://api.imgur.com/3/album/$albumID/images.xml --header='Authorization: Client-ID 1b138bce405b2e0' --quiet --output-document images-temp.xml
- imageCount=$(xmllint --xpath "count(/data/item)" images-temp.xml)
- echo "Downloading Images to: ${PWD}"
- for (( i=1; i<=$imageCount; i++ )); do
- imageLink=$(xmllint --xpath "/data/item[$i]/link/text()" images-temp.xml)
- imageTitle=$(xmllint --xpath "/data/item[$i]/title/text()" images-temp.xml)
- imageTitle=$(echo ${imageTitle::30} | sed -e "s|\s|_|g")
- imageTitle=$i'_'$imageTitle
- #echo $imageTitle
- httpsImageLink=$(echo $imageLink | sed -e "s|http|https|g")
- #echo $httpsImageLink
- echo "Downloading Image $i of $imageCount: $httpsImageLink"
- wget -N $httpsImageLink --quiet --secure-protocol=auto -O $imageTitle
- done
- echo "Removing temporary files..."
- rm images-temp.xml
- echo
- echo "DONE: $imageCount images saved to: ${PWD}"
- echo
- cd ..
- exit
- fi
Add Comment
Please, Sign In to add comment