mabox-pipemenus/usr/bin/mb-music

110 lines
2.7 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
NOWPLAY="$HOME/.config/mabox/.radio-mpv"
menu() {
PLAYLIST="$HOME/.config/pyradio/stations.csv"
case $LANG in
pl*)
VOL="Sterowanie głośnością"
RADIO="Radio Internetowe"
EDITSTATIONS="Edytuj listę stacji"
RADIOBROWSER="Szukaj stacji online"
2021-11-20 02:16:21 +01:00
MPV="Odtwarzaj za pomocą mpv (bez gui)"
MPVPLAY="Słuchaj stacji..."
2021-11-17 13:06:29 +01:00
;;
*)
VOL="Volume Control"
RADIO="Internet Radio"
EDITSTATIONS="Edit stations list"
RADIOBROWSER="Search Radio Stations online"
2021-11-20 02:16:21 +01:00
MPV="Play with mpv (no gui)"
MPVPLAY="Listen to radio..."
2021-11-17 13:06:29 +01:00
;;
esac
out+=("^sep($VOL)")
out+=("Pavucontrol (super+v),pavucontrol")
out+=("^sep($RADIO)")
pgrep -f radio-mpv > /dev/null && NOW="$(<"$NOWPLAY")" out+=("Stop <i>$NOW</i>,pkill -f radio-mpv") out+=("^sep()")
2021-11-20 02:16:21 +01:00
out+=("$MPV,^checkout(mpvradio)")
2021-11-17 13:06:29 +01:00
out2+=("^tag(mpvradio)")
2021-11-20 02:16:21 +01:00
out2+=("^sep($MPVPLAY)")
2021-11-17 13:06:29 +01:00
#mapfile -t stations < "$PLAYLIST"
while IFS=$'\r\n' read -r line
do
url=${line#*,}
name=${line%,*}
out2+=("${name},mb-music play "\""${url}"\"" "\""${name}"\""")
done <"$PLAYLIST"
out+=("^sep(PyRadio (super+r))")
out+=("PyRadio,terminator --geometry=420x440-20-20 -e pyradio")
out+=("Cava,terminator --geometry=420x200-460-20 -e cava")
out+=("^sep()")
out+=("$EDITSTATIONS,xdg-open $PLAYLIST")
out+=("$RADIOBROWSER,xdg-open https://www.radio-browser.info")
### 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
MENU_VALIGN="center"
fi
MENU_PADDING_TOP=${jgtools_padding:-0}
MENU_HALIGN="left"
JGWIDTH=320
if [[ "$1" == "ipc" ]]; then
POSITION_MODE="ipc"
else
POSITION_MODE="fixed"
fi
jgmenu_icon_size=0
[ $(pidof picom) ] && MENU_RADIUS=$jgtools_radius
[ -z $jgmenu_use_borders ] && menu_border=0
mkconfigfile
cat <<EOF > ${MENU_ITEMS}
$(printf '%s\n' "${out[@]}")
$(printf '%s\n' "${out2[@]}")
EOF
jgmenu --config-file=${CONFIG_FILE} --csv-file=${MENU_ITEMS} 2>/dev/null
exit 0
fi
printf '%s\n' "${out[@]}"
#if [[ $1 == "-r" ]]; then # not used
#printf '%s\n' "^sep()"
#printf '%s\n' "<i>$REMOVE</i>,mb-setvar places_jgdesktops=false;mb-jgtools places"
#fi
printf '%s\n' "${out2[@]}"
}
play() {
pkill -f radio-mpv
notify-send.sh "Playing now: " "$3" --icon=media-tape &
echo "$3" > "$NOWPLAY"
mpv --title=radio-mpv "$2"
}
stop() {
pkill -f radio-mpv
echo "" > "$NOWPLAY"
}
case "$1" in
play) play "$1" "$2" "$3";;
stop) stop;;
ipc|*) menu "$1";;
esac