<?php
/***********************
**
** copyright (c) 2005 Joe Shamah
** mailto: joe at mrsomeone dot com
**
**
** string audioScrobbler ( string username [, int limit [, string format ]] )
**
** username is your audioscrobbler username and optional limit is the max
** number of songs to fetch. - default is 1.
** optional format can format the text using variables. - where {name} is the name
** and {num} is the number.
** if no format is specified, each song name will be printed with a <br /> after it.
**
** questions/comments email or PM on audioscrobbler.com (username: MrSomeone)
**
***********************/
function audioScrobbler( $user, $num = 1, $format )
{
if (empty($user)) die( "<tt>Syntax: audioScrobbler(\"<b>username</b>\")</tt>" );
$num = intval( $num - 1 );
$format = (!$format) ? '' : $format;
$as = @file_get_contents( "http://ws.audioscrobbler.com/txt/recent/" . $user );
if (!$as)
{
print "Error getting song info.";
exit;
}
$line = explode( "\n", $as );
$j = 0;
$t = 0;
while ($j <= $num)
{
if( $t % 2 != 0 )
{
if ( !empty($line[$t]) )
$played[$j] = $line[$t];
$j++;
}
$t++;
}
$n = 1;
foreach( $played as $str )
{
if ( empty( $format ) )
{
print $str . "<br />";
}
else
{
$_str = $format;
$_str = str_replace( "{name}", $str, $_str );
$_str = str_replace( "{num}", $n, $_str );
print $_str;
}
$n++;
}
}
// example:
audioScrobbler( "MrSomeone", 5, "<b>{num}.</b> {name}<br />");
?>