blob: 0925a4faf683d1c095242021f9dcccbcf7ba3001 (
plain)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
#!/bin/zsh
HIST="$HOME/.mplayer.hist"
AUX_INVO=0
POSITION=0
maxplayers=1
network=0
stdin=0
firstime=0
randnum=$((${RANDOM}%${maxplayers}))
mkdir -p /tmp/mplayer
MPSOCKET="/tmp/mplayer/$randnum.fif"
fixedvo=1
typeset -A vo_map
vo_map=(1 fixed-vo 0 nofixed-vo)
pecho(){
msg="$1"
file="$2"
/bin/echo "$msg" >| $file &
sleep 0.1
echo < $file
}
# curl for non-strict url parsing ;)
isurl () {
url="[email protected]"
curl -I -s "$url" &>/dev/null || return 1
return 0
}
check_pattern(){
pecho "get_property filename" $1
if tail -2 /tmp/mplayer.log | /bin/grep 'ANS_filename' | /bin/grep -v grep ;then
pecho "get_property pause" $1
if tail -2 /tmp/mplayer.log | /bin/grep 'ANS_pause=no' | /bin/grep -v grep ;then
retval=0
return 0
fi
retval=2
fi
[[ -z $retval ]] && retval=1
return 1
}
parse(){
if [[ -z "$1" ]];then
fnum=$(awk '{ print NR" "$0 }' $HIST | cut -d ":" -f 1 | uniq -f 1 | tac | ${=DMENU})
[[ -z "$fnum" ]] && exit
num=$(echo "$fnum" | cut -d " " -f 1)
FILE=$(head -${num} $HIST | tail -1 | cut -d ":" -f 1)
if [[ $fnum == *: ]];then
name="$(cut -d ' ' -f 1 <<< $FILE)"
POSITION="$(grep $name $HIST | tail -1 | cut -d ':' -f 2)"
fi
else
if [[ $1 == "-" ]];then
stdin=1
return
fi
if isurl "$(tr -d '.' <<< $1)";then # Fix /a/b/c/d type
FILE="$1"
network=1
else
if [[ "[email protected]" == /* ]];then
prefix=
else
prefix="$pwdir/"
fi
FILE="${prefix}[email protected]"
fi
fi
retval=$FILE
}
preplay(){
mpc pause &>/dev/null
ln -sf $MPSOCKET /tmp/mplayer.fif || exit 1
}
check_status(){
if [[ $fixedvo == 1 ]];then
pidof mplayer || return 1
echo >>| /tmp/mplayer.log
retval=1
for ff in /tmp/mplayer/*.fif;do
if check_pattern $ff;then
return $retval
fi
done
return $retval
else
if xdotool search --class mplayer;then
return 1
else
return 0
fi
fi
}
aux(){
case $1 in
status)
check_status
return $?
;;
clean)
rm /tmp/mplayer/* 2>/dev/null
rm /tmp/mplayer.fif 2>/dev/null
killall -9 mplayer 2>/dev/null
rm /tmp/locks/mplayer* 2>/dev/null
mv /tmp/mplayer.log /tmp/.mplayer.log
exit
;;
pause)
pecho 'pause' $MPSOCKET
;;
snext)
pecho 'seek +10' $MPSOCKET
;;
sprev)
pecho 'seek -10' $MPSOCKET
;;
pnext)
pecho "pt_step 1" $MPSOCKET
;;
pprev)
pecho "pt_step -1" $MPSOCKET
;;
stop)
wheret
echo "$retval" >>| ~/.mplayer.hist
pecho 'stop' $MPSOCKET
echo "#STOPPED ${file}" >>| /tmp/mplayer.log
;;
*)
return 1
esac
}
wheret(){
pecho 'get_time_pos' $MPSOCKET
pecho 'get_property path' $MPSOCKET
sleep 3
LOG="tail -5 /tmp/mplayer.log"
position=$(${=LOG} | /bin/grep ANS_TIME_POSITION | head -1 | cut -d "=" -f 2)
file=$(${=LOG} | /bin/grep ANS_path | head -1 | cut -d "=" -f 2)
retval="$file:$position"
}
if [[ $0 == *mplayeraux ]];then
AUX_INVO=1
aux [email protected]
exit $?
fi
if [[ ! -e $MPSOCKET ]] ;then
firstime=1
mkfifo $MPSOCKET
ln -sf $MPSOCKET /tmp/mplayer.fif
#notify-send "Mplayer" "mplayer starting up....."
fi
exec &>>|/tmp/mplayer.log
pwdir=$(pwd)
pushd $HOME
${=LOCK}/mplayer.$randnum /usr/bin/mplayer -$vo_map[$fixedvo] -msglevel all=4 -slave -idle -input file=$MPSOCKET -input conf=$HOME/.mplayer/input.conf.mine &!
popd
parse [email protected]
FILE=$retval
preplay
[[ $firstime == 1 ]] && sleep 3
if [[ $stdin == 1 ]];then
#pecho "loadfile /dev/fd/0" /tmp/mplayer.fif
/usr/bin/mplayer -
exit 110
else
pecho "loadfile \"$FILE\" 2" $MPSOCKET
fi
check_status
# Queue or play
if [[ $? == 1 ]];then
notify-send "Player" "^i(/home/raghavendra/.notify-icons/mplayer.xpm) ^fg(red)FILE:^fg() $FILE:t queued"
else
if [[ ! $POSITION == 0* ]];then
sleep 1
pecho "set_property time_pos $POSITION" $MPSOCKET
notify-send "Player" "^i(/home/raghavendra/.notify-icons/mplayer.xpm) ^fg(red)FILE:^fg() $FILE:t ^fg(green)POSITION:^fg() ${POSITION:-0:0}"
else
notify-send "Player" "^i(/home/raghavendra/.notify-icons/mplayer.xpm) ^fg(red)FILE:^fg() $FILE:t"
fi
fi
/bin/echo "mplayer \"$FILE\"" >>| ~/.current
# vim: set foldmethod=marker:
|