Skip to content

Instantly share code, notes, and snippets.

@bonelifer
Forked from mrMustacho/mpd-notify.sh
Created January 26, 2025 05:41
Show Gist options
  • Save bonelifer/610a957b13c00009639ef621c88ca3a6 to your computer and use it in GitHub Desktop.
Save bonelifer/610a957b13c00009639ef621c88ca3a6 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Send notification with album art (if found) when mpd plays a new song, depends on libnotify
readonly MUSIC_DIR="${HOME}/Music"
while true; do
SONG_PATH="$(mpc --format '%file%' current --wait)"
if [[ ! -z "$SONG_PATH" ]]; then # check if song is being played
SONG_DIR="$(dirname "${SONG_PATH}")"
# Current implementation for covers, search recursevly from the current song directory
# if not found then prints the default music folder icon
ALBUM_ART_PATH="$(find "${MUSIC_DIR}"/"${SONG_DIR}" -type f -iname '*cover*.jpg' -o -iname '*book*.jpg' | head -n 1)"
# ALBUM_ART_PATH="${MUSIC_DIR}/${SONG_DIR}/cover.jpg"
SONG_INFO="$(mpc --format '%title%\n%artist%\n%album%' current)"
if [[ -f "${ALBUM_ART_PATH}" ]]; then # cover exist
notify-send -i "${ALBUM_ART_PATH}" "Now Playing" "${SONG_INFO}"
else
notify-send -i folder-music "Now Playing" "${SONG_INFO}"
fi
fi
done
@bonelifer
Copy link
Author

Adjusted format output to my liking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment