mabox-pipemenus/usr/bin/mb-music

326 lines
11 KiB
Plaintext
Raw Normal View History

2021-11-17 13:06:29 +01:00
#!/bin/bash
# mb-music - play Internet streams with mpv or PyRadio
2023-06-02 22:31:20 +02:00
wmctrl -R cavatransparent
2023-05-10 23:48:43 +02:00
mkdir -p "$HOME/.config/mabox/mb-music/"
CONFFILE="$HOME/.config/mabox/mb-music/mb-music.conf" # NOT USED YET
# If config file not exist create one with defaults
#if [ ! -f $CONFFILE ]; then
#cat <<EOF > ${CONFFILE}
#
#EOF
#fi
# read config variables from file
#source <(grep = $CONFFILE)
2021-11-17 13:06:29 +01:00
PLAYLIST="$HOME/.config/pyradio/stations.csv"
2023-05-10 23:48:43 +02:00
PLAYLISTYT="$HOME/.config/mabox/mb-music/yt_music_list.csv"
if [ ! -f $PLAYLISTYT ]; then
cat <<EOF > ${PLAYLISTYT}
Legendary Albums,-
Portishead - Dummy 1994,https://www.youtube.com/watch?v=qNq9TJ4QCas
R.E.M. - Automatic fot the people 1992,https://www.youtube.com/watch?v=jBUjeOBzkIk
The Cure - Faith 1981,https://www.youtube.com/watch?v=fShNf-NdJx4
Joy Division - Unknown Pleasures 1979,https://www.youtube.com/watch?v=oo7lt0lLOvg
Pink Floyd - The Dark Side Of The Moon 1973,https://www.youtube.com/watch?v=k9ynZnEBtvw
Programming music,-
Tabnine,https://www.youtube.com/watch?v=L_MupB3z1g4
Anonymous Headquarters,https://www.youtube.com/watch?v=Z-VfaG9ZN_U
Connection Lost,https://www.youtube.com/watch?v=l9nh1l8ZIJQ
Infinity,https://www.youtube.com/watch?v=UoPpxj77Vi0
Test Mode,https://www.youtube.com/watch?v=ka4KN2KEGmI
Under the Deep,https://www.youtube.com/watch?v=rr0gvSS1OzE
Brutal,https://www.youtube.com/watch?v=FS8XtrLqIxw
Hidden Service,https://www.youtube.com/watch?v=1-_tyTJHgB8
Easy Thoughts,https://www.youtube.com/watch?v=0V7X9fa0wco
EOF
fi
NOWPLAY="$HOME/.config/mabox/mb-music/.radio-mpv"
NOWPLAYYT="$HOME/.config/mabox/mb-music/.yt-mpv"
menu() {
2021-11-17 13:06:29 +01:00
case $LANG in
pl*)
2023-05-10 23:48:43 +02:00
SNM="Dźwięk i Muzyka"
2021-11-17 13:06:29 +01:00
VOL="Sterowanie głośnością"
RADIO="Radio Internetowe"
2023-05-10 23:48:43 +02:00
PYRADIO="Uruchom <b>PyRadio</b>"
LISTEN="Słuchaj radia..."
EDITSTATIONS="Edytuj listę stacji radiowych"
2021-11-17 13:06:29 +01:00
RADIOBROWSER="Szukaj stacji online"
2023-05-10 23:48:43 +02:00
MPV="Odtwarzaj (za pomocą mpv - bez gui)"
2022-03-13 14:35:29 +01:00
CAVA="Wizualizacja (cava)"
STOP="Wyłącz"
2023-05-10 23:48:43 +02:00
YTMUSIC="Odtwarzacz MPV"
PLAYYT="Odtwarzaj..."
EDITPLAYLIST="Edytuj listę"
SETTINGS="Ustawienia"
2021-11-17 13:06:29 +01:00
;;
*)
2023-05-10 23:48:43 +02:00
SNM="Sound and Music"
2021-11-17 13:06:29 +01:00
VOL="Volume Control"
RADIO="Internet Radio"
2023-05-10 23:48:43 +02:00
PYRADIO="Launch <b>PyRadio</b>"
LISTEN="Listen to the radio..."
EDITSTATIONS="Edit radio stations list"
2021-11-17 13:06:29 +01:00
RADIOBROWSER="Search Radio Stations online"
2023-05-10 23:48:43 +02:00
MPV="Play (with mpv - no gui)"
2022-03-13 14:35:29 +01:00
CAVA="Visualiser (cava)"
STOP="Stop"
2023-05-10 23:48:43 +02:00
YTMUSIC="MPV Player"
PLAYYT="Play..."
EDITPLAYLIST="Edit MPV playlist"
SETTINGS="Settings"
2021-11-17 13:06:29 +01:00
;;
esac
2023-05-10 23:48:43 +02:00
out+=("^sep($SNM)")
out+=("󰕾 $VOL <span bgcolor='#333333' color='#d3d3d3'> <small>W + v</small> </span>,pavucontrol")
2021-11-17 13:06:29 +01:00
out+=("^sep($RADIO)")
2023-06-02 22:31:20 +02:00
out+=("$PYRADIO <span bgcolor='#333333' color='#d3d3d3'> <small>W + r</small> </span>,terminator --geometry=564x440-20-20 -e pyradio")
2023-05-10 23:48:43 +02:00
out+=("^sep()")
NOWPL="0"
2021-11-17 13:06:29 +01:00
2023-06-03 16:55:59 +02:00
pgrep -f radio-mpv > /dev/null && NOW="$(<"$NOWPLAY")" NOWPL="1" out0+=("<small> $STOP <i>$NOW</i></small>,pkill -f radio-mpv;pkill -f yt-mpv")
2023-05-10 23:48:43 +02:00
out+=("$LISTEN,^checkout(mpvradio)")
2021-11-17 13:06:29 +01:00
out2+=("^tag(mpvradio)")
2023-05-10 23:48:43 +02:00
out2+=("^sep($LISTEN)")
2021-11-17 13:06:29 +01:00
#mapfile -t stations < "$PLAYLIST"
2023-05-10 23:48:43 +02:00
grp=0
2021-11-17 13:06:29 +01:00
while IFS=$'\r\n' read -r line
do
2023-05-10 23:48:43 +02:00
url=${line#*,}
name=${line%,*}
if [ ${url} == "-" ];then
((grp++))
out2+=("${name},^checkout(${grp})")
out3+=("^tag($grp)")
out3+=("^sep($name)")
else
if [ ${grp} != "0" ];then
out3+=("<small>󰐊 ${name}</small>,mb-music play "\""${url}"\"" "\""${name}"\""")
else
out2+=("<small>󰐊 ${name}</small>,mb-music play "\""${url}"\"" "\""${name}"\""")
fi
fi
done <<< $(grep -v '^\s*$\|^#\|^\s*#' $PLAYLIST)
out+=("^sep($YTMUSIC)")
2023-06-03 16:55:59 +02:00
pgrep -f yt-mpv > /dev/null && NOW="$(<"$NOWPLAYYT")" NOWPL="1" out0+=("<small> $STOP <i>$NOW</i></small>,pkill -f yt-mpv;pkill -f radio-mpv")
2023-05-10 23:48:43 +02:00
n=$(grep -v '^\s*$\|^#\|^\s*#' ${PLAYLISTYT} |wc -l)
### List yt playlist
if (( $n <= 24 ));then #flat view in rootmenu
while IFS=$'\r\n' read -r line
do
url=${line#*,}
name=${line%,*}
if [ ${url} == "-" ];then
out+=("^sep(<small>$name</small>)")
else
[[ $name != "" ]] && out+=("<small>󰐊 ${name}</small>,mb-music playyt "\""${url}"\"" "\""${name}"\""")
fi
done <<< $(grep -v '^\s*$\|^#\|^\s*#' $PLAYLISTYT)
elif (( $n <= 30 ));then # flat view in submenu
out+=("$PLAYYT ,^checkout(ytmusic)")
out2+=("^tag(ytmusic)")
out2+=("^sep($YTMUSIC)")
grp=0
while IFS=$'\r\n' read -r line
do
url=${line#*,}
name=${line%,*}
if [ ${url} == "-" ];then
out2+=("^sep(<small>$name</small>)")
else
[[ $name != "" ]] && out2+=("<small>󰐊 ${name}</small>,mb-music playyt "\""${url}"\"" "\""${name}"\""")
fi
done <<< $(grep -v '^\s*$\|^#\|^\s*#' $PLAYLISTYT)
out2+=("^sep()")
out2+=("$EDITPLAYLIST,xdg-open $PLAYLISTYT")
else # n > 30
out+=("$PLAYYT ,^checkout(ytmusic)")
out2+=("^tag(ytmusic)")
out2+=("^sep($YTMUSIC)")
grp=0
while IFS=$'\r\n' read -r line
do
url=${line#*,}
name=${line%,*}
if [ ${url} == "-" ];then
((grp++))
out2+=("${name},^checkout(yt${grp})")
out3+=("^tag(yt$grp)")
out3+=("^sep($name)")
else
if [ ${grp} != "0" ];then
out3+=("󰐊 ${name},mb-music playyt "\""${url}"\"" "\""${name}"\""")
else
out2+=("󰐊 ${name},mb-music playyt "\""${url}"\"" "\""${name}"\""")
fi
fi
done <<< $(grep -v '^\s*$\|^#\|^\s*#' $PLAYLISTYT)
fi
out+=("^sep(VISUALIZER)")
pgrep -f cavatransparent > /dev/null && out+=("$STOP 󰺢 $CAVA,mb-music cavakill;mb-music ipc" "Colorize Cava,colorizer-cava -s") || out+=("󰺢 $CAVA,mb-music cavastart;mb-music ipc")
2022-03-13 14:35:29 +01:00
2021-11-17 13:06:29 +01:00
out+=("^sep()")
2023-05-10 23:48:43 +02:00
out+=(" $SETTINGS,^checkout(settings)")
out2+=("^tag(settings)")
out2+=("^sep($RADIO)")
out2+=(" $EDITSTATIONS,xdg-open $PLAYLIST")
out2+=(" $RADIOBROWSER,xdg-open https://www.radio-browser.info")
out2+=("^sep($YTMUSIC)")
out2+=(" $EDITPLAYLIST,xdg-open $PLAYLISTYT")
2021-11-17 13:06:29 +01:00
### RUN
if [[ "$1" == "-s" || "$1" == "ipc" ]]; then
. /usr/share/mb-jgtools/pipemenu-standalone.cfg
. $HOME/.config/mabox/mabox.conf
if [[ $panels_heightpos == "top" ]]; then
MENU_VALIGN="top"
MENU_MARGIN_Y=${panels_topmargin:-0}
elif [[ $panels_heightpos == "bottom" ]]; then
MENU_VALIGN="bottom"
MENU_MARGIN_Y=${panels_topmargin:-0}
else
2023-05-10 23:48:43 +02:00
MENU_VALIGN="top"
2021-11-17 13:06:29 +01:00
fi
2023-05-10 23:48:43 +02:00
MENU_PADDING_TOP=$((jgtools_padding+102))
MENU_HALIGN="right"
JGWIDTH=$((300+2*jgtools_padding))
2021-11-17 13:06:29 +01:00
if [[ "$1" == "ipc" ]]; then
POSITION_MODE="ipc"
else
POSITION_MODE="fixed"
fi
jgmenu_icon_size=0
2023-06-03 16:55:59 +02:00
TABS=200
2021-11-17 13:06:29 +01:00
[ $(pidof picom) ] && MENU_RADIUS=$jgtools_radius
[ -z $jgmenu_use_borders ] && menu_border=0
mkconfigfile
2023-05-10 23:48:43 +02:00
if [[ "$NOWPL" == "1" ]];then
clr="#22FF22"
read -r -d '' NOWPLAYLINES <<EOF
@rect,,${jgtools_padding},$((jgtools_padding+74)),300,24,0,left,top,,#222222 80,
2023-06-02 22:31:20 +02:00
@rect,,$((jgtools_padding+16)),$((jgtools_padding+78)),$((JGWIDTH-2*jgtools_padding-32)),16,4,left,top,,#222222 25,
2023-05-10 23:48:43 +02:00
@text,,$((jgtools_padding+18)),$((jgtools_padding+76)),$((JGWIDTH-2*jgtools_padding)),20,0,left,top,#FFFFFF 90,,""" 󰐊 󰐊 󰐊 <small>${NOW}</small>"""
EOF
else
2023-06-02 22:31:20 +02:00
clr="#444444"
2023-05-10 23:48:43 +02:00
fi
2021-11-17 13:06:29 +01:00
cat <<EOF > ${MENU_ITEMS}
2023-05-10 23:48:43 +02:00
@rect,,${jgtools_padding},${jgtools_padding},300,100,0,left,top,,#222222 35,
@rect,,${jgtools_padding},$((jgtools_padding+64)),8,36,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+10)),$((jgtools_padding+70)),8,30,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+20)),$((jgtools_padding+44)),8,56,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+30)),$((jgtools_padding+56)),8,44,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+40)),$((jgtools_padding+64)),8,36,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+50)),$((jgtools_padding+54)),8,46,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+60)),$((jgtools_padding+14)),8,86,0,left,top,,${clr} 100,
2023-06-02 22:31:20 +02:00
@rect,,$((jgtools_padding+70)),$((jgtools_padding+29)),8,71,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+80)),$((jgtools_padding+64)),8,36,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+90)),$((jgtools_padding+74)),8,26,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+100)),$((jgtools_padding+54)),8,46,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+110)),$((jgtools_padding+24)),8,76,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+120)),$((jgtools_padding+34)),8,66,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+130)),$((jgtools_padding+44)),8,56,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+140)),$((jgtools_padding+54)),8,46,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+150)),$((jgtools_padding+74)),8,26,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+160)),$((jgtools_padding+84)),8,16,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+170)),$((jgtools_padding+89)),8,11,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+180)),$((jgtools_padding+94)),8,6,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+190)),$((jgtools_padding+95)),8,5,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+200)),$((jgtools_padding+95)),8,5,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+210)),$((jgtools_padding+95)),8,5,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+220)),$((jgtools_padding+96)),8,4,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+230)),$((jgtools_padding+90)),8,10,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+240)),$((jgtools_padding+81)),8,19,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+250)),$((jgtools_padding+86)),8,14,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+260)),$((jgtools_padding+90)),8,10,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+270)),$((jgtools_padding+78)),8,22,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+280)),$((jgtools_padding+64)),8,36,0,left,top,,${clr} 100,
@rect,,$((jgtools_padding+290)),$((jgtools_padding+58)),8,42,0,left,top,,${clr} 100,
2023-05-10 23:48:43 +02:00
${NOWPLAYLINES}
$(printf '%s\n' "${out0[@]}")
2021-11-17 13:06:29 +01:00
$(printf '%s\n' "${out[@]}")
$(printf '%s\n' "${out2[@]}")
2023-05-10 23:48:43 +02:00
$(printf '%s\n' "${out3[@]}")
2021-11-17 13:06:29 +01:00
EOF
jgmenu --config-file=${CONFIG_FILE} --csv-file=${MENU_ITEMS} 2>/dev/null
exit 0
fi
2023-05-10 23:48:43 +02:00
printf '%s\n' "${out0[@]}"
2021-11-17 13:06:29 +01:00
printf '%s\n' "${out[@]}"
printf '%s\n' "${out2[@]}"
2023-05-10 23:48:43 +02:00
printf '%s\n' "${out3[@]}"
2021-11-17 13:06:29 +01:00
}
play() {
pkill -f radio-mpv
2023-05-10 23:48:43 +02:00
pkill -f yt-mpv
2021-11-17 13:06:29 +01:00
notify-send.sh "Playing now: " "$3" --icon=media-tape &
echo "$3" > "$NOWPLAY"
2023-05-10 23:48:43 +02:00
mpv --title=radio-mpv "$2" --input-ipc-server=/tmp/mpvsocket
}
playyt() {
pkill -f yt-mpv
pkill -f radio-mpv
notify-send.sh "Playing now: " "$3" --icon=media-tape &
echo "$3" > "$NOWPLAYYT"
if [[ "$2" == *"playlist"* ]];then
mpv --ytdl-raw-options="yes-playlist=" "$2" --no-video --title=yt-mpv --input-ipc-server=/tmp/mpvsocket
else
mpv "$2" --no-video --title=yt-mpv --input-ipc-server=/tmp/mpvsocket
fi
2021-11-17 13:06:29 +01:00
}
2023-05-10 23:48:43 +02:00
# Not really used
2021-11-17 13:06:29 +01:00
stop() {
2023-05-10 23:48:43 +02:00
stopyt
2021-11-17 13:06:29 +01:00
pkill -f radio-mpv
echo "" > "$NOWPLAY"
}
2023-05-10 23:48:43 +02:00
stopyt() {
stop
pkill -f yt-mpv
echo "" > "$NOWPLAYYT"
}
cavastart() {
cavakill
transparent-cava ${1} ${2} &2>/dev/null &
}
cavakill() {
pkill -f cavatransparent &
}
2021-11-17 13:06:29 +01:00
case "$1" in
play) play "$1" "$2" "$3";;
2023-05-10 23:48:43 +02:00
playyt) playyt "$1" "$2" "$3";;
2021-11-17 13:06:29 +01:00
stop) stop;;
2023-05-10 23:48:43 +02:00
stopyt) stopyt;;
cavastart) cavastart "$2" "$3";;
cavakill) cavakill;;
2021-11-17 13:06:29 +01:00
ipc|*) menu "$1";;
esac