Curl, MusicBrainz and PHP

A quick block of PHP to fetch MusicBrainz ID for a song and artist based on Song Data.

As part of the New Years Resolutions I didn’t make.

I’m updating my blog with some Code Snippets!

Been fiddling about with my PHP powered Jukebox that plays out on LSRfm.com (Leeds Student Radio) Overnight, and there is a need for a bulk track adder.

So, I’ve been tidying up the MusicBrainz Data Fetcher, as well as fiddling with PHP and getting ID3 tags from Files. But thats a different blog post.

Essentially there is a (new-ish non updated recently) PHP Library for the interaction with MusicBrainz, (A music database), recently found that (this morning its rubbish), but of no good.

So went back to my curl method.

Tidyied it up and got it down to a few less lines.

Essentially for a given track, the PHP extracts the ID3 tags, and then passes it to this function: (its needs making into a function btw :-P)

$curl = new curl();

$data = array(
	'title'		=> 'Showdown',
	'artist'	=> 'Pendulum',
	'release'	=> 'In Silico',
	'duration'	=> 327784,
//	'tracknumber'	=> 0,
//	'count'		=> 10,
//	'releasetype'	=> '',

	'limit'		=> 25,
	'limit'		=> 1,
);
$target = 'http://musicbrainz.org/ws/1/track/?type=xml';
foreach ($data as $ref => $dat) {
	$target .= '&' . $ref . '=' . urlencode($dat);
}

                                $curl->target($target);
                                $curl->runit();
                                $mb = $curl->bodyarray['metadata'];

if (isset($mb['track-list'])) {
	$mb = $mb['track-list'];

	if (isset($mb['track']['0'])) {
		$mb = $mb['track'];
		$artist_id = $mb['0']['artist_attr']['id'];
		$song_id = $mb['0_attr']['id'];
	} else {
		$artist_id = $mb['track']['artist_attr']['id'];
		$song_id = $mb['track_attr']['id'];
	}
} else {
	// no data
}

echo "\n" . $artist_id . ' ' . $song_id;

Where new curl() just calls my Curl Class.

I’m sure you have your own ways of doing curl, but mine just sets the target with $curl->target and curlexec() with $curl->runit.

The result is in $curl->body, or exploded nicely as an array in $curl->bodyarray. I’ll post about my curl later! As well as some other Carlyon_CMS stuff.

So thats a quick rough and ready way to get a artist and song ID from MusicBraiz.

Its worth noting that since my limit is st to 1.

The first option of if (isset($mb[‘track’][‘0’]) is entirely redundant, as that only triggers when mb returns more than 1 result.

(I only just added limit before writing this post, which is where I decided to write this post)

The MusicBrainz Docs for its XML service is at: http://musicbrainz.org/doc/XML_Web_Service If your Interested!

Life Since the last Post

Yes, I’m still rubbish at updating my blog regularrly.

Yes, I’m rubbish at updating my blog.

So its the new year and suppose I should keep up with it.

In recent news I am no longer single, I go out with the Wonderful Kayleigh.

I’m currently sat at my temporary desk in Stage @ Leeds, (just finished painting a Door Blue and waiting for it to finish drying)

LSRfm.com – Leeds Student Radio is ticking over.

Just did a massive 19 hour shift over New Years for Wax:On over at LUU, quite good fun, running the lights in the Terrace again, didn’t blow up the rig this time which is always a bonus, last time I blew a Atomic 3000, and it tripped the whole rig out….. We think its a manufacturing fault.

So coming soon, back to degree!

Which means 360gaming [dot] net is gonna get some work done to it finally…. Its my project for my degree, bonus!

Tho I should really get on with Data Mining’s essay and my Critical Thinking Essay, total of 6000 words to write by the 14th.

Off to meet the guys from Muze.tv for SRA Chart stuff this weekend.

AND I ORDERED A MAC!

I have a 17″ on its way to me!

So stay tuned for new Mac goodness! As well as regular updatage!

Summer of Code is on, Horace Andy is off and You Do Talk About Barcamp

EPIC REVIEW OF THE WEEK

So I have finally recovered from the epic weekend that was Fruity, Tidy, and Slamdunk as well as Slam Dunk prep. when not working.

In the end Arrived at work at 11am Saturday (Tidy day) and left 3am Monday (after Slamdunk after Party), an epic Weekend.

Throughly enjoyed some of the music as well, I was running lights using Chamsys (MagicQ) on the Vans Stage, aka The Riley Smith Hall, no drinks of any kind thank you!

Best thing about my MagicQ was the remote desktop into the PC, running lights off my phone and netbook was good fun.

So The Slackers and King Blues were enjoyed, but AntiFlag were far too policitical (I now know what a Circle Pit is too).

 

So Today is day 4 of Google Summer of Code, so far done nothing for it. I lost Monday to sleeping (eventually out of bed by 5pm) Tuesday was clear the theatre day, Wednesday was getting office back in order, and today is Thursday, supposed to be doing the Horace Andy gig, lighting wise, however its been Cancelled.

 

So that takes us to, what am I going to do today, and Friday. Lets plan Summer of Code work, I’m working for GeekLog on a Syndication API, details to follow.

 

That then takes us to the Weekend, which is BarCamp Leeds 2009, part of Leeds Web Festival 2009. Should be good fun, at least is was last time, last years BarCamp let me discover geekery in Leeds, which has led to loads of new friends. And lots of werewolf playing.

 

So look out for lots and lots of Twittering this weekend on that.

 

Also I jsut remembered its my Boss’es leaving do on Friday so off to Grease Fruity, its  going to be EPIC!

And the Fruity dancers are coming as Pink Ladies too.

 

Right to GSoC Planning

Two Drums and a Cymbal Fall off a Cliff

When Two Drums and a Cymbal Fall off a Cliff do they make a RimShot sound? Tom Scott York Pirate found out http://www.tomscott.com/cliff/

iPhone Shoutcast App.

Just a quick post to say,

OMG its the Shoutcast iPhone Application!

http://blog.shoutcast.com/2009/01/09/announcing-the-shoutcast-radio-app-for-iphone-and-ipod-touch/

Shoutcast and LSR on the iPhone
Shoutcast and LSR on the iPhone

You have to turn on Hi-Bit streams in settings tho to listen to LSRfm.com, it wouild appear out low quality stream is not in the index…..