rofi-mediaplayer: factoring

This commit is contained in:
Vincent Bernat 2023-05-18 12:22:43 +02:00
parent c889c25ae6
commit ad6b65015e

View file

@ -21,6 +21,8 @@ if [ $ROFI_RETV -ge 10 ] && [ $ROFI_RETV -le 28 ]; then
ROFI_RETV=1 ROFI_RETV=1
fi fi
playerctl="playerctl -p $mediaplayer"
case $ROFI_RETV in case $ROFI_RETV in
0) 0)
# Prompt # Prompt
@ -41,15 +43,15 @@ media-playback-pause Pause
media-playback-stop Stop media-playback-stop Stop
go-next Next track go-next Next track
multimedia-volume-control Open mixer panel multimedia-volume-control Open mixer panel
com.spotify.Client Open ${Mediaplayer} com.spotify.Client Open Spotify
EOF EOF
# Player status # Player status
status=$(playerctl -p $mediaplayer status) status=$($playerctl status)
case $status in case $status in
Playing|Paused) Playing|Paused)
title="$(playerctl -p $mediaplayer metadata xesam:title | sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g')" title="$($playerctl metadata xesam:title | sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g')"
artist="$(playerctl -p $mediaplayer metadata xesam:artist | sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g')" artist="$($playerctl metadata xesam:artist | sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g')"
status="$status <span weight='light'><i>${title} (${artist})</i></span>" status="$status <span weight='light'><i>${title} (${artist})</i></span>"
;; ;;
esac esac
@ -57,13 +59,13 @@ EOF
;; ;;
1) 1)
case $ROFI_INFO in case $ROFI_INFO in
1) playerctl -p $mediaplayer previous ;; 1) $playerctl previous ;;
2) playerctl -p $mediaplayer play ;; 2) $playerctl play ;;
3) playerctl -p $mediaplayer pause ;; 3) $playerctl pause ;;
4) playerctl -p $mediaplayer stop ;; 4) $playerctl stop ;;
5) playerctl -p $mediaplayer next ;; 5) $playerctl next ;;
6) i3-msg '[class="Pavucontrol"] focus' || i3-msg exec exec pavucontrol ;; 6) i3-msg '[class="Pavucontrol"] focus' || i3-msg exec exec pavucontrol ;;
7) i3-msg '[class="'${Mediaplayer}'"] focus' || i3-msg exec exec ${mediaplayer} ;; 7) i3-msg '[class="Spotify"] focus' || i3-msg exec exec spotify ;;
esac >&2 esac >&2
;; ;;
esac esac