<?php /* * Copyright 2007 Gordon Lowery <info@gldes.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
$username = "gordol";//lastfm username $cache = "lastfm.cache";//lastfm cache file $update = 120;//cache update interval in seconds $songs = 5;//how many songs to display (10 is the max) $timeout = 3;//how long to wait before timing out $empty = "<li>Nothing.</li>"; $start = "<ul>"; $end = "</ul>";
if(!file_exists($cache)) touch($cache); $modified = filemtime($cache); if(time() - $modified > $update) { @ini_set("default_socket_timeout", $timeout); $recent = @file_get_contents("http://ws.audioscrobbler.com/1.0/user/$username/recenttracks.txt"); if(strlen($recent) == 1) { touch($cache); } else { $handle = fopen($cache, "w"); fwrite($handle, $recent); fclose($handle); } } $size = filesize($cache); if($size < 5) echo $empty; else { $recent = file_get_contents($cache); //$recent = utf8_decode($recent); echo $start; $info = explode("\n", $recent); for ($i = 0; $i < $songs; $i++) { $array = explode(",", $info[$i]); $date = date("D M j, g:i a", $array[0]); $subarray = explode("–", $array[1]); $track = $subarray[1]; $artist = $subarray[0]; echo "<li><strong>".$track." by ".$artist."</strong> <br/> <em> ".$date."</em></li>"; } echo $end; } ?>
|