Skip to content

Instantly share code, notes, and snippets.

@Pigpog
Last active January 5, 2022 01:47
Show Gist options
  • Save Pigpog/a9dead227254162d8edeb15eaaad98c6 to your computer and use it in GitHub Desktop.
Save Pigpog/a9dead227254162d8edeb15eaaad98c6 to your computer and use it in GitHub Desktop.
Music Player Daemon Discord rich presence shell script
#!/bin/dash
# MPD Discord Rich Presence
# Requires github.com/Pigpog/discord-rich-presence-cli
timecalc(){
echo "$(date +'%s') + ((($3 * 60) + $4) - (($1 * 60) + $2))" | bc
}
{
# Application ID
echo 838256184724029450;
while [ 0 ]; do
PLAYING="$(mpc current)";
# If playback is stopped
[ -z "$PLAYING" ] && echo && PLAYING="$(mpc -w current)";
# Details and State
echo $PLAYING | sed 's/ - /\n/' | tac;
# Large image key
echo mpd;
# Small image key
STATUS="$(mpc status | grep "\[playing\]")" && echo "playing" || {
echo "paused";
sleep 10s && echo &
mpc idle player > /dev/null && kill -15 $! &
}
# Start timestamp
echo 0;
# End timestamp
[ ! -z "$STATUS" ] && timecalc $(echo "$STATUS" | cut -f4- -d\ | tr ':/' ' ') || echo "0";
# Wait for changes
mpc idle player > /dev/null;
done;
} | ~/src/discord-rich-presence-cli/send-presence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment