Initial import.
[utils.git] / planime
CommitLineData
40777a19 1#!/bin/sh
2
3cmdline=(mplayer -fs)
4
5while [ "${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
19done
20
21if [ $# -lt 1 ]; then
22 echo "usage: planime [QUAL] EPNUM" >&2
23 exit 1
24fi
25if [ $# -eq 1 ]; then
26 ep="$1"
27 unset qual
28elif [ $# -eq 2 ]; then
29 qual="$1"
30 ep="$2"
31fi
32
33if [ ! -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
52fi
53
54if [ ! -r "$ep" ]; then
55 echo "no such episode: $ep" >&2
56 exit 1
57fi
58
59ifile=".${ep}.info"
60
61if [ -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
70fi
71
72unset delay
73
74if [ -r "$ifile" ]; then
75 delay="`sed -n 's/delay *: *\([^ ]*\)$/\1/p' <"$ifile"`"
76 cmdline=("${cmdline[@]}" -delay "$delay")
77else
78 cmdline=("${cmdline[@]}" "${defopts[@]}")
79fi
80
81if [ "`hostname`" = pc6 ]; then chwp=y; fi
82
83if [ "$chwp" = y ]; then (sleep 2; randomwp) & fi
84"${cmdline[@]}" "$ep"