Kuuntelin $lastfmUsername = "j0hnni"; $lastfmCache = ".cache"; $secondsBeforeUpdate = 180; $numberOfSongs = 1; // max10 $socketTimeout = 3; $emptyCache = "Cache tyhjä!"; if(!file_exists($lastfmCache)) touch($lastfmCache); $lastModified = filemtime($lastfmCache); if(time() - $lastModified > $secondsBeforeUpdate) { @ini_set("default_socket_timeout", $socketTimeout); $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); } } $cacheSize = filesize($lastfmCache); if($cacheSize < 5) echo $emptyCache; else { $recentlyPlayedSongs = file_get_contents($lastfmCache); $recentlyPlayedSongs = utf8_decode($recentlyPlayedSongs); // UTF8 h8 $track = explode("\n", $recentlyPlayedSongs); for ($i = 0; $i < $numberOfSongs; $i++) { $trackArray = explode(",", $track[$i]); $timestamp = date('j.n.Y, H:i:s :',$trackArray[0]); echo "".$timestamp." ".$trackArray[1].""; } } ?>
/** @.pre Linkkejä |
|---|
| * Muut kuvat |
| * irssistats |
| * Tuotesalkku (Alko) |
| * Sukellusloki |
| * Portfolio |
*/ |
(c) Joona "johnny" Lehikoinen ^_^