Drupal Last.fm module - now works with Drupal 5!

Another update: I noticed today that this module had disabled my site. I'm not sure why, but I think it may be because Last.fm wasn't responding. I'm still using it, but if you have it on your site and everything goes bad, it might be because Last.fm isn't available. I manually disabled it in the system table for my Drupal install and my site came back to life, so I know it was this module that caused the problem. I need to do some more debugging before it's suitable for production, so use at your own risk, or exclude the block from the admin page so at least you can disable the module if it causes problems.

Update: I've just updated this slightly, so that the cached track listing is used if your recent tracks from Last.fm is blank. This avoids you getting an empty listing if you haven't been listening to music for a while. I also updated it a second time to prevent errors occurring if you get broken XML back from Last.fm (which happened to me once, and caused my whole site to crash).

I've had a couple of requests for my Last.fm Drupal module, in response to a previous blog post. This was also a good opportunity to learn how to write modules for Drupal 5 and learn the new forms API, which I've now done.

The new version is attached to the bottom of this post. It requires Drupal 5 and PHP 5 with the DOM extension enabled (this is used for parsing the XML feed from Last.fm). It won't check whether the DOM extension is enabled (it's not that clever yet), so it could cause issues (like your site breaking) if you try to install it on a system without PHP 5 and/or the DOM extension.

Install it as a standard module (drop into the modules directory, enable in Administer > Site building > Modules). I've integrated it with the admin. system (under Administer > Site configuration > Last.fm module settings), so you'll need to configure it there before it works. The settings required are:

  • Your Last.fm username.
  • The number of tracks you want to show (1-10).
  • The period for which you want to cache the list (5 minutes to 1 hour), or no caching. The listing is cached in your Drupal root directory (under the filename lastfm_cached.html) for efficiency. In cases where Last.fm doesn't respond quickly enough, you will get an error message (rather than it just leaving your site hanging).

Then turn on the block with the title Recent tracks in the block admin. pages. And away you go! As proof it actually works, see the left-hand side of this site, where it's in action.

AttachmentSize
lastfm.zip2.04 KB

Comments

That rocks

Drupal Last.fm module - now works with Drupal 5 - that is absolute my choice :-)

Great stuff

Love all the chat about Drupal. Big fan, and can't get enough on it.

thanks

Really great work, this module is perfect for me, thanks

drupal6 last.fm module

I have developed last.fm module for drupal 6. Using that i can fetch my playlist from the last.fm. I'll give you the demo first then we will talk about rest.

Re: LastFM

I use LastFM regular and love it very much and now it is also for Drupal available - perfect - great work!

Me again

Ha ha see what I mean, I have just posted a comment about ever one is on about drupal, what the heck I am going to try it now :)

Posthumous title  Have you

Posthumous title
 Have you heard Diana's posthumous title?
Princess of Walls. Gucci Silver

Thanks for the update! Need

Thanks for the update!

Need to register a UK company?
www.accounting-on-line.com

Nice post

A lot of people are interested in a last.fm module. So I think it's a good idea to host your work on drupal.org. It will be easier for people to find it and watch the evolution of the project. If you already posted it on drupal.org, please send me the link.
Thanks and keep up the good work!

I only came across Drupal

I only came across Drupal recently because I was getting frustrated with some of the limitations with Wordpress. It's great to see that Drupal is so well supported.

... compatible to Drupal 6?

Meanwhile Drupal 6 is out - is last.fm compatible to Drupal 6?

That's a good question. I

That's a good question. I always run into compatibility issues, but then again I don't spend as much time with my Drupal site as I need to.

Thanks for the Update!

This is a great update for Drupal, I just started reading materials about it and is going to try this weekend, will keep you posted.

thanks for sharing!

Drupal 6.0?

Now that Drupal 6.0 is out, will this module work with that? I'm semi-new to Drupal, and started out with 6.0. Thanks.

Action Movie

So cute! Keep up the good work!

you try using drupal 6

you try using drupal 6 instead of drupal 5..you will notice that it has more features and you will see that the work is done more easily and accurately. Anyways a very good blog.Thanks

Now that Drupal 6 is out,

Now that Drupal 6 is out, does last.fm work as good with it ?

Last.fm & Drupal 6

