diff options
author | David Luevano Alvarado <55825613+luevano@users.noreply.github.com> | 2020-12-29 17:15:50 -0700 |
---|---|---|
committer | David Luevano Alvarado <55825613+luevano@users.noreply.github.com> | 2020-12-29 17:15:50 -0700 |
commit | c49a69e6ac7c4da458101fa544ea2431fa134558 (patch) | |
tree | a7976ad5f49a860592d91615aba4aac819e29c38 /.local | |
parent | 3d822887103658e04f7dc0326fa72f6606e50bf2 (diff) |
Fix bugs
Diffstat (limited to '.local')
-rwxr-xr-x | .local/bin/pa_control | 4 | ||||
-rwxr-xr-x | .local/bin/pctl_status | 110 | ||||
-rwxr-xr-x | .local/bin/statusbar/player_mpris_zscroll_module | 51 |
3 files changed, 131 insertions, 34 deletions
diff --git a/.local/bin/pa_control b/.local/bin/pa_control index b3d566a..1109064 100755 --- a/.local/bin/pa_control +++ b/.local/bin/pa_control @@ -91,10 +91,10 @@ EOF case "$1" in get-sink) - notify-send "Current sink" "$(get_default_sink_nickname)" + notify-send -u low "Current sink" "$(get_default_sink_nickname)" ;; next-sink) set_next_sink - notify-send "Changed to sink" "$(get_default_sink_nickname)" + notify-send -u low "Changed sink" "$(get_default_sink_nickname)" ;; esac diff --git a/.local/bin/pctl_status b/.local/bin/pctl_status index 0eccfb8..bc6af6e 100755 --- a/.local/bin/pctl_status +++ b/.local/bin/pctl_status @@ -1,30 +1,110 @@ -#!/bin/bash +#!/bin/sh -playerctl_status=$(playerctl status 2>/dev/null) -exit_code=$? +get_pctl_status () { + player="$(check_for_mpd)" -if [ $exit_code -eq 0 ]; then - status=$playerctl_status -else - status="NPF" -fi + if [ "$player" = "" ]; then + playerctl_status=$(playerctl status 2>/dev/null) + else + playerctl_status=$(playerctl -p "$player" status 2>/dev/null) + fi + exit_code=$? -case $1 in - status) - echo "$status" - ;; - text) - artist="$(playerctl metadata artist 2>/dev/null)" - title="$(playerctl metadata title 2>/dev/null)" + if [ $exit_code -eq 0 ]; then + echo "$playerctl_status" + else + echo "NPF" + fi +} + +check_for_mpd () { + pctl_players="$(playerctl -l)" + + while IFS= read line; do + line="$(echo $line | sed -e 's/\ //')" + + if [ "$line" = "mpd" ]; then + echo "$line" + fi + done <<EOF + $pctl_players +EOF +} + +get_display_text () { + player="$(check_for_mpd)" + status="$(get_pctl_status "$player")" + + if [ "$player" = "mpd" ]; then + if [ "$status" = "Stopped" ]; then + echo "%{F$(xresource color8)}No music playing%{F}" + elif [ "$status" = "Paused" ]; then + artist="$(mpc --format '[%albumartist%]|[%artist%]' current)" + title="$(mpc --format '%title%' current)" + + echo "%{F$(xresource color8)}$artist - $title%{F}" + elif [ "$status" = "NPF" ]; then + echo "%{F$(xresource color8)}No player found%{F}" + else + artist="$(mpc --format '[%albumartist%]|[%artist%]' current)" + title="$(mpc --format '%title%' current)" + echo "$artist - $title" + fi + else if [ "$status" = "Stopped" ]; then echo "%{F$(xresource color8)}No music playing%{F}" elif [ "$status" = "Paused" ]; then + artist="$(playerctl metadata artist)" + title="$(playerctl metadata title)" + echo "%{F$(xresource color8)}$artist - $title%{F}" elif [ "$status" = "NPF" ]; then echo "%{F$(xresource color8)}No player found%{F}" else + artist="$(playerctl metadata artist)" + title="$(playerctl metadata title)" + echo "$artist - $title" fi + fi +} + +get_metadata () { + player="$(check_for_mpd)" + status="$(get_pctl_status "$player")" + + if [ "$player" = "mpd" ]; then + if [ "$status" = "Playing" ] || [ "$status" = "Paused" ]; then + artist="$(mpc --format '[%albumartist%]|[%artist%]' current)" + album="$(mpc --format '%album%' current)" + title="$(mpc --format '%title%' current)" + + echo "yes>$artist>$album>$title" + fi + else + if [ "$status" = "Playing" ] || [ "$status" = "Paused" ]; then + artist="$(playerctl metadata artist)" + album="$(playerctl metadata album)" + title="$(playerctl metadata title)" + + if [ "$album" = "" ]; then + echo "no>$artist>$title" + else + echo "yes>$artist>$album>$title" + fi + fi + fi +} + +case $1 in + status) + get_pctl_status + ;; + text) + get_display_text + ;; + get-metadata) + get_metadata ;; esac diff --git a/.local/bin/statusbar/player_mpris_zscroll_module b/.local/bin/statusbar/player_mpris_zscroll_module index 6645e4c..ffe8f36 100755 --- a/.local/bin/statusbar/player_mpris_zscroll_module +++ b/.local/bin/statusbar/player_mpris_zscroll_module @@ -23,29 +23,46 @@ show_panel (){ } send_notification (){ - player_status=$(playerctl status 2> /dev/null) - if [ "$player_status" = "Playing" ]; then - artist="$(playerctl metadata artist)" - album="$(playerctl metadata album)" - title="$(playerctl metadata title)" - - if [ $album = "\n"]; then - notify-send "$icon $artist - $album" "$title" + player_status="$(pctl_status status)" + + metadata="$(pctl_status get-metadata)" + contains_album="$(echo $metadata | cut -d'>' -f1)" + + artist= + album= + title= + + summary= + body= + + pp_icon= + + if [ "$player_status" = "Playing" ] || [ "$player_status" = "Paused" ]; then + if [ "$contains_album" = "yes" ]; then + artist="$(echo $metadata | cut -d'>' -f2)" + album="$(echo $metadata | cut -d'>' -f3)" + title="$(echo $metadata | cut -d'>' -f4)" + + summary="$artist ($album)" + body="$title" + else - notify-send "$icon $artist" "$title" + artist="$(echo $metadata | cut -d'>' -f2)" + title="$(echo $metadata | cut -d'>' -f3)" + + summary="$artist" + body="$title" fi - elif [ "$player_status" = "Paused" ]; then - artist="$(playerctl metadata artist)" - album="$(playerctl metadata album)" - title="$(playerctl metadata title)" - if [ $album = "\n"]; then - notify-send "$icon (Paused) $artist - $album" "$title" + if [ "$player_status" = "Playing" ]; then + pp_icon="" else - notify-send "$icon (Paused) $artist" "$title" + pp_icon="" fi + + notify-send -u low "$icon $pp_icon $summary" "$body" else - notify-send "$icon Nothing playing" + notify-send -u low "$icon Nothing playing" fi } |