1
0
Fork 0

Added artist urls

This commit is contained in:
magnolia-fan 2011-09-20 19:47:45 +04:00
parent 2d77333856
commit 4c820dee83
1 changed files with 6 additions and 2 deletions

View File

@ -1,6 +1,6 @@
module MusicBrainz
class Artist
attr_accessor :id, :type, :name, :country, :date_begin, :date_end
attr_accessor :id, :type, :name, :country, :date_begin, :date_end, :urls
@release_groups
def release_groups
@ -16,7 +16,7 @@ module MusicBrainz
end
def self.find mbid
res = MusicBrainz.load('http://musicbrainz.org/ws/2/artist/' + mbid)
res = MusicBrainz.load('http://musicbrainz.org/ws/2/artist/' + mbid + '?inc=url-rels')
return nil if res.nil?
@artist = self.parse_xml(Nokogiri::XML(res))
end
@ -29,6 +29,10 @@ module MusicBrainz
@artist.country = xml.css('artist > country').text unless xml.css('artist > country').empty?
@artist.date_begin = xml.css('artist > life-span > begin').text unless xml.css('artist > life-span > begin').empty?
@artist.date_end = xml.css('artist > life-span > end').text unless xml.css('artist > life-span > end').empty?
@artist.urls = {}
xml.css('relation-list[target-type="url"] > relation').each do |rel|
@artist.urls[rel.attr('type').downcase.split(' ').join('_').to_sym] = rel.css('target').text
end
@artist
end