Jump to content

Problem Displaying Recent Last.fm Plays


pealo86

Recommended Posts

I'm using the following script on my website, it used to work fine but now it just outputs 'error' from the else statement:

 

<?php
	$username = 'pealo86';
	$scrobbler_url = "http://ws.audioscrobbler.com/2.0/user/" . $username . "/recenttracks";
	 
	$scrobbler_cache_file = 'scrobbler_' . $username . '_data.cache';
	 
	if (file_exists($scrobbler_cache_file)) {
	  if (time() - filemtime($scrobbler_cache_file) > 180) {
	    // if the file was created more than 3 minutes ago then delete.
	    unlink($scrobbler_cache_file);
	  } else {
	    $scrobbler_url = realpath('./' . $scrobbler_cache_file);
	  }
	}
	 
	if ($scrobbler_xml = file_get_contents($scrobbler_url)) {
	    $scrobbler_data = simplexml_load_string($scrobbler_xml);
	 
	  if (!file_exists($scrobbler_cache_file)) {
	    file_put_contents($scrobbler_cache_file, $scrobbler_xml);
	  }
	  
	  // limit to 3 songs
	  $count = 0;
	  echo '<ul id="feed-lastfm">';
	  foreach ($scrobbler_data->track as $track) {
	      if ($count == 3) {
		      break;
		  } else {
			  $string = '<li>';
			  $string .= '<div class="cover">';
			  if ($track->image[1] != '') {
				  $string .= '<a href="' . $track->url . '"><img src="' . $track->image[1] . '" alt="' . $track->album . '" /></a>';
			  }
			  $string .= '</div>';
			  $string .= '<div class="content">';
			  $string .= '<span class="title"><a href="' . $track->url . '"><strong>' . $track->artist . '</strong>: ' . $track->name . '</a></span>';
			  if (!$track->date) {
				  $date = '<span class="highlight-00a2f5 currently-listening">Currently Listening</span>';
			  } else {
				  $date = 'Played: ' .$track->date;
			  }
			  $string .= '<span class="date">' . $date . '</span>';
			  $string .= '</div>';
			  $string .= '</li>';
			  echo $string;
			  $count ++;
		  }
	  }
	  echo '</ul>';
	} else {
	
	echo 'error';
	}
?>

I got the script from here:

- http://www.hashbangcode.com/blog/simple-php-code-get-lastfm-last-played-tracks-605.html

 

Does anyone have any idea what I'm missing?

Link to comment
https://forums.phpfreaks.com/topic/275024-problem-displaying-recent-lastfm-plays/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.