-
Notifications
You must be signed in to change notification settings - Fork 2
/
vrun
executable file
·147 lines (136 loc) · 3.32 KB
/
vrun
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
#!/bin/bash
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License version 2 for
# more details.
#
# You should have received a copy of the GNU General Public License version 2
# along with this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
##############################################################
# Default configuration #
# #
# To be overload in ~/.config/vrun/configrc #
##############################################################
# vlc telnet port
tport=4212
#vlc telnet address
taddress="127.0.0.1"
# local vlc binding address
tbind="127.0.0.1"
# vlc telnet password
password="admin"
#############################################################
if [ -f ~/.config/vrun/configrc ]; then
. ~/.config/vrun/configrc
fi
if [[ $1 = "-p" ]] || [[ $1 = "--port" ]]
then
tport=$2
shift 2
fi
run(){
/bin/bash -c "echo \"$password\"; echo -e \"$*\"; sleep 0.1; echo \"logout\"" | nc $taddress $tport |
sed '/Password:/d;/VLC media player .*/d;/Welcome, Master/d;/Bye-bye/d'
}
formattime(){
a="$1"
a=${a%?}
if [[ $a = [0-9]* ]]; then
second_to_time $a;
fi
}
contain(){
local i
for i in $2; do
if [[ "$i" = "$1" ]]; then
return 0
fi
done
return 1
}
second_to_time(){
local min seconde
if [ $1 -ge 60 ]; then
min=$(( $1 / 60 ))
echo -n "${min}:"
else
min=0;
fi
seconde=$(( $1 - 60 * $min ))
printf "%02d\n" $seconde
}
case $1 in
get_time|get_length)
formattime $(run $1)
;;
pause)
a=`run is_playing`;
a=${a:0:1}
if [ $a -le 0 ]; then
run play
else
run pause
fi
;;
add|enqueue)
i=0
for path in "${@:2}"; do
c=${path:0:1}
d=${path:0:6}
if [[ "$c" != "/" ]] && [[ "$d" != "http://" ]] && [[ "$d" != "ftp://" ]] && [[ "$d" != "udp://" ]]; then
run $1 "`pwd`/$path"
else
run $1 $path
fi;
done
;;
goto|playlist|atrack|vtrack|vratio|vcrop|crop|vzoom|zoom|vdeinterlace|vdeinterlace_mode|vdeinterlace_mode)
c=${2/ */} # supprime tout après un espace insécable
run $1 $c
;;
move)
c=${2/ */}
d=${3/ */}
run $1 $c $d
;;
delete)
for file in "${@:2}"; do
c=${file/ */} # supprime tout après un espace insécable
run $1 $c
done
;;
status)
i=0
run "get_time\nget_length\nstatus" | while read line; do
i=$(($i + 1))
if [[ $i -eq 1 ]]; then
tmp=$(formattime $line)
if [[ "$tmp" != "" ]]; then
echo -n "$(formattime $line) / ";
fi
elif [[ $i -eq 2 ]]; then
tmp=$(formattime $line)
if [[ "$tmp" != "" ]]; then
echo $tmp
fi
elif [[ $i -ge 3 ]]; then
echo $line;
fi
done
;;
start)
if [ `pidof vlc | wc -l` -le 0 ]; then
shift
vlc --extraintf telnet --telnet-port $tport --telnet-host $tbind --telnet-password $password $@ &>/dev/null &
sleep 2
if [ `pidof vlc | wc -l` -le 0 ]; then
cvlc --extraintf telnet --telnet-port $tport --telnet-host $tbind --telnet-password $password $@ &>/dev/null &
sleep 2
fi
fi
;;
*)
run $*;
;;
esac