Audio Scrobbler  

Post Categories   Post Time 3 years, 7 months ago

Another section has been added to the menu on the right, entitled “Aural Pleasures”. I’ve written a script to integrate my site with my latest played songs on Audioscrobbler. Audioscrobbler builds a profile of your musical taste using a plugin for your media player (Winamp, iTunes, XMMS etc..). Plugins send the name of every song you play to the Audioscrobbler server, which updates your musical profile with the new song. Every person with a plugin has their own page on this site which shows their listening statistics. The system automatically matches you to people with a similar music taste, and generates personalised recommendations.

I’m using iTunes, and the plugin provided seems to be working flawlessly at the moment. I’m really impressed with the speed of the system, and the fact that it is so simple to use! If anyone is interested in the script I have written to achieve this, just click to read more, where you will find a copy of the code. Enjoy!


<?php
< ?php
// XML file
$file “http://ws.audioscrobbler.com/rdf/history/dappleyard”;

// set up some variables for use by the parser
$currentTag “”;
$flag “”;

// create parser
$xp xml_parser_create();

// set element handler
xml_set_element_handler($xp“elementBegin”“elementEnd”);
xml_set_character_data_handler($xp“characterData”);
xml_parser_set_option($xpXML_OPTION_CASE_FOLDINGTRUE);

// read XML file
if (!($fp fopen($file“r”))) 
{
      die(
“Could not read $file”);
}

// parse data
while ($xml fread($fp4096)) 
{
    if (!
xml_parse($xp$xmlfeof($fp))) 
    {
  die(
“XML parser error: ” .
xml_error_string(xml_get_error_code($xp)));
    }
}

// destroy parser
xml_parser_free($xp);

// opening tag handler
function elementBegin($parser$name$attributes)
{
    global 
$currentTag$flag;
    
// export the name of the current tag to the global scope
    
$currentTag $name;
    
// if within an item block, set a flag
    
if ($name == “ITEM”)
    {
  
$flag 1;
    }
}

// closing tag handler       
function elementEnd($parser$name)
{
    global 
$currentTag$flag;
    
$currentTag “”;
    
// if exiting an item block, print a line and reset the flag
    
if ($name == “ITEM”)
    {
  echo 
“<br>”;
  
$flag 0;
    }
}

// character data handler
function characterData($parser$data)
{
    global 
$currentTag$flag;
    
// if within an item block, print item data
    
    
if (($currentTag == “LINK”) && $flag == 1)
    {
  echo 
“< <<write ’a' here>> class=”delLink“ href=”$data“>”;
    }
    
    if ((
$currentTag == “DESCRIPTION”) && $flag == 1)
    {
  echo 
“$data”;
    }
}

?>

?>

Post Tags



Leave a Reply