4 grep -xq '[0-9]\+' <<<"$1"
8 if [ "${1##*.}" = mkv ]; then
10 elif [ "${1##*.}" = ogm ]; then
18 if [ -r aliases ]; then
19 while read alias rest; do
20 if [ "$alias" = "$1" ]; then
30 if [ -n "$debug" ]; then echo "finding base='$1', ep='$2', qual='$3'" >&2; fi
31 local base file tail eq eqt m matches max score
33 base="$(findbase "$1")"
34 for file in "$base"*; do
35 tail="${file#"$base"}"
38 if [ "${eq%% *}" -eq "$2" ] 2>/dev/null; then
39 if [[ "$eq" == *\ * ]]; then
45 elif [ "${eq:0:${#2}}" = "$2" ]; then
47 if [ "${eqt:0:1}" = " " -o -z "$eqt" ]; then
53 if [ "$eqt" = "$3" -o "$eqt" = "($3)" -o "${eqt:0:2}" = "- " ]; then
54 matches=("${matches[@]}" "$file")
58 if [ ${#matches[@]} -lt 1 ]; then return 1; fi
60 for m in "${matches[@]}"; do
61 score="$(scorefile "$m")"
62 if [ -n "$debug" ]; then echo "found \`$m': score $score" >&2; fi
63 if [ -z "$max" ] || [ "$score" -gt "$max" ]; then
68 if [ -n "$debug" ]; then echo "using \`$file'" >&2; fi
77 unset pretend printfile
79 while [ "${1:0:1}" = - ]; do
84 echo "usage: planime [-fdhtCL] [-A PLAYER-ARGS... ;] [-s PAR VAL] [--] [NAME-QUAL] [EP|.] [TYPE-QUAL]" >&2
91 cmdline=("${cmdline[@]}" -ao 'alsa:device=[hw:3,7]')
103 if [ $# -lt 1 ]; then
104 echo "planime: unterminated argument list" >&2
109 if [ "$a" = \; ]; then
112 cmdline=("${cmdline[@]}" "$a")
125 cmdline=("${cmdline[@]}" -v)
131 echo "planime: unknown option \`$a'"
137 dirbase="$(basename "$(pwd)")"
142 if [ $# -eq 0 ]; then
144 elif [ $# -eq 1 ]; then
151 elif [ $# -eq 2 ]; then
152 if findfile "$dirbase - " "$1" "$2" >/dev/null; then
165 if [ "$ep" = . ]; then nextep=y; fi
166 if [ "$nextep" = y -a -r nextep ]; then
168 if ! isnum "$ep"; then
169 echo "planime: nextep is non-numeric" >&2
173 if [ -z "$file" ]; then
174 if [ "$base" = . ]; then
175 if [ -r curser ]; then
181 curser="$(findbase "$base")"
183 if [ -n "$curser" ]; then
184 file="$(findfile "$dirbase $curser - " "$ep" "$tqual")" || \
185 file="$(findfile "$curser - " "$ep" "$tqual")"
187 file="$(findfile "$dirbase - " "$ep" "$tqual")"
191 if [ -z "$file" -o ! -r "$file" ]; then
192 echo "planime: no matching file found" >&2
196 case "${file##*.}" in
207 ifile=".${file}.info"
209 if [ -n "$savepar" ]; then
210 if [ -r "$ifile" ]; then
211 egrep -v "^${savepar} " "$ifile" >"$ifile.new"
212 mv -f "$ifile.new" "$ifile"
214 echo "$savepar $saveval" >>"$ifile"
220 if [ -r "$ifile" ]; then
223 while read par arg; do
224 if [ "$par" = delay ]; then
225 cmdline=("${cmdline[@]}" -delay "$arg")
226 elif [ "$par" = aspect ]; then
227 cmdline=("${cmdline[@]}" -aspect "$arg")
228 elif [ "$par" = volmod ]; then
229 cmdline=("${cmdline[@]}" -af volume="$arg")
230 elif [ "$par" = alang ]; then
233 elif [ "$par" = aid ]; then
236 elif [ "$par" = slang ]; then
239 elif [ "$par" = sid ]; then
248 if [ -n "$alang" ]; then
249 cmdline=("${cmdline[@]}" -alang "$alang")
250 elif [ -n "$aid" ]; then
251 cmdline=("${cmdline[@]}" -aid "$((aid + 1))")
253 if [ -n "$slang" ]; then
254 cmdline=("${cmdline[@]}" -slang "$slang")
255 elif [ -n "$sid" ]; then
256 cmdline=("${cmdline[@]}" -sid "$((sid + 1))")
259 if [ -n "$pretend" ]; then
260 echo "${cmdline[@]}" "$file"
261 elif [ -n "$printfile" ]; then
264 if [ "$chwp" = y ]; then (sleep 2; randomwp) & fi
265 if [ "$log" = y ]; then
266 if [ -d $HOME/.anime ]; then
267 echo "$(date) $(basename "$file")" >>$HOME/.anime/plog
270 "${cmdline[@]}" "$file"
272 if [ "$nextep" = y ]; then
273 echo "0. Save and continue (or Space)"
274 echo "1. Continue without saving"
275 echo "2. Save and exit (or Enter)"
276 echo "3. Exit without saving (or any key)"
292 if [ "$save" = y ]; then
296 if [ "$cont" = y ]; then
297 exec "${origargs[@]}"