Unfortunately, no it doesn't. I've been playing around with it since I started using Last.fm recently (clearly I'm a very late adopter!) and I can't make it work.

I have to be honest Stan,

I have to be honest Stan, and say I haven't done any work on the Last.fm module for a long time. I handed to project over to another developer, who was intending to put it up on the main Drupal website as a standard module. So I'm afraid I can't answer your question. My guess is it would need some work to get it going with Drupal 6.

Drupal 6 info?

Does anybody have any information whatsoever about Last.fm module for Drupal 6. I really need this and was unable to find any info on it. If you know anything, please post.

This module might work with

This module might work with Drupal 6, but I've never updated it to, or even tested it.

It works for me

It works for me

new version

hi elliot

those detailed instructions were perfect for me

i have come across those same problems described above

my module was disabled, and presto i reverted it back , i appreciate your assistance

what would we do without you

Glad it was useful.

Glad it was useful.

Thanks!

I am new to Drupal and trying to learn more so any help is a good addition to the knowledge.Great article.Your efforts are highly appreciated.Thanks for posting.

Excellent info - love

Excellent info - love last.fm! Thanks for sharing this.

Same here! I've found so

Same here! I've found so many new bands via last.fm, and I've rediscovered many of my old favorites who have their catalog on the site. Its a great site to help pass the day.

Last.fm on drupal.org

If you would you like any assistance with managing this module on drupal.org , please
let me know.

Best, Paul

Hi Paul. I've effectively

Hi Paul. I've effectively handed this over to Jeff Eaton, who was talking about putting it up on drupal.org. I don't have much time to develop on it any more. You might be able to get in touch with Jeff via his blog at http://jeff.viapositiva.net/. Cheers.

Last.fm and Tabbo module

Hi,

I've just finished a Last.fm and Tabbo module for Drupal 6... I don't know how much yours exactly works (don't have a working D5 installation around and your demo is either turned off or malfunctioning), but it seems to be similar (one difference is that mine also supports Tabbo.

P.S. You need some sort of anti-spam measures. Captcha + reCAPTCHA modules have been working fine for me (one site got literally thousands of spam comments. I deleted them all and installed those two modules - not even one bastard got through).

Don't I know I need those

Don't I know I need those modules.

I turned off the Last.fm module, just because it made my site crash if Last.fm timed out, unless I hacked in some changes to the Drupal HTTP client code. Which I didn't fancy maintaining. Glad to hear you've done some work on a new module for it. Good luck with it!

Problem with multisite?

Hey there,

Very cool module - thanks for taking the time to work on it. I've only tried it on a multisite install so far and am getting an error:

Parse error: syntax error, unexpected T_OBJECT_OPERATOR in .../sites/default/modules/lastfm/lastfm.module on line 176

I realize this is a very early release, so it's not that big a deal, but should I be getting this error? I tried moving it to sites/domain.com/modules and got the same error. I have not tried it in a single Drupal install yet. Thanks!

Hello Arp. Are you using PHP

Hello Arp. Are you using PHP 4? I developed on PHP 5 and haven't tested on PHP 4 as I never use it. I get the feeling it might be due to that. In PHP 4, you can't chain together method invocations on objects, as this module does on the line where the error occurs. If you can, try running it under PHP 5 and see whether the problem goes away. I need to do some work to make it PHP 4 compatible, as I believe Drupal 5 still supports that PHP version.

Sponsorship and/or Development Help

Hi Elliot. We've got a client that is interested in doing Last.fm/Drupal integration on their site. They would probably sponsor a bunch of fixes/features for this module. So if you're looking for help/money for developing the modules (and perhaps not having it crash your site!), please contact me and I can give you more details.

Submitting to drupal.org?

Have you considered putting this into CVS on drupal.org? It's a module that quite a few others have mentioned a need for, and I'm pretty sure some other folks would be able to pitch in with patches for things like multi-user support. It could take advantage of drupal's built in caching system pretty easily, too... (http://www.lullabot.com/articles/a_beginners_guide_to_caching_data)...

Hi Jeff. I think that's a

Hi Jeff. I think that's a good idea, and I'd definitely be willing to do it. Only thing is I've got quite a bit on at the moment, so may not get round to it for a week or so. Any tips on the best place to start when thinking about contributing to Drupal?

The caching idea is also a great one. Looks like I could easily use that instead of my hokey caching to the filesystem. Thanks for the reference and the clear article.

Is it possible to have it for each user??

Basically, I want everyone that signs in to have the option to enter their last.FM username and have their feed display in their homepage AND in their user's page. Is this possible?

I imagine this is possible,

I imagine this is possible, but it's not something I need or have attempted yet. If you have patches, I'd be happy to incorporate them.

where is the code

you said:
"he new version is attached to the bottom of this post. "

I don't see it.

It's here. It only shows up

It's here. It only shows up in the full view of the post.

Thanks

Thanks a lot.

You're welcome, Artur.

You're welcome, Artur.