Displaced Geek

Just a city geek and father coming to terms with being replanted in farm country

imgurdl 0.5

NINJA EDIT: Apparently this form only works with certain imgur album layouts, probably due to the ridiculous awk nonsense I did to get my source urls. I don’t care right now, if I try to download an album and it doesn’t work, maybe then I’ll fix it.
Revisions are welcome in the comments

Sorted.

 

Unsatisfied with the flexibility of other options, I hacked this together the other day to download a large wallpaper archive, and thought it might be useful. It’s uncommented save for the usage text, but really, if you need an explanation for this, then I suggest you start here.

Relative paths don’t work properly in $2, which is obviously a quoting issue, but it met my needs, so I expect all work on this to cease for now.

#!/bin/bash
if [ -z "$2" ]
then
echo "Usage: imgurdl (album address) (savedir)"
exit
else
SEQ=/usr/bin/seq
albumaddy=$1
rawlist=$(curl $albumaddy | awk '/image" id="/ {print $3}')
alist=( $(echo $rawlist) )
echo " Number of files to download is $(( ${#alist[@]} ))"
echo " Continue?"
read dl
case "$dl" in
"n"*|"N"*)
exit
;;
"y"*|"Y"*)
for i in $($SEQ 0 $((${#alist[@]} - 1)))
do
#echo "alist $i = "${alist[$i]}
newlist[$i]=${alist[$i]:4:(${#alist[$i]}-6)}
echo "Remote filename = "${newlist[$i]}".jpg"
echo "Local filename = "$i"."${newlist[$i]}".jpg"
wget -r --tries=10 -q --limit-rate=968k -w 3 --random-wait -nd -U "Firefox" http://i.imgur.com/"${newlist[$i]}".jpg -P $2 -O $i.${newlist[$i]}.jpg
# len=${#alist[$i]}
done

;;
*)
exit
esac
fi

Advertisements

Written by Peter

December 28, 2011 at 1510

Posted in geek

Tagged with , , ,

%d bloggers like this: