This is really old. last.fm changed their interface, and this script no longer works. I am keeping it up for historic reasons, so people can apply the basic idea of the script to other problems.
Its been over a month since last.fm released their new full track player. All in all I am very impressed. As a linux user fighting iTunes and Rhapsody consumed most of my listening time. Since last.fm uses a simple flash player there is no need to use a virtual machine or remove a DRM or re-encode. So far last.fm is working fine, except in one area. You have to click on each track individually to play it. You can't click on an album and just have it play one track after the other. After a couple of hours playing with greasemonkey and firebug I wrote a very simple greasemonkey script to play the next track in a playlist after the last one ends. It works great!
Here is the script.
// ==UserScript==
// @name last.fm Loop Playlist
// @namespace all
// @description Plays all the songs in a last.fm album/playlist with out having to manually press play after each song
// @include *last.fm/*
// ==/UserScript==
// Find the player
var player = document.getElementById('lfmPlayer');
// If there is a player then lets set it up to loop the songs.
if (player) {
// override the onFlashPlayerNextTrackHighlight function that is called after each track finishes playing :)
// This is all the same code in the main.js script except the last line
unsafeWindow.onFlashPlayerNextTrackHighlight = function() {
if (unsafeWindow.currentTrack!=undefined) {
unsafeWindow.currentTrack.onend();
}
if (unsafeWindow.currentTrackNum == undefined) {
unsafeWindow.currentTrackNum = 1;
} else {
if (unsafeWindow.currentTrack!=undefined) {
var a = unsafeWindow.currentTrackNum;
a = a + 1;
unsafeWindow.currentTrackNum = a;
}
}
if (unsafeWindow.currentTrackNum > unsafeWindow.Lastfm.resources.length) {
unsafeWindow.currentTrackNum = 1;
}
unsafeWindow.currentTrack = unsafeWindow.getCurrentTrack();
if (unsafeWindow.currentTrack!=undefined) {
unsafeWindow.currentTrack.onstart();
}
// start next track after 2000ms. This prevents the track from getting logged in your chart twice.
setTimeout(playnexttrack,2000);
};
}
function playnexttrack() {
unsafeWindow.playPreview(unsafeWindow.currentTrackNum);
}
To use the Greasemonkey script you need to download and install Firefox. Then install the Firefox Greasemonkey plugin(clcik on this when using Firefox). Once Greasemonkey is installed download and install the last.fm script. If everything works correctly when you download the last.fm script Greasemonkey will spawn a dialog and ask you if you really want to install the script(click okay).
| Attachment | Size |
|---|---|
| lastfmplayall.user.js | 1.5 KB |
This script is great, makes
This script is great, makes the full length track feature much better.
But I've been having a problem where all the tracks I play from an album are submitted twice, I'm not sure why.
Any ideas?
Keep up the good work
tracks submitted twice
Hey baby-g,
I am glad that your are enjoying my script. Its good to know that it is useful to someone other than my self.
I have been playing with the script and the way that last.fm's javascript/flash player work. I added a timeout function which starts the track after 2 seconds which prevents the track from being submitted twice. I have uploaded the new code.
Enjoy...
--Adam R. Bates
last.fm
Hi Adam
Downloaded the script
not having any luck the script does not appear to work.
Iam using firefox 3.05 and I gave the latest greasemonkey plugin
any ideas?
rtctmt