Wednesday, October 31, 2007

Linq Me This Nut

The Banshee-to-Windows porting has been more or less done for a while and the code is about to be integrated into trunk. Since the end of the SoC, I've been occupying myself with a tangentially related project. Banshee talks to the MusicBrainz database to get metadata on CDs. Currently it calls into the unmanaged libmusicbrainz library which is both old and no fun. Enter musicbrainz-sharp, my new project to implement a fully managed API for MusicBrainz. It's a very nice OO encapsulation of MusicBrainz's XMLWebService and it's really easy to use:

Artist a = Artist.QuerySingle("The Magnetic Fields");
foreach(Release r in a.Releases)
    Console.WriteLine(r.Title);

Right now it lives in banshee's svn (thanks to Aaron for setting me up with autotools et al). The API is 90% done, the documentation is 90% written, and the unit tests are at about 50% coverage. It's been my intension to create a Linq provider when 3.5 comes out, but for whatever reason the urge overcame me today. I did a quick job which only supports very specific cases, but the following code now works like a charm in Orcas:

var query = from a in MB.Artists
            where a.Name == "Goodshirt"
            select a;

foreach(var artist in query) {
    Console.WriteLine(
artist);
    foreach(var release in artist.Releases) {
        Console.WriteLine("\t{0}", release);
        foreach(var track in release.Tracks)
            Console.WriteLine("\t\t{0}", track);
    }
}


I was muy excited. There's some boilerplate code involved with writing a Linq provider. I hope Microsoft adds some base classes to the API. Linq is balls awesome!

3 comments:

Anonymous said...

Yeah! I'm glad to see some news about Banshee porting.
I'm also working with linq, it's pretty awesome.

Andrew said...

Thanks for the demo; that code is really simple.

David Oxley said...

Awesome!
How can i download the library?