You are not logged in.

#1 2016-09-04 09:12:15

aplainzetakind
Member
Registered: 2016-05-16
Posts: 3

Conky $if_match behaviour with $exec

I set up conky and started playing around with it. I figured it would be nice to have an mpd section which displays album art. Here's what I did to that end:

The relevant section in my conky.conf:

${if_match ${exec mpc --format %artist% | sed -nr '2p' | sed 's/^.*\(..\)\:\(..\)\/.*$/\1\2/'} <= 1}
${exec /usr/bin/getconkycover}
$endif
$alignc${image /tmp/conky_mpd.jpg -p 75,510 -s 150x150 -n}

The if_match statement checks if we're in the first second of a new song, with the hope that only in that period my album-art-grabbing getconkycover script will run. The script is thus:

#!/bin/bash

ARTIST=$(mpc --format %artist% | head -n 1)
ALBUM=$(mpc --format %album% | head -n 1)           #Get the names of the artist and album of the current track from mpc
DIR=/tmp/$ARTIST/$ALBUM/                                     #Embed that information in the directory structure under /tmp
DIR=${DIR//\ /}                                                        #Strip spaces to avoid syntax troubles
FILE=${DIR}conky_mpd.jpg
if [[ ! -f $FILE ]]
then
	mkdir -p $DIR      #If an image file doesn't already exist, create the appropriate path...
	glyrc cover --artist "$ARTIST" --album "$ALBUM" --formats jpeg --write $FILE --from 'musicbrainz;lastfm;local;rhapsody'>/dev/null 2>/dev/null   #...and grab the image from the internet
fi
ln -sf $FILE /tmp/conky_mpd.jpg     #have a symlink point to it
exec date >> /tmp/conklog   #to be able to check how often the script is invoked

This creates a bit of a clutter under /tmp but does the job while avoiding multiple downloads of the same images upon playback of tracks from the same album.

Basically this works. But my problem is that the $if_match ... $endif seems to only hide the intervening elements from sight while they're actually still alive (if I add some plaintext inbetween, it really only gets displayed for a moment at the beginning, so the if_match check does work). Specifically, the log from the last line of the script shows that it gets invoked every second. If I use execi/texeci, then it is invoked likewise constanty with the specified interval (which can miss the beginning of tracks by considerable margins and switch pictures ridiculously late).

I hate to have such redundancy and I'd really like to have a clean way to fire that script just once at the beginning of a track. Any suggestions would be much welcome. Thanks.

Offline

Board footer

Powered by FluxBB