Last.fm Recent Album Artwork Plugin
My blog is now running a WordPress plugin that shows the album covers from Last.fm of songs I've recently listened to. There's a lot of plugins out there, but none that I found that did the job of getting the artwork, and certainly not for the most recent albums.
Download the Last.fm recent album artwork plugin
Last.fm Integration
You'll need a Last.fm account and the iScrobbler running to store the recent tracks at Last.fm. To check, you can view the recent tracks feed changing remysharp to your Last.fm username.
Installing
Download the Last.fm recent album artwork plugin and save it in your plugins directory (usually located in wp-content).
Then activate the plugin from the Plugins tab in your WordPress admin tools.
Setup
Through the Options -> Last.fm Recent Albums tab fill out the required fields.
Album Art Cache Settings
You must ensure the directory that you point the plugin to is writable. You can use either full or relative paths for the album artwork.
For example, my album artwork is located at http://remysharp.com/albums/, so my URL is set to:
/albums/
Within my WordPress set up, this is physically located in /home/remy/remysharp.com/htdocs/albums/, but I've set the path to be relative in the settings, so it reads:
albums/
Since the root of my WordPress installation is /home/remy/remysharp.com/htdocs/ this works just fine.
Adding to your Blog
Once the setup is complete, use the get_lastFM_album_artwork() function to add the album artwork to you blog. My blog adds the code as follows (with the setup wrapping the elements with li)
<?php if (function_exists('get_lastFM_album_artwork')) { ?>
<div class="lastfm">
<h3>Recent Albums</h3>
<ul>
<?php
get_lastFM_album_artwork();
?>
</ul>
</div>
<?php } ?>
Behind the Scenes
Behind the scenes the code will only show album artwork if Last.fm have the album associated (there's a number of tracks that don't have that information linked). If there's not enough recent tracks from the feed, the plugin will fill the rest of the albums based on the recently played albums (using timestamps from the artwork files).
The plugin will also avoid showing the same album cover twice.
Problems?
If you have any problems or suggestions or questions about the plugin, please let me know and I'll do my best to help.
Update: I've fixed a small bug where the album art wouldn't load if the album title had a question mark in it.
Hey, any chance that you could get the plugin to show track information as well as the album art? I have yet to see a plugin that does both, I want to show track names and artists along with the album art, like this: http://daleanthony.com/sample.jpg
What do you think?
Cheers.
Dale.
@Dale - sure. If you give me a little while I reckon I should be able to upgrade the plugin to allow you to specify how you want the HTML outputted - i.e. something like:
Then it can be styled appropriately. I'll drop an update on this post when it's ready.
Wow! quick response. That's fantastic, thanks a lot
I tried to install the plugin on Wordpress 2.2.2, but without success. There is an fatal error when I try to activate the plugin. Can you give me a hint what could be wrong?
@Matt - can you find the error from your apache logs? I'm running 2.2 - but I can't imagine it 2.2.2 has many differences. If you can send me the sample I'll try to fix the bug.
Unfortunately I don't have access to log files.
But I know now what parts of the code are causing the
problems.
If I comment out 2 to try statements (lines 39-48 and 133-152) as well as the nodevalue function (line 116-118) I can at least activate the plugin.
When I remove the comments again and open the options form I get the following errors:
Parse error: syntax error, unexpected '{' in /mnt/web1/31/72/5168672/htdocs/blog/wp-content/plugins/lastfmalbumsartwork.php on line 39
Parse error: syntax error, unexpected TOBJECTOPERATOR in /mnt/web1/31/72/5168672/htdocs/blog/wp-content/plugins/lastfmalbumsartwork.php on line 117
Parse error: syntax error, unexpected '{' in /mnt/web1/31/72/5168672/htdocs/blog/wp-content/plugins/lastfmalbumsartwork.php on line 133
Hope this helps a bit to nail the bug.
@Matt - I think I know what's causing the problem. You're using PHP 4 aren't you? I've used try/catch statements in the plugin - but checking the documentation, that's only supported by PHP 5.
Can you double check this for me. If that's the case, I'll have to look at making it cross compatible (i.e. to work with PHP 4 + 5).
Hi Remy,
your assumption is correct.
I switched from PHP4 to PHP5 and the errors were gone.
Hey, how are the new features coming along? Just thought I would ask... I have just started to code my new blog layout
When is the next update coming out? The plugin worked fine on the dev server but the main server is php4 and the plugin will not activate... fatal error
@Dale - I've uploaded a new version that supports specifying your own format as discussed.
@Jared - I've modified the plugin to try to detect which version of PHP is running and use the appropriate DOM parser. I don't have an active copy of PHP4 so I've not been able to run any tests. Could you let me know how you get on with the latest version?
Wohoo... Thanks a lot..
It's all working great, I am having a problem getting it to work with my stylesheet though ( http://www.daleanthony.com/blog/ )
@Dale - I've just fixed that now. If you download, you should find version 1.0.2 fixed the slashes appearing in the class attribute.
Oh - and if you want a decent twitter plugin - I've got one
Perfect, works great.
Thanks again!
@Remy - I just downloaded the newest version you released and tried to activate it, still gave me a fatal error =(
I'm going to see if my error logs give me any clues. Right now I am stuck using a different last.fm plugin but it is not near as good as yours!
Yeah I just checked, my host is running PHP Version 4.4.7.
@Jared - I'm in the process of re-writing the plugin so that it will support PHP4 (I've tweaked my apache so I can run both) and PHP5 - but unfortunately (for me) isn't a quick, straight forward job.
I hope to have it ready within the next few days. Check back here and I'll post when it's ready.
If you're already using this plugin - please visit the official Wordpress plugin page and give it a rating - cheers.
Any chance that you could make this plugin into a sidebar widget?
Is there any possibility that this plugin could be made into a single embeddable script? just so that I could paste the code into an html file and still work fine...
just recently switched to wordpress (from serendipity)... so I have to add code in wordpress templates in order to get plugins visible?
@Gareth - I'm not sure about sidebar widgets, I'll have a look.
@Kimatg - you should be able to easily convert the plugin in to a standalone. There are two lines at the end, one commented out and one not - just switch around the comments like so:
Then in the
get_lastFM_album_artworkfunction, there's a block where my test variables are - uncomment it, and comment out the code below up to the// code startscomment. That should be it.@Mike - That's right - you need to insert the code as per the "Adding to your Blog" in the post above.
Would love the PHP4 version, I get the error too.
Many thanks.
Hi there!!
First of all, thanks for this great plugin!!
I have a problem
I'm trying to run it as standalone, I had made a:
and in ur .php file I had uncommented ur test variables, and write mines, ofc commented the next get_option lines.
Also in the file's bottom I had commented add_action and uncomment the next line, but I recive this error msg:
and its impossible to remove!!! I had tried to put a die; in the first line and the error still appears!
158 line contais:
of the funcition nodeValue but I still have the error commenting it or putting a return true;
I don't know what I can do!!
Greets from Spain
Hey, Me again
I just started getting this message on my wordpress, can't even get into my admin panel.
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /home/daleanth/public_html/blog/wp-content/plugins/lastfm_albums_artwork.php on line 158
I don't think I have changes any files recently so not to sure what is causing this.
@Dale + @ Ignacio - are you using php 4 or php 5?
PHP5, I tried also to remove manually some parts of PHP4 code but I failed also
Its more hard that I thought to run it at standalone
Is there any way to make the album art image act as the url as well? without displaying the written url?
aha, I'm most likely using php4 - that's my question answered!
Any updates on how the new version is coming?
Hi,
great plugin. Does anyone knows why the first letters are missing? It would be great if it also fetches the album year ...
Check http://www.gamito.net/blog.
Now i realized that tracks are missing too.
My code is:
$artwork
$artist($year) $album$track
Thanks.
[...] Visit [...]
Woohoo!! This plugin looks HOT! I've seen the other Last.FM plugins that have the ability to include a timestamp of when the track was played. This one comes to mind:
http://wordpress.org/extend/plugins/lastfm-for-wordpress/
Would it be possible to include that? Thanks!!
[...] WP官方下载页面 | 插件作者下载页面 [...]
Hey again,
How often is this plugin setup to refresh the data? I have listened to a ton of songs today and it hasn't updated my recently played this evening.
Is there an option anywhere to change the frequency of the updates?
@Dale - the update happens each time the page is requested. Once the page is called, and the function called (i.e. from your sidebar), it will pull the RSS feed from last.fm.
Sometimes their feed goes down, or doesn't update - so you might be seeing this.
On the other hand, the plugin is designed not to show the same album artwork twice, so it depends on the songs you've listened too.
Finally, there's logic so say, only display albums that have enough details to get the artwork and album name. Sometimes last.fm don't have all the details, so those albums are skipped over.
I'd recommend checking the feed and seeing what you've got there first. Cheers.
Hi,
I'm using PHP4 as well, and was just wondering how the cross compatible version was coming along? I would love to get this working on my blog!
Alex
I'm trying to install your plugin to my sidebar. I've changed my username in the PHP file, set up iScrobbler, and And inserted the code into my sidebar but I keep getting and erroe which reads:
Album path must exist and be read/write permissions ()
What should i do?
-JB
@JB - the 'Album Art Cache' directory needs to have write permissions as done like this (assuming the same directories as the post above):
Hi,
Great plugin, just what I was looking for. However, I've followed your instructions and I'm getting the following error:
#
I know this looks like a file permissions error but I've done a chmod on the newly created directory:
/home/users/website.co.uk/lastfm/
It is currently set to 777. I'm also running PHP 5 and Wordpress 2.3 (latest at the time of writing).
Any ideas what could be wrong?
Cheers
Ok, I've sorted the above problem. It was my own stupid mistake of not pointing the full path to the right directory
However, now there are no errors at all but it also isn't displaying any items. I've checked my xml feed and there are items there being updated as I listen but they just aren't showing up on my blog.
I have the following html format:
$artwork
$artist
$track
I am having the same problem as Dale in comment #25. Trying to activate the plug-in. Dunno re: php4 or 5.
I'm still having the same problem with the title being displayed but not artwork or album information at all - just white space.
I've set the following parameters:
URL: http://website.co.uk/lastfm/
Full Path: /home/users/website.co.uk/lastfm/
The above directory I've done and chmod on to 777 and checked this a million times. I've entered in my correct lastfm account details and double checked this but I still get nothing.
What's going wrong?
This plugin looks great, but I'm stuck with php4 and can't use it, I keep getting an error
Hi,
I'm still having the same problems I noted earlier this month with regard to this plugin. Can you suggest how I may resolve them? The plugin page on Wordpress says to come here to get problems resolved. I'd just really like to get it working.
Thanks
Hi there,
any news on sorting the following error....
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /home/daleanth/public_html/blog/wp-content/plugins/lastfm_albums_artwork.php on line 158
I have php 4.4.7 installed on my server
pleeasee help
stu
I installed the plugin and followed the instructions, but now the plugin is not displaying anything. I probably just missed a little detail. The path for the URL is: http://www.jasoncypret.com/lastfmArt/
Full path: lastfmArt/
The folder has been created and is set to 777.
-JC
It's working now. Now I just gotta figure out why the URL's are going to a 404 page.
Thanks, it's a great plugin!
-JC
[...] Plugin Homepage [...]
[...] Last.FM Recent Albums and Artwork - Displays my most recently played albums from Last.FM with album artwork covers in a highly customizable fashion. Caches them on the site to decrease loading time from image sources. [...]
Many thanks, great plugin, works great with wordpress 2.5 and latest K2 aswell!!
TIP: if anyone has hosting with both php4 AND php5, but default on php4, you can put "SetEnv DEFAULT_PHP_VERSION 5" in an .htaccess file in your root and it will default to PHP5.
Hi!
Thanks for your great plugin, it really rocks! Just one thing: I've figured out that $url now has to be ..blabla..artist/_/track and NOT artist/album/track.
After changing it in the code everything works like a charm! Congrats.
Hi!
My goodness, I don't understand. I give up...
I installed the plugin and followed the instructions with tchmod on to 777 but "Album path must exist and be read/write permissions (/home/gwen-gwen/www.bloguenotes.com/album/)" Arrgh !!!
What's going wrong? Full path?!?
By advance, thanks
[...] Last.fm Recent Albums and Artwork by Remy Sharp [...]
[...] Last.fm Recent Albums and Artwork by Remy Sharp [...]