sdushantha / kunst

Download and display album art or display embedded album art

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Run less frequently (only on album change)

dextre opened this issue · comments

Due to the broadness of mpc idle player, kunst currently runs every song change, play state change, or just seeking within a song. If you seek or skip tracks on albums often, it can needlessly run dozens of times when the cover hasn't changed once. This gets more wasteful if you're dealing with very large files or resolutions.

On some artwork (small ones it has to scale up?) I've noticed a flash of sxivs background color while its switching art, which gets really distracting at fullscreen when it happens every seek or song change.

To remedy these I've made mine only run when the album changes like so:

ALBUM="$(dirname "$(mpc current -f %file%)")"
mpc idle player &>/dev/null && (mpc status | grep "\[playing\]" &>/dev/null) && sleep .3 && if [ "$ALBUM" != "$(dirname "$(mpc current -f %file%)")" ]; then break; fi

This prevents the vast majority of find_album_art runs.
I'm using the album path for ALBUM as a personal preference, but a more universal way (since many people keep a bunch of random tracks in one dir) could be:
mpc current -f "[[%albumartist% - |%artist% - ]%album%]|%file%"
This should try AlbumArtist - Album to not update on every track change on multi-artist compilations, then Artist or just Album if they exist, or falls back to just file path on songs missing all tags (which updates on every track change).

Alternatively, to only fix the run-every-seek issue, you could keep track of song changes like "$SONG" != "$(mpc current -f %file%)". Though only running on album changes is much more efficient. Ideally there could be an option to toggle between or disable the feature.

I'm posting this as a suggestion not a PR because I'm a bash & git noob and I'm sure my if method can be improved by someone. I added a sleep .3 in my example above because in some circumstances it was not detecting an album change (I'm not sure why, could be because my mpd is on another pc across the network), adding the delay seemed to fix mine.