Over the last few weeks I've been working on a Last.fm module for Drupal. I started with some code by an English programmer. I'd hope to polish it up before sharing my modifications with him, but since I see that he's back at work on it I'm posting it here and sending him this message:
I've been playing with your code for a few weeks. Since I see that you are working on it again, I wanted to make my modifications available to you... I had this dream of squashing all the bugs and sharing some pristine code with you, but here's an alpha version so you can see what I've done. If you would like to work together on this, let's talk. Here's the status:
Implemented:
* Use drupal_cache_get/set functions.
** http://www.lullabot.com/articles/a_beginners_guide_to_caching_data
** If there is an error getting lastfm data, and there is data in the cache, update the expiration on the cached data
* Admin option to show timestamps for when the tracks were played
* Admin option to display a last updated timestamp on the block, so we can see how fresh the data is
* Admin option to Override Refresh Interval (Always get Last.fm data.). Maybe this should be removed. My thinking: The admin wants to turn on an option like track timestamps, or change the number of tracks. They want to see the block update immediately - they don't want to wait for the cache to expire. Changing to "no caching" doesn't expire what is currently in the cache...it could, that might be a better way to go...
* drupal_add_js calls lastfm.js test function works.
* drupal_add_css calls lastfm.css
Bugs:
* If click Save Configuration on the admin form you will get a blank page. (This is probably related to the bug in your post above.). Work around: Don't reload the page (this resubmits the form data). Just click in the location bar and hit Enter to get the same URL again. You should see the page and the block should be updated with any changed options.
* Track times: They are probably incorrect for you. I haven't adjusted the timestamps from the XML correctly yet. The "UTS" attribute is seems to be based on the localtime zone of the Last.fm server (USA: EDT). (UTS...? "unix time stamp"???)
** Note I'm not using the textcontext item because in order to do date arithmetic on it, I'd have to use strtotime() and there are bugs that will make the time appear as "12:00". During certain hours. I haven't looked into this. Using the uts attribute, might not be necessary...
Ideas/Plans:
* Data should be updated by cron, not triggered by user page load. At least there should be an admin option to do it that way.
* Find the best way to truncate the artist-trackname to maintain a reasonable width. Right now I'm just truncating the string. A slightly better option is described here: http://www.computing.net/webdevel/wwwboard/forum/1919.html See javascript_truncate_table_POC.html. Ideas welcome.
** onHover show full artist-title
** jquery to make the artist title scroll like the Last.fm widget
** jquery to make cover art popup on mouseover
Installation:
I renamed "lastfm" to "lastfmdev" so that this module could be installed along side your file-based-caching version. Right now I have your file-based block available to all users and this dev block available only to the administrator.
(You'll notice some broken stuff on my site. Style sheets broken in IE. Some images need to be fixed too.)
Hope this work and dreaming is helpful. I'll probably have some time to get back to this on the weekend.
Comments
Attachment removed
See most recent post for latest tarball.
Maybe I'll get to help out
http://townx.org/blog/elliot/progress-drupal-last-fm-module#comment-14245