summaryrefslogtreecommitdiffstats
path: root/bin/comics/MANvsMAGIC
blob: a1aa77cd82d35c86f2c6ad2d3add09ad3ae46361 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash

if [ -z "$1" -o ! -d "$1" ]; then
    echo "Usage: $0 <top-directory> [<days ago>]" 1>&2
    exit 1
fi

top="${1}"
shift

source "${top}/etc/settings.sh"
tmp="$(mktemp -d)"
cd "${tmp}"

browser="Mozilla/4.76 [de] (X11; U; Linux 2.2.18 i586)"

TARGET_URL=$(wget ${wget_args} -q -U "$browser" "http://www.manvsmagic.com/archive/" -O - | sed -nre "s#.+href=\"(/`date -d "$daysago days ago" +%Y/%m/%d`/[^\"]+)\".+#\1#p")
newn="${day}.png"

if [ -n "$TARGET_URL" ]; then
	echo "Found $TARGET_URL"
	wget ${wget_args} -U "$browser" http://www.manvsmagic.com$TARGET_URL -q -O index.html

	IMG_URL=`sed -nre 's#.+img src="(/images/[^"]+)".+#\1#p' index.html`
	if [ -n "$IMG_URL" ]; then
		IMG_URL=http://www.manvsmagic.com$IMG_URL
		ALT=`sed -nre 's#.+img src="/images.+alt="([^"]+).+#\1#p' index.html`

		echo "Img is $IMG_URL"
		echo "Alt is $ALT"

		wget ${wget_args} -U "$browser" -O "${tmp}/${newn}" --header="Referer: http://www.manvsmagic.com/" "$IMG_URL"

		if [ -s "${tmp}/${newn}" ]; then
			mv "${tmp}/${newn}" "${image_dir}/$newn"
			echo "$ALT" > "${image_dir}/${day}.alt"

			# update symlinks
			rm -f "${comic_dir}/latest.png" "${comic_dir}/latest.title" "${comic_dir}/latest.alt"
			ln -s "${image_offset}/$newn" "${comic_dir}/latest.png"
			ln -s "${image_offset}/${day}.alt" "${comic_dir}/latest.alt"
		fi
	fi
fi

rm -rf ${tmp}