Displaced Geek

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

imgurdl 1.0

Partially working crap is fine for home use, but serving it up for public consumption bugged me.

#!/bin/bash
if [ -z "$2" ]
then
echo "Usage: imgurdl (album address) (savedir)"
exit
else
SEQ=/usr/bin/seq
albumaddy=$1
rawlist=$(curl -s $albumaddy | awk 'BEGIN {RS = ","} /\"hash\":"/ {print substr($0,RSTART+10,5)}')
touch ~/cookie.txt
wget --cookies=on --keep-session-cookies --save-cookies=~/cookie.txt $albumaddy
echo "$rawlist"
alist=( $(echo $rawlist) )
echo "alist1 = ${alist[1]}"
echo "alist5 = ${alist[5]}"
#5 to 9
echo " Number of files to download is $(( ${#alist[@]} ))"
echo " Continue?"
read dl
case "$dl" in
"n"*|"N"*)
exit
;;
"y"*|"Y"*)
cd $2
for i in $($SEQ 0 $((${#alist[@]} - 1)))
do
#echo "alist $i = "${alist[$i]}
#newlist[$i]=${alist[$i]:4:(${#alist[$i]}-6)}
echo "Remote filename = "${alist[$i]}".jpg"
echo "Local filename = "$i"."${alist[$i]}".jpg"
# echo ${newlist[$i]}
wget --referer=$albumaddy --cookies=on --load-cookies=~/cookie.txt --keep-session-cookies --save-cookies=cookie.txt -r --tries=10 -q --limit-rate=968k -w 3 --random-wait -nd -U "Firefox" http://i.imgur.com/"${alist[$i]}".jpg -P $2 -O $i.${alist[$i]}.jpg
# len=${#alist[$i]}
#working newlist[$i]=${alist[$i]:4:(${#alist[$i]}-6)}
# {newlist[$i]}=$(${alist[$i]:5:(${#alist[$i]}-2)})
#echo "newlist $i = "${newlist[$i]}
done

;;
*)
exit
esac
fi

 

Advertisements

Written by Peter

December 28, 2011 at 1714

Posted in geek

Tagged with , , , ,

One Response

Subscribe to comments with RSS.

  1. […] Sorted. […]

    imgurdl 0.5 « Displaced Geek

    December 28, 2011 at 1715


Comments are closed.

%d bloggers like this: