dotfiles/.local/bin/mpd-notif

33 lines
926 B
Bash
Executable file

#!/bin/bash
export MPD_HOST="$HOME/.mpd/socket"
DUNST_ID=$(sum <<<"mpd" | cut -d' ' -f1)
declare -- cursong prevsong
while true
do
systemctl --user is-active mpd.service &>/dev/null || exit 1
timeout 5 mpc -w current
prevsong="$cursong"
cursong="$(mpc -f '[[%artist%\n|%name%\n]%title%[\n%album%]]|[%file%]' current)"
if [[ "$cursong" != "$prevsong" ]]
then
if [[ -z "$cursong" ]]
then
infos="<i>Arrêt</i>"
fi
artist="$(sed -n 1p <<<"$cursong")"
title="$(sed -n 2p <<<"$cursong")"
album="$(sed -n 3p <<<"$cursong")"
[[ -z "$title" ]] && title="$artist" && artist=""
title=$(basename "$title")
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
fi
done