GithubHelp home page GithubHelp logo

active_musicbrainz's Introduction

ActiveMusicbrainz

ActiveRecord models for the 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'
 => #<ActiveMusicbrainz::Model::Artist id: 24146, gid: "9a709693-b4f8-4da9-8cc1-038c911a61be", name: 143497, sort_name: 143497, begin_date_year: 1976, begin_date_month: 3, begin_date_day: 30, end_date_year: nil, end_date_month: nil, end_date_day: nil, type: 1, area: 221, gender: 1, comment: "UK electro artist Simon Green", edits_pending: 0, last_updated: "2013-05-13 11:00:09", ended: false, begin_area: nil, end_area: nil>

artist.name
 => "Bonobo"

artist.release_groups.first.type
 => #<ActiveMusicbrainz::Model::ReleaseGroupPrimaryType id: 1, name: "Album">

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
 => [#<ActiveMusicbrainz::Model::Medium id: 654199, release: 654199, position: 1, format: 1, name: nil, edits_pending: 0, last_updated: "2012-01-15 13:46:18", track_count: 12>]

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
 => #<ActiveMusicbrainz::Model::MediumFormat id: 1, name: "CD", parent: nil, child_order: 0, year: 1982, has_discids: true>

Author

Andrea Franz - 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

active_musicbrainz's People

Contributors

floriandejonckheere avatar gravityblast avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

active_musicbrainz's Issues

SystemStackError: stack level too deep

When accessing artist#aliases, Ruby throws a stack overflow. I'm not really sure where this comes from, since these issues usually occur in a has_many :through relationship. Removing the :foreign_key options in artist_alias stops the exception from being thrown, at the cost of losing the ArtistAlias โ†’ Artist relation.

2.3.1 :009 > ActiveMusicbrainz::Model::Artist.first.aliases
  ActiveMusicbrainz::Model::Artist Load (52.9ms)  SELECT  "artist".* FROM "artist" ORDER BY "artist"."id" ASC LIMIT $1  [["LIMIT", 1]]
SystemStackError: stack level too deep
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/arel-7.1.1/lib/arel/table.rb:30:in `new'
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/arel-7.1.1/lib/arel/table.rb:30:in `alias'
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/activerecord-5.0.0.1/lib/active_record/table_metadata.rb:50:in `associated_table'
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/activerecord-5.0.0.1/lib/active_record/relation/predicate_builder/association_query_handler.rb:5:in `value_for'
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/activerecord-5.0.0.1/lib/active_record/relation/predicate_builder.rb:45:in `expand'
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/activerecord-5.0.0.1/lib/active_record/relation/predicate_builder.rb:90:in `block in expand_from_hash'
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/activerecord-5.0.0.1/lib/active_record/relation/predicate_builder.rb:86:in `each'
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/activerecord-5.0.0.1/lib/active_record/relation/predicate_builder.rb:86:in `flat_map'
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/activerecord-5.0.0.1/lib/active_record/relation/predicate_builder.rb:86:in `expand_from_hash'
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/activerecord-5.0.0.1/lib/active_record/relation/predicate_builder.rb:31:in `build_from_hash'
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/activerecord-5.0.0.1/lib/active_record/relation/predicate_builder/association_query_handler.rb:27:in `call'
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/activerecord-5.0.0.1/lib/active_record/relation/predicate_builder.rb:76:in `build'
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/activerecord-5.0.0.1/lib/active_record/relation/predicate_builder.rb:46:in `expand'
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/activerecord-5.0.0.1/lib/active_record/relation/predicate_builder.rb:90:in `block in expand_from_hash'
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/activerecord-5.0.0.1/lib/active_record/relation/predicate_builder.rb:86:in `each'
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/activerecord-5.0.0.1/lib/active_record/relation/predicate_builder.rb:86:in `flat_map'
... 9661 levels...
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/activerecord-5.0.0.1/lib/active_record/associations/association.rb:97:in `association_scope'
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/activerecord-5.0.0.1/lib/active_record/associations/association.rb:86:in `scope'
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/activerecord-5.0.0.1/lib/active_record/associations/collection_association.rb:447:in `scope'
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/activerecord-5.0.0.1/lib/active_record/associations/collection_proxy.rb:37:in `initialize'
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/activerecord-5.0.0.1/lib/active_record/relation/delegation.rb:100:in `new'
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/activerecord-5.0.0.1/lib/active_record/relation/delegation.rb:100:in `create'
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/activerecord-5.0.0.1/lib/active_record/associations/collection_association.rb:47:in `reader'
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/activerecord-5.0.0.1/lib/active_record/associations/builder/association.rb:111:in `aliases'
    from (irb):9
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/railties-5.0.0.1/lib/rails/commands/console.rb:65:in `start'
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/railties-5.0.0.1/lib/rails/commands/console_helper.rb:9:in `start'
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:78:in `console'
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
    from /usr/local/rvm/gems/ruby-2.3.1@default/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.