I wanted to give you more information about my work.
The overal idea is not from me. I found it on Berrie’s blog, in an article called “Cover art in MPoD and MPaD” (http://www.katoemba.net/makesnosenseatall/2011/03/05/cover-art-in-mpod-and-mpad/comment-page-1/). The most interesting part was hidden in the comments related to this post. Yan shared a ruby script “that extracts the cover art from FLAC-file,ALAC-file,MP3-file,OGG-file.” After playing for a while with this Ruby based solution (i fixed some bugs and improved Yan’s script) and struggling with each new version of Volumio when i had to reinstall the stack necessary to run this script, i decided to rewrite it in PHP which is the language used for the server side development of Volumio’s UI.
Let me try to explain how it works :
- The PHP script receives the path to the song played by MPD.
- It will look, in the folder containing the song, for an artwork file called “Folder.xxx” or “Cover.xxx”. If such a file is found, its binary content will be returned.
- If no file is found, it will browse the songs contained in the folder and look for an artwork contained in the meta information of the song.
- If no artwork is found in songs, a placeholder can be returned.
Here is a short compatibility list based on the tests i have conducted for my own needs :
- jpg and png image file formats are supported
- mp3, AAC and ALAC music file formats are supported
- ID3 tags are supported up to version 2.4.0
That’s it for the basic. From a technical standpoint now :
- The PHP script has one dependency non satisfied with a fresh Volumio 1.4 install : PECL Imagick (http://pecl.php.net/package/imagick). This library is required to convert the image binaries into jpeg as png (or any other image file format) is not supported by the MPD client mobile apps (Mpod or Mpad). @Michelangelo : would it be possible to include this library in the next releases of Volumio ?
- The script i wrote is called “artwork.php”. @Michelangelo : this is not a fancy name and i am open to any suggestion, mainly if there is a naming convention to follow.
- The script relies heavily on a PHP library called getID3() (http://www.getid3.org). This library allows to extract the artwork included in the meta info of the song files. @Michelangelo : getID3() requires PHP 5.3 minimum, i guess this should not be an issue. Considering that this library is distributed under the GPL licence, is it possible to include it directly in Volumio ? There is a section related to this question on their site and the answer seems to be positive.
- I have modified some code in Volumio 1.4 :
“/etc/nginx/nginx.conf” : to create a rewrite rule redirecting to “artwork.php”
“/var/www/_player_engine.php” : to add the path to the song being played by MPD
“/var/www/templates/indextpl.html” and “/var/www/js/player_lib.js” : to display the artwork of the song being played in the “Playback” screen of the Web UI. Those two last modifications are more anecdotical and i did them to show how easy it is to display an artwork when the path to a song in the library is known. i.e. :
It means that artworks could easily be added almost anywhere in Volumio’s UI (in the “Library” or “Browse” screens).
Even if my scripts works reliably for a couple of months now, in my install, i don’t consider it as 100% finished. Here is what could be worked on or what i have in mind for possible future versions :
- more robust tests.
- test more images or song file formats (i.e. FLAC)
- add some cache to write on disk (in a “Folder.jpg” file) the artworks extracted from the songs. This would lower the latency to render the artwork next time the song is played.
- transfer the song files partially (the first bytes only) when searching for artworks in meta info. This would lower the latency to render the artwork, specially with big ALAC or FLAC files, saving some network traffic.
- add some settings for artwork management in Volumio settings screens.
- improve the way artworks are rendered. I have worked on some nice full CSS animated transition effect that i would like to apply when changing song.
- this list can grow with suggestions from the community
Tomorrow i will work on sharing my code for people to test this feature and for Michelangelo to review it.