Mise à jour du gestionnaire de notifications MPD

This commit is contained in:
Breizh 2022-11-10 00:54:47 +01:00
parent 90aa8ddad1
commit f59f15b9e8
1 changed files with 11 additions and 17 deletions

View File

@ -3,37 +3,31 @@
export MPD_HOST="$HOME/.mpd/socket" export MPD_HOST="$HOME/.mpd/socket"
DUNST_ID=$(sum <<<"mpd" | cut -d' ' -f1) DUNST_ID=$(sum <<<"mpd" | cut -d' ' -f1)
runtime="${XDG_RUNTIME_DIR}/i3blocks" declare -- cursong prevsong
[[ ! -d "$runtime" ]] && mkdir -p "$runtime"
[[ ! -f "$runtime/mpd" ]] && touch "$runtime/mpd"
while true while true
do do
systemctl --user is-active mpd.service &>/dev/null || exit 1 systemctl --user is-active mpd.service &>/dev/null || exit 1
timeout 5 mpc -w current timeout 5 mpc -w current
onelineinfos="$(mpc -f '[%artist%§|%name%§]%title%|[%file%]' current)" prevsong="$cursong"
if [[ -f "$runtime/mpd" && "$onelineinfos" != "$(<${runtime}/mpd)" ]] cursong="$(mpc -f '[[%artist%\n|%name%\n]%title%[\n%album%]]|[%file%]' current)"
if [[ "$cursong" != "$prevsong" ]]
then then
echo "$onelineinfos" > ${runtime}/mpd if [[ -z "$cursong" ]]
echo "$(<${runtime}/mpd) " > ${runtime}/mpd-scroll
infos=$(mpc -f '[[%artist%\n|%name%\n]%title%[\n%album%]]|[%file%]' current)
if [[ -z "$infos" ]]
then then
infos="<i>Arrêt</i>" infos="<i>Arrêt</i>"
fi fi
artist=$(sed -n 1p <<<$infos) artist="$(sed -n 1p <<<"$cursong")"
title=$(sed -n 2p <<<$infos) title="$(sed -n 2p <<<"$cursong")"
album=$(sed -n 3p <<<$infos) album="$(sed -n 3p <<<"$cursong")"
[[ -z "$title" ]] && title="$artist" && artist="" [[ -z "$title" ]] && title="$artist" && artist=""
title=$(basename "$title") 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 "title=${title}" \
--data-urlencode "artist=${artist}" \ --data-urlencode "artist=${artist}" \
--data-urlencode "album=${album}" \ --data-urlencode "album=${album}" \
https://pleroma.breizh.pm/api/v1/pleroma/scrobble &>/dev/null & 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 ) &
fi fi
done done