I love last.fm. I first registered because I wanted to list my recently listened tracks on my website. I found a plugin for WordPress by Marc Hodges which doesn’t seem to work in WordPress 2.2.2. So, I was browsing last.fm forums and I found good-old Recent Tracks-script by astoever. I wasn’t pleased with the original, so I customized it a bit.
(below is the original writing I posted on the forum)
I wanted ”time x ago”-timestamp, so I did one. I’m not good at php but here’s the result:
$trackArray = explode(",", $track[$i]);
$entry = explode("?", $trackArray[1]);
echo "<li class=\"song\"><span class=\"artist\">".$entry[0]."</span><br /><span class=\"title\">".$entry[1]."</li>";
$now = time();
$played = date($trackArray[0]);
$lastplayed = $now - $played;
$minutes = $lastplayed / 60;
$hours = $lastplayed / 3600;
$days = $lastplayed / 86400;
if ($minutes > 60) {
echo "<br /><span class=\"time\">".round($hours, 0)." hours ";
} else {
echo "<br /><span class=\"time\">".round($minutes, 0)." minutes ";
}
if ($hours > 24) {
echo "<br /><span class=\"time\">".round($days, 0)." days ";
}
echo "ago</span></li>";
}
echo $wrapperEnd;
}
?>
(if you want to try, replace this with the end of the code; note ”echo $wrapperEnd; -> replace the original ending with this…)
the Code is yet under construction. I’ll develop it a bit but yet decided to tell this…
Btw what’s the point with question marks between the artist and song (for example ”Dream Theater ? Octavarium”). I split those because I wanted them to be on different lines.
I also have band-artwork but that aint gonna tell you (yet) :)
What do you think?
Seems to work for me, for now.
Working demo (rollemaa.fi/scrobbler-example.php) with temp-stylesheets (rollemaa.fi has been a bit slow recently though). Oh, almost forgot, thanks Nikke for those little tips.

Keskustelu
Ei vielä kommentteja
Kukaan ei ole vielä sanonut mitään. Aloita keskustelu Mastodonissa tai siellä, missä kirjoitus on jaettu.
Osallistu keskusteluun
Keskustelu käydään somessa. Julkiset kommentit Blueskysta, Threadsista ja Mastodonista tuodaan tämän artikkelin kylkeen automaattisesti. Voit vastata kirjoitukseen suoraan omalta Mastodon-tililtäsi tai miltä tahansa fediversumin palvelimelta:
Haku löytää kirjoituksen, ja voit vastata siihen kuten mihin tahansa julkaisuun.
@[email protected]
Kun kirjoitus jaetaan Mastodonissa, Blueskyssa tai Threadsissa, jakoon tulleet vastaukset ja lainaukset kopioituvat tänne viestiketjuineen. Keskustelu näkyy täällä yleensä vartin sisällä.