<? // 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) {
// 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) {
} echo $wrapperEnd; } ?>