<?php
/**
* MySpace ripping proof of concept
*
* @author : Ed Cradock
*/

/*
 * Because of the absolutely abismal page optimization
 * of MySpace, a byte amount must be defined here to
 * not cause too much overhead.
 * 
 * If no matches are found (and the artist exists), 
 * increase this value as MySpace
 * have added more bloat. If still to no avail, then
 * this script won't work as MySpace have altered something.  
*/
define('MAX_BYTES_OFFSET'12025);


/*
 * Set the myspace artist url
*/
$ms_url 'http://www.myspace.com/futurebound';

/**
* Rips apart the XML file and builds an array of title / durl
* for each track
*
* @access public
* @param string $url - The MySpace URL
* @return array  
*/
function getMusic($url)
{
   
$match_pat '#viewPicture&amp;friendID=([0-9]+)#i';
   
$src file_get_contents($urlfalsenull0MAX_BYTES_OFFSET);
   
$songs = array();

   
preg_match($match_pat$src$matches);
   
   if(
$matches[1])
   {
      
$xml = new DOMDocument();
      
$xml->load('http://mediaservices.myspace.com/services/media/musicplayerxml.ashx?b=' $matches[1]);
   
      
$xpath = new DOMXPath($xml);
      
$songNodes $xpath->query('playlist/song');

      
$i 0;
      foreach(
$songNodes as $songNode)
      {
         
$songs[$i]['title'] = $songNode->getAttribute('title');
         
$songs[$i]['url']   = $songNode->getAttribute('durl');

         
$i++;
      }

   }else
      return 
false;

   return 
$songs;
}

/* 
 * Output the links for MP3 and title of track.
*/
$songs getMusic($ms_url);

if(
is_array($songs))
{
   foreach(
$songs as $song)
   {
      
printf("<a href=\"%s\">%s</a><br />\n"$song['url'], $song['title']);
   }
}
else
   echo 
'Failure to extract tracks.';
?>