Coverart display

From awesome

Jump to: navigation, search
Screenshot

Displaying Cover Art for mpd tracks with the help of naughty.

Cover Art should be in the same directory with song file.

[edit] Used scripts

I created two shellscripts for this task:

1) coverart.sh - Detects current song file directory and finds coverart within it

#!/bin/bash

DEFAULT_COVER="/path/to/defaultcover.png"

MUSICDIR=`cat /etc/mpd.conf | grep -v "#" | grep music_directory`
MUSICDIR=${MUSICDIR:16}
MUSICDIR=${MUSICDIR%/$}

MFILE=`mpc current -f %file%`
MFILE=${MFILE%/*}
MFILE=${MFILE%/$}

FULLDIR="$MUSICDIR/$MFILE"

COVERS=`ls "$FULLDIR" | grep "\.jpg\|\.png\|\.gif"`

if [ -z "$COVERS" ]; then
	COVERS="$DEFAULT_COVER"
else
	TRYCOVERS=`echo "$COVERS" | grep "cover\|front" | head -n 1`

	if [ -z "$TRYCOVERS" ]; then
		TRYCOVERS=`echo "$COVERS" | head -n 1`
		if [ -z "$TRYCOVERS" ]; then
			TRYCOVERS="$DEFAULT_COVER"
		else
			TRYCOVERS="$FULLDIR/$TRYCOVERS"
		fi
	else
		TRYCOVERS="$FULLDIR/$TRYCOVERS"
	fi

	COVERS="$TRYCOVERS"
fi

echo -n "$COVERS"

2) mpdinfo.sh - Prints any info you want to see in tooltip

#!/bin/bash

echo "Artist: `mpc current -f %artist%`"
echo "Album: `mpc current -f %album%`"
echo -n "Year: `mpc current -f %date%`"

[edit] Changes in rc.lua

1) You need to add function to show/hide tooltip

local coverart_nf
function coverart_show()
    local img = awful.util.pread("/path/to/coverart.sh")
    local ico = image(img)
    local txt = awful.util.pread("/path/to/mpdinfo.sh")
    coverart_nf = naughty.notify({icon = ico, icon_size = 100, text = txt})
end

function coverart.hide()
    if coverart_nf ~= nil then
	    naughty.destroy(coverart_nf)
    end
end

2) You need to add mouse event handlers to your widget. Also you are able to change your naughty popup position.

Note: mpdw is my widget displaying mpd info.

naughty_default_position = "top_right"
naughty_coverart_position = "bottom_left"

mpdw:add_signal("mouse::enter", function()
	naughty.config.presets.normal.position = naughty_coverart_position 
	coverart_show()
end)

mpdw:add_signal("mouse::leave", function()
	naughty.config.presets.normal.position = naughty_default_position 
	coverart_hide()
end)
Personal tools