forked from hamano/ame.sh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ame.sh
executable file
·98 lines (91 loc) · 2.35 KB
/
ame.sh
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env bash
# ame.sh
function ame_init() {
deps=(curl convert)
for d in $deps; do
if ! type $d > /dev/null 2>&1; then
echo "$d not found"
exit 1
fi
done
if [ ! -d ~/.ame ]; then
mkdir -p ~/.ame
fi
if [ ! -f ~/.ame/map000.pnm ]; then
convert http://tokyo-ame.jwa.or.jp/map/map000.jpg ~/.ame/map000.pnm
fi
if [ ! -f ~/.ame/msk000.png ]; then
curl -s -o ~/.ame/msk000.png http://tokyo-ame.jwa.or.jp/map/msk000.png
fi
}
function ame_print() {
SIZE="640x"
TIME=$1
LABEL=${TIME:8:2}:${TIME:10}
URI=http://tokyo-ame.jwa.or.jp/mesh/000/${TIME}.gif
convert -compose over ~/.ame/map000.pnm \
$URI \
-composite ~/.ame/msk000.png \
-undercolor white -stroke gray -pointsize 26 -gravity south -annotate 0 " ${LABEL} " \
-resize ${SIZE} \
-composite sixel:-
}
function ame_last() {
LAST=`curl -s http://tokyo-ame.jwa.or.jp/scripts/mesh_index.js \
|sed -e 's/[^0-9,]//g' -e 's/,/\n/g'|head -1`
ame_print "${LAST}"
}
function ame_play() {
INDEX=`curl -s http://tokyo-ame.jwa.or.jp/scripts/mesh_index.js \
|sed -e 's/[^0-9,]//g' -e 's/,/\n/g'|tac`
declare -a TIMES=()
for t in $INDEX; do
TIMES+=( ${t} )
ame_print $t
sleep 0.5
done
i=$((${#TIMES[@]}-1))
while IFS= read -r -n1 -s c; do
if [[ $c == $'\x1b' ]]; then
read -r -n2 -s rest
c+="$rest"
fi
case $c in
l | j | $'\x1b\x5b\x43' | $'\x1b\x5b\x42')
let i++
if [ $i -ge ${#TIMES[@]} ]; then
i=$((${#TIMES[@]}-1))
fi
ame_print ${TIMES[$i]}
echo "time: ${TIMES[$i]}"
;;
h | k | $'\x1b\x5b\x44' | $'\x1b\x5b\x41')
let i--
if [ $i -lt 0 ]; then
i=0
fi
ame_print ${TIMES[$i]}
echo "time: ${TIMES[$i]}"
;;
esac
done
}
function usage() {
echo "Usage: $0 [--play]" 1>&2
exit 1
}
while getopts :h:play opt
do
case $opt in
h)
usage
;;
p)
ame_init
ame_play
exit
;;
esac
done
ame_init
ame_last