diff options
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 |