2013-11-06 02:15:09 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2012-10-12 12:45:51 +00:00
|
|
|
module MusicBrainz
|
2013-01-20 12:36:52 +00:00
|
|
|
class Artist < BaseModel
|
2012-10-12 12:45:51 +00:00
|
|
|
field :id, String
|
|
|
|
field :type, String
|
|
|
|
field :name, String
|
|
|
|
field :country, String
|
2013-01-20 12:36:52 +00:00
|
|
|
field :date_begin, Date
|
|
|
|
field :date_end, Date
|
2012-10-12 12:45:51 +00:00
|
|
|
field :urls, Hash
|
|
|
|
|
|
|
|
def release_groups
|
2013-02-06 13:07:20 +00:00
|
|
|
@release_groups ||= client.load(:release_group, { artist: id, inc: [:url_rels] }, {
|
2013-01-20 12:36:52 +00:00
|
|
|
binding: :artist_release_groups,
|
|
|
|
create_models: :release_group,
|
2012-10-12 12:45:51 +00:00
|
|
|
sort: :first_release_date
|
|
|
|
}) unless @id.nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
class << self
|
|
|
|
def find(id)
|
2013-01-20 12:36:52 +00:00
|
|
|
client.load(:artist, { id: id, inc: [:url_rels] }, {
|
|
|
|
binding: :artist,
|
|
|
|
create_model: :artist
|
2012-10-12 12:45:51 +00:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
def search(name)
|
2013-05-05 23:14:44 +00:00
|
|
|
super({artist: name})
|
2012-10-12 12:45:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def discography(mbid)
|
|
|
|
artist = find(mbid)
|
|
|
|
artist.release_groups.each { |rg| rg.releases.each { |r| r.tracks } }
|
|
|
|
artist
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_by_name(name)
|
|
|
|
matches = search(name)
|
2013-11-06 21:37:31 +00:00
|
|
|
if matches and not matches.empty?
|
|
|
|
find(matches.first[:id])
|
|
|
|
end
|
2012-10-12 12:45:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|