-
Notifications
You must be signed in to change notification settings - Fork 10
/
jukebox.sh
executable file
·221 lines (201 loc) · 7.11 KB
/
jukebox.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
#!/usr/bin/env bash
# Jukebox for native terminal
#
# Made by [email protected]
# https://github.com/llaine/cmdfm
# Fork me !
# COLOR FOR PROMPT UI
readonly RED="$(tput setaf 1)"
readonly GREEN="$(tput setaf 2)"
readonly YELLOW="$(tput setaf 3)"
readonly BLUE="$(tput setaf 4)"
readonly MAGENTA="$(tput setaf 5)"
readonly CYAN="$(tput setaf 6)"
readonly RESET="$(tput sgr0)"
readonly UNDERLINE="$(tput smul)"
readonly ARGS="$@"
header() {
clear
echo $GREEN"
__ _ _
\ \ _ _| | _____| |__ _____ __
\ \ | | | |/ / _ \ '_ \ / _ \ \/ /
/\_/ / |_| | < __/ |_) | (_) > <
\___/ \__,_|_|\_\___|_.__/ \___/_/\_\ v 1.3
"$RESET$MAGENTA"Brought to you by darksioul with <3 & Freedom. " $RESET
printf "\n\n\n"
}
genres() {
echo -e "\n
$GREEN $UNDERLINE Available genres $RESET$YELLOW\n
80s Acid Jazz Acoustic
Acoustic Rock African Alternative Ambient
Americana Arabic Avantgarde Bachata
Bhangra Blues Blues Rock Bossa Nova
Chanson Chillout Chiptunes Choir
Classic Rock Classical Classical Guitar Contemporary
Country Cumbia Dance Dancehall
Death Metal Dirty South Disco Dream Pop
Drum & Bass Dub Dubstep Easy Listening
Electro House Electronic Electronic Pop Electronic Rock
Folk Folk Rock Funk Glitch
Gospel Grime Grindcore Grunge
Hard Rock Hardcore Heavy Metal Hip-Hop
House Indie Indie Pop Industrial Metal
Instrumental Rock J-Pop Jazz Jazz Funk
Jazz Fusion K-Pop Latin Latin Jazz
Mambo Metalcore Middle Eastern Minimal
Modern Jazz Moombahton New Wave Nu Jazz
Opera Orchestral Piano Pop
Post Hardcore Post Rock Progressive House Progressive Metal
Progressive Rock Punk R&B Rap
Reggae Reggaeton Riddim Rock
Rock 'n' Roll Salsa Samba Shoegaze
Singer / Songwriter Smooth Jazz Soul Synth Pop
Tech House Techno Thrash Metal Trance
Trap Trip-hop Turntablism
$RESET
--------------------------------------------------------------------------------
Usage :$RED ./cmdfm -g minimal $RESET
"
}
action() {
echo "+---------------------------------------------+"
echo "$RED p $RESET $CYAN # Pause.$RESET"
echo "$RED n $RESET $CYAN # Next song in the $YELLOW$1$RESET$CYAN playlist. $RESET"
#echo "$RED g $RESET $CYAN # Switch to genre.. $RESET"
echo "$RED e $RESET $CYAN # Exit the Jukebox. $RESET"
echo "$RED m $RESET $CYAN # Display mini menu $RESET"
echo "+---------------------------------------------+"
}
actionMini() {
echo "$RED p $RESET--> pause | $RED n $RESET--> next | $RED g $RESET--> genre | $RED e $RESET--> exit "
}
# replace all blank space in string by %20 for web query
replace() {
STR="$@"
OUTPUT=`echo $STR | sed 's/ /%20/g'`
echo $OUTPUT
}
quit() {
echo "quit" > /tmp/mplayer-control
echo "$MAGENTA Bye ! $RESET Repo : $YELLOW https://github.com/llaine/cmdfm $RESET\n"
}
# get song's
# title
# genre
# stream_url
# duration
# from a style
getSongFromStyle() {
theGenre="$@"
theGenre=`replace $theGenre`
url="https://cmd.fm/api/tracks/search/?genre=$theGenre&limit=1"
this=`curl -s -H Content-type:application/json $url`
title=`echo $this | grep 'title":"' | tr ',' "\n" | grep 'title' | cut -d '"' -f 4`
description=`echo $this | grep '"description":"' | tr ',' "\n" | grep 'description' | cut -d '"' -f 4`
genre=`echo $this | grep '"main_type":"' | tr ',' "\n" | grep 'main_type' | cut -d '"' -f 4`
stream_url=`echo $this | grep 'stream_url":"' | tr ',' "\n" | grep 'stream_url' | cut -d '"' -f 4`
dur=`echo $this | grep 'duration":' | tr ',' "\n" | grep 'duration' | egrep -o '[[:digit:]]'`
duration=`echo $dur | tr -d ' '`
theReturn="$title||$genre||$stream_url||$duration||$description"
echo $theReturn
}
play() {
# streamUrl="$@?client_id=2cd0c4a7a6e5992167a4b09460d85ece"
mkfifo /tmp/mplayer-control &>/dev/null
mplayer -slave -quiet -input file=/tmp/mplayer-control $streamUrl &>/dev/null &
}
# Usage function
usage() {
echo -e "$GREEN $UNDERLINE USAGE (argv) :$RESET\n"
echo -e "$RED -a $RESET # display all the$RED musical genre$RESET."
echo -e "$RED -g $RESET$YELLOW<style>$RESET # launch a playlist the selected musical genre.\n"
}
runloop () {
while [[ true ]]; do
read -p "> " -t$durationSecondes
printf "\n"
if [[ $REPLY = "e" ]]; then
quit
break 2
elif [[ $REPLY = "p" ]]; then
echo "pause" > /tmp/mplayer-control
elif [[ $REPLY = "d" ]]; then
echo "Not currently available"
#urlSong=`./getUrlSong.sh $title`
#./download.sh $urlSong
elif [[ $REPLY = "n" ]]; then
echo "quit" > /tmp/mplayer-control
echo "Fetching next song ..."
break 1
elif [[ $REPLY = "m" ]]; then
actionMini
else
echo "quit" > /tmp/mplayer-control
break 1
fi
done
}
main() {
if [[ -z $1 ]]; then
usage
exit 1
fi
argv=$1
argc=$#
[[ -z $3 ]] && argvGenre=$2 || argvGenre=$(replace $2 $3) ; selectedStyle="$2 $3"
case $argv in
"-a" )
genres
;;
"-g")
if [[ -z $argvGenre ]]; then
usage
exit 1
fi
informations=`getSongFromStyle $argvGenre`
if [[ $informations = "||||||||" ]]; then
echo "\n$BLUE [!]$RESET The $YELLOW $selectedStyle $RESET genre doesn't exit"
echo "$BLUE [!]$RESET$RED -a $RESET to display the genre available genres\n"
exit 1
fi
header
#echo "Playlist created -> $YELLOW $selectedStyle $RESET"
action "$selectedStyle"
while [[ true ]]; do
informations=`getSongFromStyle $argvGenre`
#echo $informations
if [[ $informations = "||||||" ]]; then
echo -e "\n$BLUE [!]$RESET The $YELLOW $selectedStyle $RESET genre doesn't exit"
echo -e "$BLUE [!]$RESET$RED -a $RESET to display the genre available genres\n"
exit 1
fi
IFS='||' read -a songInfo <<< "$informations"
title="${songInfo[0]}"
genre="${songInfo[2]}"
streamUrl=$(curl -s "${songInfo[4]}?client_id=2cd0c4a7a6e5992167a4b09460d85ece" | perl -wnE'say /location":"(.*)"/g' | sed 's/https/http/g')
length="${songInfo[6]}"
durationSecondes=$(($length / 1000 ))
[[ -z "${songInfo[8]}" ]] && descr="empty" || descr="${songInfo[8]}"
play $streamUrl #Streaming url
pidofMPlayer=$(pgrep mplayer)
if [[ -z $pidofMPlayer ]]; then
echo "Loading ..."
break 1
else
echo "$GREEN Now Playing :$RESET $YELLOW $title $RESET"
echo "$GREEN Main genre :$RESET $YELLOW $genre $RESET"
echo -e "$GREEN Description :$RESET $YELLOW $descr $RESET\n"
fi
runloop
done
;;
esac
}
# while [[ true ]]; do
# sleep 0.5
# length+='#'
# echo -ne "$length \r"
# done
main $ARGS