diff options
author | EuAndreh <eu@euandre.org> | 2023-02-20 12:11:51 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2023-02-20 12:12:03 -0300 |
commit | c49a432e10da90f4b5e24b0c5acb4019fc32e137 (patch) | |
tree | 7b06af41708cf2932a46948211d8495d63cc0f11 /bin/player | |
parent | bin/wms: Use player(1) over accessing the cache file (diff) | |
download | dotfiles-c49a432e10da90f4b5e24b0c5acb4019fc32e137.tar.gz dotfiles-c49a432e10da90f4b5e24b0c5acb4019fc32e137.tar.xz |
Use "player synopsis" for MPRIS status string
Diffstat (limited to 'bin/player')
-rwxr-xr-x | bin/player | 37 |
1 files changed, 32 insertions, 5 deletions
@@ -22,7 +22,7 @@ help() { - next: go to the next track - play-pause: play/pause - rotate: rotate across available MPRIS players - - current: show the current MPRIS player + - synopsis: show the current MPRIS player and title Manipulate the MPRIS audio player. @@ -32,7 +32,7 @@ help() { Change the current MPRIS player: - $ player current + $ player synopsis Play/pause: @@ -104,6 +104,29 @@ next_player() { fi } +format_player_name() { + sed 's|^firefox\.instance.*$|firefox|' +} + +formatted_player_title() { + TITLE="$( + playerctl --player="$CURRENT_PLAYER" metadata xesam:title \ + 2>/dev/null ||: + )" + if [ -z "$TITLE" ]; then + TITLE="$( + playerctl --player="$CURRENT_PLAYER" metadata xesam:url | + uri -d | + sed 's|^.*/home/andreh/Downloads/||' + )" + fi + if [ ${#TITLE} -gt 82 ]; then + printf '%s...\n' "$(printf '%s' "$TITLE" | head -c 80)" + else + printf '%s\n' "$TITLE" + fi +} + case "$ACTION" in backward) playerctl --player="$CURRENT_PLAYER" position 5- @@ -123,10 +146,14 @@ case "$ACTION" in rotate) PLAYER="$(next_player)" echo "$PLAYER" > "$CURRENT_PLAYER_PATH" - notify-send -t 1000 "$PLAYER" 'current MPRIS target' + notify-send -t 1000 -- \ + "$(printf '%s' "$PLAYER" | format_player_name)" \ + 'current MPRIS target' ;; - current) - printf '%s\n' "$CURRENT_PLAYER" + synopsis) + printf '%s: %s\n' \ + "$(echo "$CURRENT_PLAYER" | format_player_name)" \ + "$(formatted_player_title)" ;; *) printf 'Bad ACTION: "%s".\n\n' "$ACTION" >&2 |