An open API service indexing awesome lists of open source software.

https://github.com/gravityblast/active_musicbrainz

Ruby ActiveRecord models for the MusicBrainz database.
https://github.com/gravityblast/active_musicbrainz

Last synced: about 1 year ago
JSON representation

Ruby ActiveRecord models for the MusicBrainz database.

Awesome Lists containing this project

README

          

# ActiveMusicbrainz

ActiveRecord models for the [MusicBrainz](http://musicbrainz.org/) [database](http://musicbrainz.org/doc/MusicBrainz_Database).

## Installation

Add this line to your application's Gemfile:

gem 'active_musicbrainz'

And then execute:

$ bundle

Or install it yourself as:

$ gem install active_musicbrainz

## Usage

Require ActiveMusicbrainz and initialize the database **(if you are inside a rails app, you can skip the following lines)**:

require 'active_musicbrainz'
ActiveRecord::Base.establish_connection(YAML.load_file('path/to/config.yml'))

Some models are hardcoded, others are dynamically generated based on existing tables. You can initialize all those models with the following line:

ActiveMusicbrainz.init

The *init* method should be called after establishing a database connection since the library needs to read all the database tables.
If you are inside a rails project you could put the code above in **config/initializers/active_musicbrainz.rb**.

If you want to establish a different database connection for the ActiveMusicbrainz tables you can call the establish_connection method on ActiveMusicbrainz::Module::Base instead of ActiveRecord::Base:

ActiveMusicbrainz::Model::Base.establish_connection(YAML.load_file('path/to/config.yml'))

Now under the ActiveMusicbrainz::Model module, you have one model for each MusicBrainz table.
Here some examples:

artist = ActiveMusicbrainz::Model::Artist.by_gid '9a709693-b4f8-4da9-8cc1-038c911a61be'
=> #

artist.name
=> "Bonobo"

artist.release_groups.first.type
=> #

artist.release_groups.each{|r| puts r.name }
Black Sands
Dial 'M' for Monkey
Scuba EP
Flutter
Pick Up
Terrapin
Eyesdown
...

artist.release_groups.first.releases.first.mediums
=> [#]

artist.release_groups.first.releases.first.mediums.first.tracks.each{|t| puts t.name}
Prelude
Kiara
Kong
Eyesdown
...

artist.release_groups.first.releases.first.mediums.first.format
=> #

## Author

Andrea Franz - [http://gravityblast.com](http://gravityblast.com)

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request