-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmusplayer.sh
More file actions
executable file
·265 lines (254 loc) · 7.34 KB
/
musplayer.sh
File metadata and controls
executable file
·265 lines (254 loc) · 7.34 KB
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
#!/data/data/com.termux/files/usr/bin/bash
# MusPlayer
# Version : 1.0
# Author : KasRoudra
# Github : https://github.com/KasRoudra
# Email : kasroudrakrd@gmail.com
# Contact : https://m.me/KasRoudra
# Description: Play music in termux.
# Music player termux
white="\033[1;37m"
red="\033[1;31m"
green="\033[1;32m"
yellow="\033[1;33m"
purple="\033[1;35m"
cyan="\033[1;36m"
blue="\033[1;34m"
nc="\033[00m"
info="${cyan}[${white}+${cyan}] ${yellow}"
ask="${cyan}[${white}?${cyan}] ${purple}"
error="${cyan}[${white}!${cyan}] ${red}"
success="${cyan}[${white}√${cyan}] ${green}"
re='^[0-9]+$'
logo="${green} __ __ ____ _
${red}| \/ |_ _ ___| _ \| | __ _ _ _ ___ _ __
${blue}| |\/| | | | / __| |_) | |/ _' | | | |/ _ \ '__|
${yellow}| | | | |_| \__ \ __/| | (_| | |_| | __/ |
${purple}|_| |_|\__,_|___/_| |_|\__,_|\__, |\___|_|
${cyan} |___/
${red} [By KasRoudra]${nc}
"
helper(){
if $SHUFFLE; then
st="On"
else
st="Off"
fi
if $REPEAT; then
if [ $REPNUM -eq 0 ]; then
rt="On ➤ ${cyan}∞ Times"
else
rt="On ➤ ${cyan}${REPNUM} Times"
fi
else
rt="Off"
fi
echo -e "\n${info}${cyan}List of commands:${yellow}
${purple}> help ${yellow}Shows this help
${purple}> list ${yellow}Shows music list
${purple}> chdir${green} <path> ${yellow}Changes music list directory (current: $blue$DIR$yellow)
${purple}> play${green} <number> ${yellow}Plays that music
${purple}> play all ${yellow}Plays all music
${purple}> repeat${green} <number> ${yellow}Repeats the music (current: $blue$rt${yellow})
${purple}> shuffle ${yellow}Shuffles all music (current: $blue$st$yellow)
${purple}> about ${yellow}About this program
${purple}> more ${yellow}More tools from author
${purple}> exit ${yellow}Exit from this program${nc}"
}
export REPEAT=false
export SHUFFLE=false
export NUMS=0
export RAND=0
export REPNUM=0
if [ `pidof mpv > /dev/null 2>&1` ]; then
killall mpv
fi
if [ -d "/data/data/com.termux/files/home" ]; then
if ! [ -d "/sdcard/Music" ]; then
mkdir /sdcard/Music
else
export DIR="/sdcard/Music"
fi
export DIR="/sdcard/Music"
else
if ! [ -d "$HOME/Music" ]; then
mkdir $HOME/Music
fi
export DIR="$HOME/Music"
fi
if ! [ `command -v mpv` ]; then
echo -e "\n${info}Installing mpv.....\n${nc}"
pkg install mpv -y
if [ `command -v mpv` ]; then
echo -e "\n${success}Mpv installed!\n${nc}"
else
echo -e "\n${error}Mpv installation failed!\n${nc}"
exit
fi
fi
clear
sleep 0.4
echo -e "$logo"
sleep 0.4
while true; do
trap '' 2
sleep 0.2
printf "\n${yellow}MusPlayer > ${purple}"
read cmd
sleep 0.5
if [ "$cmd" = "help" ]; then
helper
elif [ "$cmd" = "list" ]; then
echo
getlist=$(ls $DIR | grep mp3)
replace=${getlist// /%%}
n=1
if ! [[ $replace == "" ]]; then
for music in $replace; do
if (( $n % 2 == 0 )) ; then
echo -e "${yellow}[$n]${blue} ${music//%%/ }"
else
echo -e "${green}[$n]${purple} ${music//%%/ }"
fi
((n++))
done
else
echo -e "${error}No music here!$blue($DIR)${nc}"
fi
elif echo "$cmd" | grep -q "chdir"; then
path="$(echo "$cmd" | cut -d " " -f 2)"
if [[ -d "$path" ]]; then
export DIR="${path}"
echo -e "\n${success}Directory changed!${nc}"
elif [[ $path == "chdir" ]]; then
echo -e "\n${error}Please enter a path!${nc}"
else
echo -e "\n${error}Path do not exist!${nc}"
fi
elif echo "$cmd" | grep -q "play"; then
arg=$(echo "$cmd" | cut -d " " -f 2)
getlist=$(ls $DIR | grep mp3)
replace=${getlist// /%%}
list=()
for m in $replace; do
list+=("$m")
done
while true; do
if [[ $arg = "all" || $arg = "play" ]]; then
if ! [[ $list == "" ]]; then
echo -e "\n${success}Playing all.....${nc}"
if $SHUFFLE; then
while true; do
trap 'break' 2
cd $DIR
export NUMS=`ls *.mp3 | wc -l`
export RAND=`shuf -i 1-${NUMS} -n 1`
music=${list[(($RAND))]}
echo -e "\n${success}${blue}${music//%%/ }\n${nc}"
mpv "$DIR/${music//%%/ }"
done
break
else
for ms in $replace; do
echo -e "\n${success}${blue}${ms//%%/ }\n${nc}"
trap 'break' 2
mpv "$DIR/${ms//%%/ }"
done
break
fi
else
echo -e "\n${error}No music!${nc}"
break
fi
elif ! [[ $arg =~ $re ]]; then
echo -e "\n${error}Not a number!${nc}"
break
else
music=${list[(($arg-1))]}
if [[ ${music//%%/ } == "" ]]; then
echo -e "\n${error}Music not found!"
else
echo -e "\n${success}Playing ${music//%%/ }\n${nc}"
if $REPEAT; then
if [[ "$REPNUM" != "0" ]]; then
j=0
while [ $j -lt $REPNUM ]; do
trap 'break' 2
mpv "$DIR/${music//%%/ }"
((j++))
done
else
while true ; do
trap 'break' 2
mpv "$DIR/${music//%%/ }"
done
fi
else
trap 'break' 2
mpv "$DIR/${music//%%/ }"
fi
fi
break
fi
done
elif echo "$cmd" | grep -q "repeat"; then
arg2=$(echo "$cmd" | cut -d " " -f 2)
if [[ $REPEAT = false || $arg2 =~ "$re" ]]; then
if [[ $arg2 =~ $re && $arg2 != 0 ]]; then
export REPNUM="$arg2"
elif [[ "$arg2" == "repeat" || "$arg2" == "∞" ]]; then
export REPNUM=0
elif [[ "$arg2" == "on" || "$arg2" == "On" || "$arg2" == "ON" ]]; then
printf ""
else
echo -e "\n${error}Invalid argument for repeat!${nc}"
fi
export REPEAT=true
echo -e "\n${success}Repeat turned on!${nc}"
elif [[ $REPEAT = true && $arg2 != "repeat" ]]; then
if [[ $arg2 =~ $re && $arg2 != 0 ]]; then
export REPNUM="$arg2"
elif [[ "$arg2" == "off" || "$arg2" == "Off" || "$arg2" == "OFF" ]]; then
printf ""
else
echo -e "\n${error}Invalid argument for repeat!${nc}"
fi
else
export REPEAT=false
echo -e "\n${success}Repeat turned off!${nc}"
fi
elif echo "$cmd" | grep -q "shuffle"; then
if [ $SHUFFLE = false ]; then
export SHUFFLE=true
echo -e "\n${success}Shuffle turned on!${nc}"
else
export SHUFFLE=false
echo -e "\n${success}Shuffle turned off!${nc}"
fi
elif echo "$cmd" | grep -q "about"; then
clear
echo -e "$logo"
echo -e "$red[ToolName] ${cyan} :[MusPlayer]
$red[Version] ${cyan} :[1.0]
$red[Description]${cyan} :[Music player for termux]
$red[Author] ${cyan} :[KasRoudra]
$red[Github] ${cyan} :[https://github.com/KasRoudra]
$red[Messenger] ${cyan} :[https://m.me/KasRoudra]
$red[Email] ${cyan} :[kasroudrakrd@gmail.com]"
read -p ">>> " abot
clear
echo -e "$logo"
elif echo "$cmd" | grep -q "more"; then
xdg-open "https://github.com/KasRoudra/KasRoudra#My-Best-Works"
clear
echo -e "$logo"
elif [ "$cmd" = "clear" ]; then
clear
echo -e "$logo"
elif [ "$cmd" = "exit" ]; then
echo -e "${nc}"
exit
else
echo -e "\n${error}Sorry, wrong input! Please type 'help'${nc}"
fi
done