Myspace Gigs Parser
Update: This PHP class that I built has gained a little momentum on the interweb. If anyone has actually used this class on their site and would like to have a link back from us here at DCSHB.com then feel free to email the webmaster for details.
Addendum: If you're mildly famous (or the webmaster for someone who is) and use this PHP class then please consider signing, scanning and emailing the webmaster an 8x10 headshot signed "Dave Coulier Shaves his Balls".
Thousands of bands, musicians, DJs and comedians maintain their concert calendars through their Myspace pages. Unfortunately, Myspace has never offered any form an an API to get access at any of their data. So, that makes people like me come up with creative ways to pull and parse publicly available Myspace pages in order to populate our sites.
Therefore, I have come up with a simple utilitarian PHP class to pull and parse someone's Myspace page. The Myspace Gigs Parser is simple to use, all you need is the simple Myspace URL for the band or comedian you wish to parse, e.g. http://www.myspace.com/bobsaget. You pass the URL to the class and out comes an array of all the Upcoming Gigs.
To test this parser you can try some of the links below or type in the last part of the Myspace URL into the text box in the upper right corner. Try your band's page or try your favorite band.
Examples:
Let's show you a quick example of how to utilize the the PHP Myspace Gigs Parser
$url = "http://www.myspace.com/bobsaget";
$gigs_parser = new Myspace_Gigs_Parser($url);
var_dump($gigs_parser->gigs);
The gigs array will either contain all the gigs parsed off that Myspace page, or bool(false). To utilize, just use a foreach() loop and
foreach($gigs_parser->gigs as $gig){
$time = $gig[0] . ' ' . $gig[1];
echo date('D, j M Y g:iA', strtotime($time));
echo '<br />';
echo $gig[2]; echo '<br />';
echo $gig[3]; echo '<br />';
}
The data comes in an array and these are the following pertinent indexes.
[0] month day year of gig, format: date('M j Y')
[1] time of gig, format: date('g:iA')
[2] venue of gig
[3] city state of gig
That is pretty much all you need to know about how to use the Myspace Gigs Parser. Just keep one thing in mind when utilizing this class, I built it quickly so don't be critical of how I did my parsing. The only thing I regret is that I didn't notice that have a div with the id of "profile_bandschedule". I could have perhaps cut down some of the string searching time by finding that node first and searching from there. The other thing that could be improved is the final algorithm loops through all data nodes and splits them up into batches of four. This could probably be done quicker with some simple math and array_split() but I chose not waste my time any more than I already have.
And now, what you all have been waiting for... the source code:
