2013-04-01 10:15:41 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# A simple notify script for now-playing songs on mpd. This script uses
|
|
|
|
# notify-send and mpc to get the current song information.
|
2013-04-17 11:36:06 +02:00
|
|
|
# ImageMagick is also needed for the cover.
|
2013-04-01 10:15:41 +02:00
|
|
|
|
|
|
|
# Configuration-------------------------------------------------------
|
|
|
|
|
|
|
|
# The music directory that contains the music and cover files
|
2013-04-17 11:36:06 +02:00
|
|
|
# Change according to your configuration
|
2013-04-01 10:15:41 +02:00
|
|
|
MUSIC_DIR="$HOME/Musica"
|
|
|
|
|
|
|
|
# The default cover to use (optional)
|
|
|
|
DEFAULT_ART=""
|
|
|
|
|
|
|
|
# Regex expression used for image search
|
|
|
|
IMG_REG="(front|cover|art|Folder|folder)\.(jpg|jpeg|png|gif)$"
|
|
|
|
|
|
|
|
# Path of temporary resized cover
|
|
|
|
TEMP_PATH="/tmp/mpdnotify_cover.png"
|
|
|
|
|
|
|
|
# Resize cover to (optional, recommended)
|
|
|
|
COVER_RESIZE="100x100"
|
|
|
|
|
|
|
|
# Thumbnail background (transparent by default)
|
|
|
|
COVER_BACKGROUND="none"
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
|
|
|
|
# determine file
|
|
|
|
file="$(mpc current -f %file%)"
|
|
|
|
|
|
|
|
# check if anything is playing at all
|
|
|
|
[[ -z $file ]] && exit 1
|
|
|
|
|
|
|
|
# Art directory
|
|
|
|
art="$MUSIC_DIR/${file%/*}"
|
|
|
|
|
|
|
|
# find every file that matches IMG_REG set the first matching file to be the
|
|
|
|
# cover.
|
|
|
|
cover="$(find "$art/" -maxdepth 1 -type f | egrep -i -m1 "$IMG_REG")"
|
|
|
|
|
|
|
|
# when no cover is found, use DEFAULT_ART as cover
|
|
|
|
cover="${cover:=$DEFAULT_ART}"
|
|
|
|
|
|
|
|
# check if art is available
|
|
|
|
if [[ -n $cover ]]; then
|
2013-04-16 21:29:22 +02:00
|
|
|
if [[ -n $COVER_RESIZE ]]; then
|
|
|
|
convert "$cover" -thumbnail $COVER_RESIZE -gravity center -background "$COVER_BACKGROUND" -extent $COVER_RESIZE "$TEMP_PATH"
|
2013-04-01 10:15:41 +02:00
|
|
|
cover="$TEMP_PATH"
|
2013-04-16 21:29:22 +02:00
|
|
|
fi
|
2013-04-16 23:28:31 +02:00
|
|
|
else
|
|
|
|
rm $TEMP_PATH
|
2013-04-01 10:15:41 +02:00
|
|
|
fi
|
2013-04-16 21:29:22 +02:00
|
|
|
|
|
|
|
exit 0
|