-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsomabox
executable file
·180 lines (158 loc) · 6.45 KB
/
somabox
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
#!/bin/bash
# original idea: <https://github.com/epitron/scripts/blob/master/somafm>
# Modified and extended by Barret E <https://github.com/archusXIV>
#
# Dependencies: dialog, mpv, streamripper (optional).
# It is also provided as third party software in Mpv-Playlists-Manager.
# <https://github.com/archusXIV/mpv-playlists-manager>
#
# somabox let you play/rip chosen channels from <https://somafm.com/>
# Add/Remove items from their respective arrays and change the window size
# using lines and columns in the echo command below to correctly fit the amount
# of CHANNELS and stream informations at the bottom of the box.
# If streamripper is installed, don't forget to change the rip_dir variable.
for pkg in dialog mpv; do
! command -v "$pkg" && {
notify-send -t 0 -u critical "$pkg isn't installed, exiting!"
printf '%s\n' " $pkg isn't installed, exiting!"
exit 127
}
done
# resize the window according to the amount of channels
# height = 29 lines, whidth = 96 columns
echo -ne '\e[8;29;96t'
VERSION="v.0.7"
export MPVSOCKET="/tmp/mpvsocket"
soma_url="http://somafm.com/nossl/"
nowPlaying="NO STATION SELECTED"
nowRipping="$nowPlaying"
rip_dir="$HOME/Music/streamripper"
low=64 medium=130 high=256 higher=320
if [[ -n $(command -v streamripper) ]]; then
select="PLAY/RIP SELECTED"
else
select="PLAY SELECTED"
fi
# Add channels names and descriptions here
# "channel_name" "description" on each line.
LIST=(
"Boot Liquor" "Americana Roots music"
"Dark Zone" "The darker side of deep ambient"
"Deep Space One" "Deep ambient electronic, experimental and space music"
"Drone Zone" "Served best chilled, safe with most medications"
"Folk Forward" "Indie Folk, Alt-folk and the occasional folk classics"
"Groove Salad" "Nicely chilled plate of ambient/downtempo beats"
"Mission Control" "Celebrating NASA and Space Explorers everywhere"
"SF 10-33" "Ambient tunes mixed with San Francisco public safety radio"
"Space Station" "Spaced-out ambient and mid-tempo electronica"
"Synphaera Radio" "Featuring the music from an independent record label"
"ThistleRadio" "Exploring music from Celtic roots and branches"
"Underground 80s" "Early 80s UK Synthpop and a bit of New Wave"
)
# keep this one empty to create a blank line between
# channels and tuned station quality informations.
LIST+=("" "")
# Add/Remove array index [0],[2] etc...
# use even numbers for the channel name
declare -A LOWBITRATES=(
[${LIST[0]}]="${soma_url}bootliquor${medium}.pls"
[${LIST[2]}]="${soma_url}darkzone${medium}.pls"
[${LIST[4]}]="${soma_url}deepspaceone${low}.pls"
[${LIST[6]}]="${soma_url}dronezone${medium}.pls"
[${LIST[8]}]="${soma_url}folkfwd${low}.pls"
[${LIST[10]}]="${soma_url}gsclassic${low}.pls"
[${LIST[12]}]="${soma_url}missioncontrol${low}.pls"
[${LIST[14]}]="${soma_url}sf1033${low}.pls"
[${LIST[16]}]="${soma_url}spacestation${low}.pls"
[${LIST[18]}]="${soma_url}synphaera${medium}.pls"
[${LIST[20]}]="${soma_url}thistle${low}.pls"
[${LIST[22]}]="${soma_url}u80s${medium}.pls"
)
declare -A HIGHBITRATES=(
[${LIST[0]}]="${soma_url}bootliquor${higher}.pls"
[${LIST[2]}]="${soma_url}darkzone${high}.pls"
[${LIST[4]}]="${soma_url}deepspaceone${medium}.pls"
[${LIST[6]}]="${soma_url}dronezone${high}.pls"
[${LIST[8]}]="${soma_url}folkfwd${medium}.pls"
[${LIST[10]}]="${soma_url}gsclassic${medium}.pls"
[${LIST[12]}]="${soma_url}missioncontrol${medium}.pls"
[${LIST[14]}]="${soma_url}sf1033${medium}.pls"
[${LIST[16]}]="${soma_url}spacestation${medium}.pls"
[${LIST[18]}]="${soma_url}synphaera${high}.pls"
[${LIST[20]}]="${soma_url}thistle${medium}.pls"
[${LIST[22]}]="${soma_url}u80s${high}.pls"
)
_main() {
while true; do
channelChoice=$(
dialog --stdout --backtitle "SOMABOX $VERSION" \
--ok-label "$select" --cancel-label "QUIT SOMABOX" \
--title "SOMAFM CHANNELS LIST" --no-shadow \
--menu "Select a radio station:" 0 90 0 \
"${LIST[@]}" \
"NOW PLAYING:" "${nowPlaying}" \
"" "${BITRATES_MSG}" \
"NOW RIPPING:" "${nowRipping}" \
"" "${RIPPING_MSG}"
)
case $? in 1|255) clear; _killMpv; _killStreamripper; exit 0 ;; esac
bitrates=$(
dialog --stdout --backtitle "SOMABOX $VERSION" \
--title "AUDIO BITRATES" \
--menu "Select a bitrate for ${channelChoice}:" 10 50 2 \
LOW "(AAC 64k / MP3 128k)" \
HIGH "(AAC 128k / MP3 256/320k)"
)
[[ -n $(command -v streamripper) && -n $bitrates ]] && {
ripping=$(
dialog --stdout --backtitle "SOMABOX $VERSION" \
--title "STREAMRIPPER OPTIONS" \
--menu "Do you want to record ${channelChoice}?" 10 50 2 \
YES "Rip in selected quality" \
NO "Play selected station instead."
)
[[ ! -d $rip_dir && $ripping == 'YES' ]] && mkdir --parents "$rip_dir"
}
if [[ $bitrates == 'LOW' && $ripping == 'YES' ]]; then
nowRipping="${channelChoice}"
RIPPING_MSG="Ripping in LOW quality: (AAC 64k / MP3 128k)"
_ripStation "${LOWBITRATES[${channelChoice}]}" &
elif [[ $bitrates == 'HIGH' && $ripping == 'YES' ]]; then
nowRipping="${channelChoice}"
RIPPING_MSG="Ripping in HIGH quality: (AAC 128k / MP3 256/320k)"
_ripStation "${HIGHBITRATES[${channelChoice}]}" &
elif [[ $bitrates == 'LOW' ]]; then
nowPlaying="${channelChoice}"
BITRATES_MSG="Playing in LOW quality: (AAC 64k / MP3 128k)"
_mpvOptions "${LOWBITRATES[${channelChoice}]}"
elif [[ $bitrates == 'HIGH' ]]; then
nowPlaying="${channelChoice}"
BITRATES_MSG="Playing in HIGH quality: (AAC 128k / MP3 256/320k)"
_mpvOptions "${HIGHBITRATES[${channelChoice}]}"
else
continue
fi
done
}
_killStreamripper() {
kill -SIGTERM "$(pgrep -x streamripper)"
rm -rf "$rip_dir"/incomplete
} 2>/dev/null
_ripStation() {
_killStreamripper; sleep 0.2
streamripper "$*" \
-u "FreeAmp/2.x" \
-d "$rip_dir" -s >/dev/null 2>&1
}
_killMpv() { kill -SIGTERM "$(pgrep -x mpv)" 2>/dev/null; }
_mpvOptions() {
_killMpv; sleep 0.2
mpv \
--no-config \
--idle=no \
--cache=no \
--no-terminal \
--force-window=no \
"${MPVSOCKET}" "$*" &
}
_main "${@}"