forked from bing0o/bash_scripting
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmusic.sh
86 lines (69 loc) · 1.48 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
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
#!/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 ${pick##*/}
pkill vlc
case $vlc in
True) vlc "$pick" &>/dev/null & ;;
*) cvlc "$pick" --play-and-exit &>/dev/null & ;;
esac
}
prog=${0##*/}
Usage() {
while read -r line; do
printf "%b\n" "$line"
done <<-EOF
\r #Options:
\r \t -p, --path\t\t The Path To Your Music Directory.
\r \t -e, --extension\t The Extension of The Files (mp3, mp4, avi,....etc, or "*" to load all the files).
\r \t -v, --vlc\t\t to run the music or the video clip with vlc GUI.
\r \t -l, --list\t\t to list all the songs and pick the music by yourself.
\r #Example:
\r \t $prog -p $HOME/Music -e mp3 -v -l
EOF
}
# change the default path here!
path="$HOME/Music"
ext="mp3"
vlc=False
list=False
while [ -n "$1" ]; do
case "$1" in
-p|--path)
path=$2
shift;;
-e|--extension)
ext=$2
shift;;
-v|--vlc)
vlc=True;;
#shift;;
-l|--list)
list=True;;
#shift;;
*)
Usage
exit 1;;
esac
shift
done
m=0
for i in "$path"/*."$ext"; do
[ -f "$i" ] && music[$m]=$i
[ $list == True ] && echo "[$m] ${i##*/}"
let m+=1
done
[ $list == True ] && read -p "[+] Pick a Song: " num || num=$[ $RANDOM % $m ]
MUSIC