Skip to content

Instantly share code, notes, and snippets.

@mrMustacho
Last active January 26, 2025 05:41
Show Gist options
  • Save mrMustacho/18c858e53fc8dd8ac3d4878dab6cad91 to your computer and use it in GitHub Desktop.
Save mrMustacho/18c858e53fc8dd8ac3d4878dab6cad91 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 '##%track% - %title%\n%artist% - %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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment