From f59f15b9e814800d9908c5ce9207c08109f1510b Mon Sep 17 00:00:00 2001 From: Breizh Date: Thu, 10 Nov 2022 00:54:47 +0100 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jour=20du=20gestionnaire=20de?= =?UTF-8?q?=20notifications=20MPD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .local/bin/mpd-notif | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/.local/bin/mpd-notif b/.local/bin/mpd-notif index 862822f..fd5c39a 100755 --- a/.local/bin/mpd-notif +++ b/.local/bin/mpd-notif @@ -3,37 +3,31 @@ export MPD_HOST="$HOME/.mpd/socket" DUNST_ID=$(sum <<<"mpd" | cut -d' ' -f1) -runtime="${XDG_RUNTIME_DIR}/i3blocks" -[[ ! -d "$runtime" ]] && mkdir -p "$runtime" -[[ ! -f "$runtime/mpd" ]] && touch "$runtime/mpd" +declare -- cursong prevsong while true do systemctl --user is-active mpd.service &>/dev/null || exit 1 timeout 5 mpc -w current - onelineinfos="$(mpc -f '[%artist%§|%name%§]%title%|[%file%]' current)" - if [[ -f "$runtime/mpd" && "$onelineinfos" != "$(<${runtime}/mpd)" ]] + prevsong="$cursong" + cursong="$(mpc -f '[[%artist%\n|%name%\n]%title%[\n%album%]]|[%file%]' current)" + if [[ "$cursong" != "$prevsong" ]] then - echo "$onelineinfos" > ${runtime}/mpd - echo "$(<${runtime}/mpd) " > ${runtime}/mpd-scroll - infos=$(mpc -f '[[%artist%\n|%name%\n]%title%[\n%album%]]|[%file%]' current) - if [[ -z "$infos" ]] + if [[ -z "$cursong" ]] then infos="Arrêt" fi - artist=$(sed -n 1p <<<$infos) - title=$(sed -n 2p <<<$infos) - album=$(sed -n 3p <<<$infos) + artist="$(sed -n 1p <<<"$cursong")" + title="$(sed -n 2p <<<"$cursong")" + album="$(sed -n 3p <<<"$cursong")" [[ -z "$title" ]] && title="$artist" && artist="" title=$(basename "$title") - curl -s -X POST -u breizh:$(pass show Web/pleroma.breizh.pm) \ + dunstify -r "$DUNST_ID" "MPD" "$cursong" + curl -s -X POST -u "breizh:$(pass show Web/pleroma.breizh.pm)" \ --data-urlencode "title=${title}" \ --data-urlencode "artist=${artist}" \ --data-urlencode "album=${album}" \ - https://pleroma.breizh.pm/api/v1/pleroma/scrobble &>/dev/null & - dunstify -r $DUNST_ID "MPD" "$infos" - [[ -f ${XDG_RUNTIME_DIR}/i3blocks/mpdvol ]] && mpc volume "$(<${XDG_RUNTIME_DIR}/i3blocks/mpdvol)" - #( pidof cava && sleep 1 && pkill -USR1 cava ) & + https://pleroma.breizh.pm/api/v1/pleroma/scrobble &>/dev/null fi done