-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbmplayer.sh
executable file
·283 lines (260 loc) · 6.48 KB
/
bmplayer.sh
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#!/bin/bash
# bmplayer.sh
#
# Copyright 2014 levi (levi0x0) (https://github.com/levi0x0/bash-player)
#
# bash-player is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# bash-player 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 for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
#
# Author: levi aka levi0x0 (http://github.com/levi0x0/)
# Date: 30-04-2014
# Description:
#
# "Bash-player script is A simple GUI (Graphical User Interface) for mplayer/mpv
# Written in Shell Under Linux. "
#script version
version="0.10"
#videos folder
folder="$HOME/Videos"
#banner
banner="Bash-player $version - Copyright 2014 (C) levi0x0 (https://github.com/levi0x0)"
#date="22-01-2014"
#date="08-04-2014"
#date="11-04-2014"
#date="13-04-2014"
#date="16-04-2014"
date="30-04-2014"
#mplayer options (Example FULL SCREEN: -fs)
mplayerpa=""
#status variables
debug="[DEBUG]"
error="[ERROR]"
exit="[EXIT]"
#show subtitles Dialog Default Show Dialog
#1 for show
#0 for hide
subtitlesDialog=1
#exit in the end
#0 for no
#1 for yes
exitend=1
#startup dialog
#0 - for no
#1 - for yes
startupDialog=0
#check if zenity installed
if zenity --version &> /dev/null ;then
echo "$debug Found zenity"
else
echo "$error Zenity package not installed"
fi
#check if mplayer installed
if mplayer &> /dev/null ;then
PLAYER="mplayer"
echo "$debug Found mplayer"
else
if mpv &> /dev/null ;then
PLAYER="mpv"
echo "$debug Found mpv"
else
zenity --error \
--title="mplayer/mpv not found" \
--text="mplayer/mpv package not installed"
exit
fi
fi
is_root() {
if [ $UID -ne 0 ];then
echo "$error Please Run as root."
exit
fi
}
cversions() {
bmp="https://raw.githubusercontent.com/levi0x0/bash-player/master/bmplayer.sh"
if curl --version &> /dev/null;then
echo "$debug Found CURL"
else
zenity --error \
--title="Curl Not Found" \
--text="Curl Not Installed."
exit
fi
cv=`curl -s "$bmp" | grep "version=" | head -1 | sed 's/[version\"/=]//g'`
if [[ $version == $cv ]];then
echo "[NOOP] Bash-player $version is the newest VERSION"
exit
elif [[ $version != $cv ]];then
echo "[GOOD NEWS] Ah! New version is avilable VERSION: $cv"
echo -n "Want to Upgrade? (y/n):"
read answer
if [[ $answer == "y" ]];then
echo "$debug Old version $version..."
else
echo "$exit Bye!"
exit
fi
fi
}
#help function
help() {
zenity --list \
--title="Mplayer - Shortcut" \
--ok-label="Return" \
--cancel-label="exit" \
--width=100 \
--height=400 \
--text "Help Options for Mplayer Type this with Your Keyboard in Mplayer" \
--column "Help" \
--column "Key" \
"Full Screen" f \
"Volume Up" 0 \
"Volume Down" 9 \
"Quit/Stop" "Esc" \
"Pause" "Space" \
"v" "Toggle subtitle visibility." \
"F" "Toggle displaying forced subtitles ."\
"T" "Toggle stay-on-top (also see -ontop)." \
"z and x" "Adjust subtitle delay by +/- 0.1 seconds." \
"r and t" "Move subtitles up/down." \
"left and right" "Seek backward/forward 10 seconds." \
"up and down" "Seek forward/backward 1 minute."
}
upgrade() {
repo="https://github.com/levi0x0/bash-player.git"
tmpDir="/tmp/bash-player-update"
#update from git repository
if git --version &> /dev/null;then
echo "$debug Found git"
else
zenity --error \
--title="Git Not Installed." \
--text="git not Installed."
fi
is_root
echo "$debug Making Directory: $tmpDir.."
echo "$debug Running git clone.."
git clone $repo $tmpDir
echo "$debug Install.sh.."
cd $tmpDir
sudo make install
echo "$debug Remiving $tmpDir"
rm -rf $tmpDir
echo "[DONE] Bash-Player Upgraded.."
}
#bash-player function
bash_player() {
if [ $startupDialog -ne 0 ];then
zenity --question \
--width=100 \
--height=150 \
--title="Bash-player - $version" \
--ok-label="Select video" \
--cancel-label="Help"
else
echo "$debug No Startup Dialog."
fi
if [ $? -ne 0 ]; then
help #print help dialog
if [ $? -ne 0 ]; then
exit
else
bash_player
fi
else
#select video
video=`zenity --file-selection \
--title="Select a video" \
--filename=$folder`
if [ $? -ne 0 ]; then
echo "$debug no File selected."
exit
elif [ $subtitlesDialog -eq 1 ]; then
zenity --question \
--title="Add subtitles" \
--text="Subtitles? \n\t(You can disable this Dialog)" \
--ok-label="Yes, add" \
--cancel-label="No, play video"
if [ $? -ne 0 ]; then
$PLAYER -title "Bash-player $version - $video" $mplayerpa "$video"
if [ $exitend -eq 0 ];then
bash_player
else
exit
fi
else
subtitles=`zenity --file-selection \
--title="Select subtitles" \
--filename=$folder`
#run mplayer
$PLAYER -title "Bash-player $version - $video" $mplayerpa "$video" -sub "$subtitles"
if [ $exitend -eq 0 ]; then
bash_player
else
exit
fi
fi
else
$PLAYER -title "Bash-player $version - $video" $mplayerpa "$video"
if [ $exitend -eq 0 ];then
bash_player
else
exit
fi
fi
fi
}
usage() {
echo -e "Usage: bmplayer [OPTION]\n"
echo -e "Options:\n"
echo -e "\t-h, --help - print this screen."
echo -e "\t-gh,--help-gui - Mplayer help (BaPl GUI)."
echo -e "\t-v, --version - print version."
echo -e "\t-u, --update - check, upgrade version."
echo -e "\t-fu, --force-upgrade - upgrade without check versions..\n"
echo -e "Update bash-player:"
echo -e "\tsudo bmplayer --update"
echo -e "\t OR:"
echo -e "\tsudo bmplayer --force-update"
echo -e "\n#BashPlayer2014\n"
}
if [ -z $1 ];then
echo "$debug Bash-player Started..."
bash_player
#version
elif [[ $1 == "--version" ]] || [[ $1 == "-v" ]]; then
echo "Bash-player - $version"
exit
exit
#help
elif [[ $1 == "--help" ]] || [[ $1 == "-h" ]];then
usage
exit
#mplayer gui help
elif [[ $1 == "--help-gui" ]] || [[ $1 == "-hg" ]];then
help
exit
#update
elif [[ $1 == "--update" ]] || [[ $1 == "-u" ]];then
cversions
upgrade
exit
elif [[ $1 == "--force-upgrade" ]] || [[ $1 == "-fu" ]];then
upgrade
else
video="$1"
$PLAYER -title "Bash-player $version - $video" $mplayerpa "$video"
fi