Mercurial > ec-dotfiles
comparison bin/xkcdmania @ 124:5bafb912837e
Massive addition of old scripts collection.
author | Edho Prima Arief <edho@myconan.net> |
---|---|
date | Wed, 26 Oct 2011 15:22:00 +0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
123:173833e4ba35 | 124:5bafb912837e |
---|---|
1 #!/bin/sh | |
2 | |
3 dir="/anime/misc/webcomics/xkcd" | |
4 [ -d "${dir}" ] || exit 1 | |
5 | |
6 fetchlink() { | |
7 if [ "$1" -a "$2" ]; then | |
8 wget --quiet -O "$2" "$1" | |
9 else | |
10 return 1 | |
11 fi | |
12 } | |
13 latest=$(fetchlink http://xkcd.com/ - | grep 'Permanent link' | sed -e 's/.*\/\([0-9]*\)\/.*/\1/') | |
14 [ -n "${latest}" ] || exit 1 | |
15 next=1 | |
16 while [ "${next}" -le "${latest}" ]; do | |
17 to_dl="${to_dl} ${next}" | |
18 next=$((next + 1)) | |
19 done | |
20 | |
21 for i in $to_dl | |
22 do | |
23 if [ ! -n "$(find "$dir/$(printf '%04d' $i)"* -type f 2>/dev/null)" ] && [ "${i}" -ne 404 ]; then | |
24 page=$(fetchlink "http://xkcd.com/$i/" -) | |
25 img=$(echo "$page" | grep 'Image URL' | sed -e 's/.*\(http[^<]*\).*/\1/' | head -n 1) | |
26 echo "$(echo "$page" | grep "src" | grep "$img" | sed -e 's/.*title="\([^\"]*\)".*/\1/')" > "$dir/$(printf '%04d' $i) $(basename $img | sed -e 's/\(.*\)\..*/\1/').txt" | |
27 fetchlink "${img}" "$dir/$(printf '%04d' $i) $(basename "$img")" | |
28 fi | |
29 done |