dotfiles/.local/bin/mpd-notif

40 lines
1.3 KiB
Text
Raw Normal View History

2019-06-13 20:12:29 +02:00
#!/bin/bash
export MPD_HOST="$HOME/.mpd/socket"
2020-01-09 21:17:01 +01:00
DUNST_ID=$(sum <<<"mpd" | cut -d' ' -f1)
runtime="${XDG_RUNTIME_DIR}/i3blocks"
[[ ! -d "$runtime" ]] && mkdir -p "$runtime"
2021-05-18 19:13:45 +02:00
[[ ! -f "$runtime/mpd" ]] && touch "$runtime/mpd"
2019-06-13 20:12:29 +02:00
while true
do
2021-01-15 21:59:21 +01:00
systemctl --user is-active mpd.service &>/dev/null || exit 1
2020-01-09 21:17:01 +01:00
timeout 5 mpc -w current
2021-04-05 17:09:57 +02:00
onelineinfos="$(mpc -f '[%artist%§|%name%§]%title%|[%file%]' current)"
2021-05-18 19:13:45 +02:00
if [[ -f "$runtime/mpd" && "$onelineinfos" != "$(<${runtime}/mpd)" ]]
2019-06-13 20:12:29 +02:00
then
2020-01-09 21:17:01 +01:00
echo "$onelineinfos" > ${runtime}/mpd
echo "$(<${runtime}/mpd) " > ${runtime}/mpd-scroll
2021-04-05 17:09:57 +02:00
infos=$(mpc -f '[[%artist%\n|%name%\n]%title%[\n%album%]]|[%file%]' current)
2020-01-09 21:17:01 +01:00
if [[ -z "$infos" ]]
then
infos="<i>Arrêt</i>"
fi
artist=$(sed -n 1p <<<$infos)
title=$(sed -n 2p <<<$infos)
album=$(sed -n 3p <<<$infos)
[[ -z "$title" ]] && title="$artist" && artist=""
title=$(basename "$title")
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)"
2020-05-17 20:29:45 +02:00
#( pidof cava && sleep 1 && pkill -USR1 cava ) &
2019-06-13 20:12:29 +02:00
fi
done
2020-01-09 21:17:01 +01:00