forked from bing0o/bash_scripting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
music.sh
52 lines (40 loc) · 1.29 KB
/
music.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
#!/bin/bash
#
# bash script to pick a music for you from the given directory.
# Just For Fun [^^]
#
# chmod 755 music.sh
# sudo cp music.sh /usr/local/bin/music
#
#set -x
cyan="\e[36m"
end="\e[0m"
MUSIC () {
pick=${music[$num]}
echo -e $cyan"\n[+] The Songs: "$end ${#music[@]}
echo -e $cyan"[+] The Picked Number: "$end $num
echo -e $cyan"[+] The Picked Song: "$end $(echo "$pick" | awk -F/ '{print $NF}')
pkill vlc
[ "$1" == "vlc" ] && { vlc "$pick" &>/dev/null & } || { cvlc "$pick" --play-and-exit &>/dev/null & }
}
[ "$1" == "-h" ] && {
echo -e "#Usage:
\tmusic <PATH> <EXTENSION> <vlc> <list>\n
\t<PATH>\t\tThe Path To Your Music Directory.
\t<EXTENSION>\tThe Extension of The Files (mp3, mp4, avi,....etc, or \"*\" to load all the files)
\t<vlc>\t\tEnter 'vlc' to run the music or the video clip with vlc GUI.
\t<list>\t\tEnter 'list' to list all the songs and pick the music by yourself.
";
exit;
}
# change the default path here!
[ -z $1 ] || [ "$1" == "." ] && path="/home/bingo/Music" || path=$1
[ -z "$2" ] || [ "$2" == "." ] && ext="mp3" || ext="$2"
m=0
for i in $path/*.$ext; do
[ -f "$i" ] && music[$m]="$i"
[ "$4" == "list" ] && echo "[$m] $(echo $i | awk -F/ '{print $NF}')"
let m+=1
done
[ "$4" == "list" ] && read -p "[+] Pick a Song: " num || num=$[ $RANDOM % $m ]
MUSIC "$3"