Last.fm tool: Generate your recommended artists tag cloud
';
printMessages( "recommend" );
echo 'p>The following script takes the 50 top artists in your musical profile
from
Last.fm, and creates a cloud of the
similar artists that are not in your top 50. The result is a "tag cloud"
like description of highly recommended artists.
Please be patient, the script may require up to a full minute to
process your request. The script needs to download and analyze your profile
and your top 50 artists. Last.fm policy states that we can only make 1
request per second, and the script\'s worst case scenario requires 51
requests. Caching is used to lower the load on user (cache = 10 minutes) and
artist (cache = 1 week) database requests.
Also, make sure to check out my scripts to generate your personal musical tag cloud and compare your profile with that of other users.
';
if( !$type )
$type = "overall";
if( $user ) {
// get user's top artists
$userfilename = "./users/" . $user . ".xml";
$userurl = "http://ws.audioscrobbler.com/1.0/user/$user/topartists.xml";
$xmlroot = "topartists";
if( $type == "12months" ) {
$userurl .= "?type=12month";
$userfilename .= ".12month";
}
if( $type == "6months" ) {
$userurl .= "?type=6month";
$userfilename .= ".6month";
}
if( $type == "3months" ) {
$userurl .= "?type=3month";
$userfilename .= ".3month";
}
if( $type == "weekly" ) {
$userfilename = "./weeklyusers/" . $user . ".xml";
$userurl = "http://ws.audioscrobbler.com/1.0/user/$user/weeklyartistchart.xml";
$xmlroot = "weeklyartistchart";
}
$userdata = getDataFrom( $userfilename, $userurl, 10*60 );
$data = XML_unserialize( $userdata );
// for each of the artists, analyze its top similar artists
$similarartists;
$topartists;
$artisturls;
$nrartists = 0;
if( $data[ $xmlroot ] )
if( $data[ $xmlroot ]['artist']['0'] )
foreach( $data[ $xmlroot ]['artist'] as $artist ) {
if( $nrartists < 50 ) {
$nrartists++;
$name = substr(strrchr($artist['url'], "/"), 1);
$playcount = $artist['playcount'];
// print( $name . " -> " . $playcount . "" );
$topartists[ $artist['name'] ] = $playcount;
$artisturls[ $artist['name'] ] = $artist['url'];
$artistfilename = "./similarartists/" . substr( $name, 0, 100 ) . ".xml";
$artisturl = "http://ws.audioscrobbler.com/1.0/artist/$name/similar.xml";
$artistdata = getDataFrom( $artistfilename, $artisturl );
$data = XML_unserialize( $artistdata );
$similarcount = 0;
if( $data['similarartists'] )
if( $data['similarartists']['artist'] )
if( count( $data['similarartists']['artist'] ) > 1 )
foreach( $data['similarartists']['artist'] as $similarartist ) {
$similarcount++;
$tagname = $similarartist['name'];
$similarartists[ $tagname ] += $similarartist['match']*$playcount;
$artisturls[ $tagname ] = $similarartist['url'];
}
if( $similarcount <= 0 )
$nrartists--;
}
}
arsort( $similarartists );
$max = 0;
$count = 0;
foreach( $similarartists as $similarartist => $value ) {
if( $count < 50 ) {
if( $topartists[ $similarartist ] > 0 )
$similarartists[ $similarartist ] = 0;
else {
if( $value > $max )
$max = $value;
$cloudartists[ $similarartist ] = round( $value * 28 / $max );
$count++;
}
}
}
ksort( $cloudartists );
echo "
Recommended artists cloud for $user
";
echo "
The following is a textual cloud representation of recommended artists for $user. These artists are similar to your overall top artists, but are not in this list. Most of them will ring a bell, some will not be relevant, you may listen to some of them if they're not in your top, but there's probably a couple of artists you'll want to hear more from.
";
echo '
'."\n";
foreach( $cloudartists as $artist => $size ) {
if( $size > 4 ) {
$artist_unicode = unicode_to_entities( utf8_to_unicode( $artist ) );
$artist_url = $artisturls[ $artist ];
echo " $artist_unicode \n";
}
}
echo ' |
'."\n";
echo "
BBCode!
";
echo "
The following BBCode can easily be copied to Last.fm forums, journals, ... (be warned, it contains a lot of artist connections)
";
echo '
'."\n";
echo " Take the 50 top artists in your musical profile, and create a cloud of the similar artists that are not in your top 50. The result is a collection of highly recommended artists for your personal profile. You can generate your own cloud (in BBCode) at http://anthony.liekens.net/pub/scripts/last.fm/recommend.php
\n\nMy recommendations are \n\n[b][align=center]";
foreach( $cloudartists as $similarartist => $value ) {
$artist_unicode = unicode_to_entities( utf8_to_unicode( $similarartist ) );
$size = round( $value * 2 / 3 );
if( $size > 4 )
if( $size > 12 ) {
echo "[size=$size] [artist]" . $artist_unicode . "[/artist] [/size]";
} else {
echo "[size=$size] " . $artist_unicode . " [/size]";
}
$numberartists++;
}
echo "[/align][/b] ";
echo ' |
'."\n";
printLinks( $user, "recommend" );
}
echo '