Updated theme HTML.
[utils.git] / planime
CommitLineData
94bf9c94 1#!/bin/bash
40777a19 2
25378dd8 3isnum() {
4 grep -xq '[0-9]\+' <<<"$1"
5}
6
7findfile() {
8 local file tail eq eqt m
9 for file in "$1"*; do
10 tail="${file#$1}"
11 eq="${tail%.*}"
12 m=n
13 if [ "${eq%% *}" -eq "$2" ] 2>/dev/null; then
14 if [[ "$eq" == *\ * ]]; then
15 eqt="${eq#* }"
16 else
17 eqt=
18 fi
19 m=y
20 elif [ "${eq:0:${#2}}" = "$2" ]; then
21 eqt="${eq:${#2}}"
22 if [ "${eqt:0:1}" = " " -o -z "$eqt" ]; then
23 eqt="${eqt# }"
24 m=y
25 fi
26 fi
27 if [ "$m" = y ]; then
28 if [ "$eqt" = "$3" -o "$eqt" = "($3)" ]; then
29 echo "$file"
30 return 0
31 fi
32 fi
33 done
34 return 1
35}
36
251d97ca 37origargs=("$0" "$@")
1c19e28f 38cmdline=(mplayer -fs -ass)
40777a19 39
40while [ "${1:0:1}" = - ]; do
41 a="$1"
42 shift
43 case "$a" in
529814da 44 -h)
45 echo "usage: planime [-ht] [-s PAR VAL] [NAME-QUAL] [EP|.] [TYPE-QUAL]" >&2
46 exit 0
47 ;;
40777a19 48 -t)
49 cmdline=("${cmdline[@]}" -ao oss:/dev/dsp1)
50 ;;
5f7e9143 51 -A)
52 while :; do
53 a="$1"
54 shift
55 if [ "$a" = \; ]; then
56 break;
57 fi
58 cmdline=("${cmdline[@]}" "$a")
59 done
60 ;;
40777a19 61 -s)
62 savepar="$1"
63 shift
64 saveval="$1"
65 shift
66 ;;
67 esac
68done
69
529814da 70base="$(basename "$(pwd)")"
71nextep=n
72file=
73tqual=
74if [ $# -eq 0 ]; then
75 nextep=y
e299213e 76 if [ -r curser ]; then
77 base="$base $(<curser)"
78 fi
529814da 79elif [ $# -eq 1 ]; then
80 if [ -r "$1" ]; then
81 file="$1"
82 else
83 if findfile "$base - " "$1" >/dev/null; then
84 ep="$1"
85 else
86 nextep=y
87 base="$base $1"
88 fi
89 fi
40777a19 90elif [ $# -eq 2 ]; then
529814da 91 if findfile "$base - " "$1" "$2" >/dev/null; then
92 ep="$1"
93 tqual="$2"
94 else
e299213e 95 if [ "$1" = . -a -r curser ]; then
96 base="$base $(<curser)"
97 else
98 base="$base $1"
99 fi
529814da 100 ep="$2"
101 fi
102else
e299213e 103 if [ "$1" = . -a -r curser ]; then
104 base="$base $(<curser)"
105 else
106 base="$base $1"
107 fi
40777a19 108 ep="$2"
529814da 109 tqual="$3"
110fi
111if [ "$ep" = . ]; then nextep=y; fi
112if [ "$nextep" = y -a -r nextep ]; then
113 ep="$(<nextep)"
114 if ! isnum "$ep"; then
115 echo "planime: nextep is non-numeric" >&2
116 exit 1
117 fi
40777a19 118fi
90aff0d0 119if [ -z "$file" ]; then
b8882e5f 120 file="$(findfile "$base - " "$ep" "$tqual")"
90aff0d0 121fi
529814da 122
4c7a7e70 123if [ -z "$file" -o ! -r "$file" ]; then
529814da 124 echo "planime: no matching file found" >&2
125 exit 1
126fi
127
4c7a7e70 128case "${file##*.}" in
129 ogm)
c6fdc541 130 aid=1
131 sid=0
4c7a7e70 132 ;;
133 mkv)
c6fdc541 134 alang=jpn
135 slang=eng
4c7a7e70 136 ;;
137esac
40777a19 138
b8882e5f 139ifile=".${file}.info"
40777a19 140
141if [ -n "$savepar" ]; then
142 if [ -r "$ifile" ]; then
b8882e5f 143 egrep -v "^${savepar} " "$ifile" >"$ifile.new"
081b510d 144 mv -f "$ifile.new" "$ifile"
40777a19 145 fi
b8882e5f 146 echo "$savepar $saveval" >>"$ifile"
40777a19 147 exit 0
148fi
149
150unset delay
151
152if [ -r "$ifile" ]; then
b8882e5f 153 exec 3<&0
154 exec 0<"$ifile"
155 while read par arg; do
156 if [ "$par" = delay ]; then
157 cmdline=("${cmdline[@]}" -delay "$arg")
158 elif [ "$par" = aspect ]; then
159 cmdline=("${cmdline[@]}" -aspect "$arg")
21e62b99 160 elif [ "$par" = volmod ]; then
161 cmdline=("${cmdline[@]}" -af volume="$arg")
c6fdc541 162 elif [ "$par" = alang ]; then
163 unset alang aid
164 alang="$arg"
165 elif [ "$par" = aid ]; then
166 unset alang aid
167 aid="$arg"
168 elif [ "$par" = slang ]; then
169 unset slang sid
170 slang="$arg"
171 elif [ "$par" = sid ]; then
172 unset slang sid
173 sid="$arg"
b8882e5f 174 fi
175 done
176 exec 0<&3
177 exec 3<&-
c6fdc541 178fi
179
180if [ -n "$alang" ]; then
181 cmdline=("${cmdline[@]}" -alang "$alang")
182elif [ -n "$aid" ]; then
183 cmdline=("${cmdline[@]}" -aid "$aid")
184fi
185if [ -n "$slang" ]; then
186 cmdline=("${cmdline[@]}" -slang "$slang")
187elif [ -n "$sid" ]; then
188 cmdline=("${cmdline[@]}" -sid "$sid")
40777a19 189fi
190
21e62b99 191if [ "`hostname`" = pc6 -o "`hostname`" = pc7 -a "$DISPLAY" = :1 ]; then chwp=y; fi
40777a19 192
193if [ "$chwp" = y ]; then (sleep 2; randomwp) & fi
4c7a7e70 194"${cmdline[@]}" "$file"
251d97ca 195
196if [ "$nextep" = y ]; then
1f6c2e48 197 echo "0. Save and continue (or Space)"
251d97ca 198 echo "1. Continue without saving"
1f6c2e48 199 echo "2. Save and exit (or Enter)"
200 echo "3. Exit without saving (or any key)"
251d97ca 201 IFS= read -sn1 c
202 save=n
203 cont=n
204 case "$c" in
205 0|" ")
206 save=y
207 cont=y
208 ;;
209 1)
210 cont=y
211 ;;
2d68de16 212 2|"")
251d97ca 213 save=y
214 ;;
215 esac
216 if [ "$save" = y ]; then
90aff0d0 217 let ep++
218 echo "$ep" >nextep
251d97ca 219 fi
220 if [ "$cont" = y ]; then
221 exec "${origargs[@]}"
90aff0d0 222 else
223 echo "nextep is $ep"
251d97ca 224 fi
225fi