RBrainz - Musicbrainz API for Ruby !


Today I've decided to test a simple API for Ruby, so I look for something in the Rubyforge.I found the Rbrainz, how the title describe, a MusicBrainz API, I really don't know what was MusicBrainz, I only know that amarok use it. I search about this in the Wikipedia. It's a music library, well I love music and Ruby, so I start to program with it. Now let's see a small tutorial:

First, download the API in the official website(http://rbrainz.rubyforge.org/) or using the gems:

gem install rbrainz

Starting our script, read the comments:

_________________________________________________________________

#/usr/bin/env ruby

require 'rubygems'

require 'rbrainz'

include MusicBrainz

#we required the dependencies

artists_includes = Webservice::ArtistIncludes.new(

 :aliases=>true,

 :releases=>['Album', Official'],

 :artist_rels=>true,

 :release_rels=>true,

 :track_rels=>true,

 :label_rels=>true,

 :url_rels=>true,

#We created a Hash with informations

query = Webservice::Query.new
id = '
ba853904-ae25-4ebb-89d6-c44cfbd71bd2'
artista = query.get_artist_by_id(id, artist_includes)

#Variables for describe the webservice(query), the artist ID, you can see the information searching in the musicbrainz's website and we put the object called artist the id and the hash called artist_includes.

#Now we will print the informations

print <     <     eof

ID number(número de id):#{artista.id.uuid}

Name(nome):#{artista.name}

Begin date(data de início):#{artista.begin_date}

End date(data do fim):#{artista.end_date}

Aliases(participantes):#{artista.aliases.to_a.join('; ')}

Releases(Álbuns):#{artista.releases.to_a.join('; ')}

EOF

_________________________________________________________________

End of the script, now see the output:

ID : ba853904-ae25-4ebb-89d6-c44cfbd71bd2
Name : Blur
Begin date : 1989
End date : 
Aliases : Albarn James Coxon Rowntree
Releases : Modern Life Is Rubbish; Modern Life Is Rubbish; Leisure; Leisure; Modern Life Is Rubbish; Modern Life Is Rubbish; Parklife; Parklife; Leisure; The Great Escape; The Great Escape; The Great Escape; Blur; Blur; 13; 13; Think Tank; Think Tank

Yes, ba853904-ae25-4ebb-89d6-c44cfbd71bd2is the Blur's ID

I take the ID here: http://musicbrainz.org/show/artist/details.html?artistid=361

0 comentários: