
Okay, you’ve probably noticed it by now, that if you actually visit this site via your web browser and not an RSS reader that over on the right menu sometimes you will see a ‘Currently Playing’ section which looks similar to that in the screenshot on the right. If you were a previous visitor before the redesign, you would have also seen it was a lot more basic than it is now.
The current setup is actually quite complex (we’re talking about the process to show cover art for albums - for those who have missed it). I’ve seen this on one of the other blogs I frequent, asterisk*. I’m sure the currently playing function over there functions totally different to here. In fact, I know it does because the author of asterisk* uses iTunes on a Mac, and over here i’m using Winamp on a Windows PC.
The complex structure?
- Details of currently playing track (Title, Artist, Album, Length, Genre etc) are sent via a HTTP POST containing a special key to a script stored on this server.
- The script then generates a “friendly name” for both the artist and album. (Similar to that of the friendly post URL’s you see here.
- The artist and album are then compared to a ‘replacement list. The replacement list serves to replace artists or albums depending on their album. This allows us to ‘fake’ an album or artist so we can get an image for “Various Artist” albums where the ID3 artist tag differs for each track.
- The artist and album are then joined together in the format of artist_album and then a local cache here is checked to see if it contains the cover art.
- If the cover art exists, we don’t bother doing anything else in the script and we let it exist gracefully.
- If not, we have to go hunting! Currently the script uses the Amazon Web Services API to search by Artist and Album to find the first “medium album image” and it downloads it to the server.
- The image is then resized to a max of 75×75 pixels and stored in the cache directory.
Thats just the download part of images too, the process which is ran every time a song of mine changes in Winamp. The front end part of the script simply checks to see if Winamp is actually playing something (by calculating the last track length, when it should have finished, and the time now), then depending on the results of that it will either show the Currently Playing section or not. When shown the script simply checks the cache directory for a corresponding cover art image, then displays it.
Obviously there are some inperfections, but don’t worry - I’m working on them.
This could be one of my first WordPress plugins too!