Initial import.
[utils.git] / planime
1 #!/bin/sh
2
3 cmdline=(mplayer -fs)
4
5 while [ "${1:0:1}" = - ]; do
6     a="$1"
7     shift
8     case "$a" in
9         -t)
10             cmdline=("${cmdline[@]}" -ao oss:/dev/dsp1)
11             ;;
12         -s)
13             savepar="$1"
14             shift
15             saveval="$1"
16             shift
17             ;;
18     esac
19 done
20
21 if [ $# -lt 1 ]; then
22     echo "usage: planime [QUAL] EPNUM" >&2
23     exit 1
24 fi
25 if [ $# -eq 1 ]; then
26     ep="$1"
27     unset qual
28 elif [ $# -eq 2 ]; then
29     qual="$1"
30     ep="$2"
31 fi
32
33 if [ ! -r "$ep" ]; then
34     if [ -z "$qual" ]; then
35         ep="$(basename "$(pwd)") - ${ep}"
36     else
37         ep="$(basename "$(pwd)") ${qual} - ${ep}"
38     fi
39     if [ -r "${ep}.ogm" ]; then
40         ep="${ep}.ogm"
41         defopts=(-aid 1 -sid 0)
42     elif [ -r "${ep}.mkv" ]; then
43         ep="${ep}.mkv"
44         defopts=(-slang eng -alang jpn)
45     elif [ -r "${ep}.mpg" ]; then
46         ep="${ep}.mpg"
47     elif [ -r "${ep}.mp4" ]; then
48         ep="${ep}.mp4"
49     elif [ -r "${ep}.avi" ]; then
50         ep="${ep}.avi"
51     fi
52 fi
53
54 if [ ! -r "$ep" ]; then
55     echo "no such episode: $ep" >&2
56     exit 1
57 fi
58
59 ifile=".${ep}.info"
60
61 if [ -n "$savepar" ]; then
62     if [ -r "$ifile" ]; then
63         exec 3<"$ifile"
64         rm "$ifile"
65         egrep -v "^${savepar}:" 0<&3 >"$ifile"
66         exec 3<&-
67     fi
68     echo "$savepar: $saveval" >>"$ifile"
69     exit 0
70 fi
71
72 unset delay
73
74 if [ -r "$ifile" ]; then
75     delay="`sed -n 's/delay *: *\([^ ]*\)$/\1/p' <"$ifile"`"
76     cmdline=("${cmdline[@]}" -delay "$delay")
77 else
78     cmdline=("${cmdline[@]}" "${defopts[@]}")
79 fi
80
81 if [ "`hostname`" = pc6 ]; then chwp=y; fi
82
83 if [ "$chwp" = y ]; then (sleep 2; randomwp) & fi
84 "${cmdline[@]}" "$ep"