Philip P. Ide

Author, programmer, science enthusiast, half-wit.
Life is sweet. Have you tasted it lately?

User Tools

Site Tools


blog:articles:general:conky_mpd

Conky and MPD

Conky displaying an MPD panel Conky is a widget available on Linux, that allows the display of an enormous amount of data about system resources in real-time. Amongst those resources it can display is data available from MPD - Music Player Daemon. However, there are some bits of info that MPD outputs that conky doesn't collect, and some of that is particularly interesting.

It is possible to get that information though, although there are different techniques. For example, this extracts the current queue position and the length of the queue:

${execi 1 (mpc -h romeo status|grep 'playing.'|cut -f2 -d'#'|cut -f1 -d' ')}

As you can see, it requires a bit of shell arcanery, but actually it's pretty straightforward. For the elapsed time, I simply took the values of two conky variables (mpd_length and mpd_elapsed), which appear as 00:00 format time strings, converted them to seconds, subtracted one from the other and turned the result back into a formatted time string. In this case, I wrote a few functions in lua and added the lua script to conky.

For the length of the entire queue, I wrote an application in Rust (which compiles down to optimised machine code). This application fetches the entire playlist from MPD and then iterates through the list extracting the length of the track in seconds, and accumulating the results - then formats the final result as a 00:00:00 formatted time string. The source code is available on GitHub if you want to compile it for yourself.

Update: I have written another function in Rust, this collects a whole bunch of information from the MPD queue, and outputs a Conky parsable formatted string, so it can not only display all that information, but apply Conky positional instructions, such as $alignc, ${offset}, ${voffset}, change colours/font etc. This allows me to display the following queue information: length of the queue as a timestring, elapsed time, remaining time, percentage elapsed. This is available at mpd_queue_stats on GitHub.

You may notice there is a 'File:' marker just below the track title. This only displays if there is no title information available (think of it as a fallback). I found that having the filename displayed with the title makes for a confusing display, to I made them either/or options.

This just left fetching the artwork. There is a wonderful shell script called Vindauga, which fetches the artwork, and does a fine job of it too. I made some small changes to the script so it had a better chance of catching perfectly legal artwork names (as the default vindauga only captured a subset). If you follow the link to the vindauga article, and from there to the github repository, and then look in the 'issues' tab, you'll see a comment by stroggprog (that's me). In the comment you'll see the changes I suggested.

Incidentally, my MPD is running on a Raspberry Pi, which is an entirely different machine from my desktop, which is running Mint Cinnamon on an AMD 8-core brick. Conky has no problems fetching mpd information from another machine, it just needs to know the hostname or IP address of the machine in question. My desktop looks like this: full desktop

As you can see, the conky panel on the right is displaying system information, and the panel in the top left is displaying information about the queue and the currently playing track. All in all, I think it's a sexy desktop. I'm going to upload the rust code to a repository on github, and I'm debating whether the lua code should be included with it or as a separate repo.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies

Discussion

Enter your comment:
H W S A᠎ M
 
blog/articles/general/conky_mpd.txt · Last modified: 2024/06/21 13:09 by Phil Ide

Except where otherwise noted, content on this wiki is licensed under the following license: Copyright © Phil Ide
Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki