Location: PHPKode > scripts > Last.fm Mood > test.php

//Path to class

//Define tag and API key here
$tag = 'pop punk';
$key = '';

//Instantiate Lastfm_Mood object, it requires 2 params, tag e.g. Indie, Sad etc. and a Last.fm API key.
$lfm = new Lastfm_Mood($tag,$key);

//Prints the tag set
echo "<p>Tag name: ".$lfm->getTag()."</p>";

//Prints the top artist for specified tag
echo "<p>Artist name: ".$lfm->getArtist()."</p>";

//Prints the top track for the artist generated from getArtist()
echo "<p>Artists top track: ".$lfm->getArtistTrack('single')."</p>";

//Returns an array of top tracks from the artist generated from getArtist()
echo "<p>Artists top tracks: ".$lfm->getArtistTrack('list')."</p>";

//Returns the n'th track from the top tracks
$track = array();
$trackno = 3;
foreach($lfm->getArtistTrack('list') as $t){
    $track[] = $t;
//Will return the 3rd result of the search
echo $track[$trackno];

//Prints a Last.fm formatted URL based on artist and trackname supplied, no validation of if they exist, use with care
echo "<p>Last.fm formatted link: ".$lfm->getLink('Millencolin', 'No Cigar')."</p>";

//Example of the above using the artist and artist track generated
echo "<p>Last.fm formatted link with dynamic content: ".$lfm->getLink($lfm->getArtist(), $lfm->getArtistTrack())."</p>";

//Generates a button, first param is link, second is text displayed
echo "<p>Last.fm 'button': ".$lfm->getButton('http://google.com','Test Text')."</p>";

//Example of above using generated link from the generated artist/trackname, uncomment line.
//WARNING: Slow! Sometimes causes timeout, use with caution.
//echo "<p>Last.fm dynamic 'button': ".$lfm->getButton($lfm->getLink($lfm->getArtist(), $lfm->getArtistTrack('single')), 'Dynamically generated goodness!')."</p>";

Return current item: Last.fm Mood