Cover Art With conky And mpd

After one year of using mpd on my Fluxbox machine I have started to sift through my music collection, fixing tags and adding album covers. Since there is no need for having album art if you do not show it, I set out to make conky show the images on my disk. I was lucky to find script in the depth of some forum (reference lost) that inspired the following piece of bash code.

IFS=$'\t' mpd_array=( $(MPD_HOST=localhost MPD_PORT=6600 \
          mpc --format "\t%artist%\t%album%\t%file%\t") );


if [[ ! -f /tmp/"${mpd_array[1]}".album ]] ; then
  rm -f /tmp/*.album &> /dev/null;

  album=`dirname "/path/to/music/${mpd_array[2]}"`;
  cover=$album"/"`ls $album | egrep "jpeg|jpg|png|gif" | head -n 1`;

  if [[ ! -f $cover ]]; then
    cp $placeholder /tmp/$filename;
    convert $cover -resize "130>x" -alpha On -channel A \
                   -evaluate set 25% /tmp/$filename;

When this script is run, the currently playing album’s artist and name are retrieved and the corresponding image — or a dummy — is copied to /tmp for conky to pick up. Note that always the first image in the album’s folder is chosen and then manipulated with imagemagick; you might have to do a little coding yourself if you store your music or covers differently. Note that all time consuming stuff is done only once per album run.

On the conky side, life is easy now. Just add something like this to your .conkyrc:

${if_running mpd}
MPD: ${alignr}${mpd_status}${if_mpd_playing}
 ${mpd_artist 25}
 ${mpd_album 25}
 ${mpd_title 25}
 ${mpd_bar 3,130}
 ${exec ~/bin/conky_mpd_art}${image /tmp/conky_cover.png -p 3,772 -s 130x130 -n}

You have to adapt the visual thingies to your liking, of course.

Comments are closed.