<? // im listening to (last.fm) by alexander <www.astoever.no> // the cache code was stolen from an old audioscrobbler script whose author eludes me (mail for cred).

$lastfmUsername = "astoever"; $lastfmCache = "lastfm.cache"; $secondsBeforeUpdate = 180; // remember to be nice to their link $numberOfSongs = 5; $emptyCache = "Maybe I'm not listening to anything, maybe the server is down. Either way, the local cache is empty."; $wrapperStart = "<ul>"; $wrapperEnd = "</ul>";

// grab the tracks if(!file_exists($lastfmCache)) touch($lastfmCache); $lastModified = filemtime($lastfmCache); if(time() - $lastModified > $secondsBeforeUpdate) { ini_set("default_socket_timeout", 8); $recentlyPlayedSongs = @file_get_contents("http://ws.audioscrobbler.com/1.0/user/$lastfmUsername/recenttracks.txt"); if(strlen($recentlyPlayedSongs) == 1) {

touch($lastfmCache);
} else {
$handle = fopen($lastfmCache, "w"); fwrite($handle, $recentlyPlayedSongs); fclose($handle);
} }

// post them $cacheSize = filesize($lastfmCache); if($cacheSize < 1) echo $emptyCache; else { $recentlyPlayedSongs = file_get_contents($lastfmCache); echo $wrapperStart; $track = explode("\n", $recentlyPlayedSongs); $i = 0; while ($i < $numberOfSongs) {

$trackClean = ereg_replace("(0-9?{10}),", "", $track$i?); echo "<li>$trackClean</li>"; $i++;
} echo $wrapperEnd; } ?>