1
0
Fork 0

Adds release group urls

This commit is contained in:
lionel 2013-02-06 14:07:20 +01:00
parent be1743f836
commit ac25d4cdb3
6 changed files with 11 additions and 4 deletions

View File

@ -93,7 +93,8 @@ MusicBrainz::ReleaseGroup.search(artist_name, title, type: 'Album')
:type => String, :type => String,
:title => String, :title => String,
:desc => String, :desc => String,
:first_release_date => Date :first_release_date => Date,
:urls => Hash
} }
``` ```

View File

@ -8,7 +8,10 @@ module MusicBrainz
type: (xml.attribute('type').value rescue nil), type: (xml.attribute('type').value rescue nil),
title: (xml.xpath('./title').text rescue nil), title: (xml.xpath('./title').text rescue nil),
desc: (xml.xpath('./disambiguation').text rescue nil), desc: (xml.xpath('./disambiguation').text rescue nil),
first_release_date: (xml.xpath('./first-release-date').text rescue nil) first_release_date: (xml.xpath('./first-release-date').text rescue nil),
urls: (Hash[xml.xpath('./relation-list[@target-type="url"]/relation').map{ |xml|
[xml.attribute('type').value.downcase.split(" ").join("_").to_sym, xml.xpath('./target').text]
}] rescue {})
} }
end end

View File

@ -9,7 +9,7 @@ module MusicBrainz
field :urls, Hash field :urls, Hash
def release_groups def release_groups
@release_groups ||= client.load(:release_group, { artist: id }, { @release_groups ||= client.load(:release_group, { artist: id, inc: [:url_rels] }, {
binding: :artist_release_groups, binding: :artist_release_groups,
create_models: :release_group, create_models: :release_group,
sort: :first_release_date sort: :first_release_date

View File

@ -5,6 +5,7 @@ module MusicBrainz
field :title, String field :title, String
field :desc, String field :desc, String
field :first_release_date, Date field :first_release_date, Date
field :urls, Hash
alias_method :disambiguation, :desc alias_method :disambiguation, :desc
@ -18,7 +19,7 @@ module MusicBrainz
class << self class << self
def find(id) def find(id)
client.load(:release_group, { id: id }, { client.load(:release_group, { id: id, inc: [:url_rels] }, {
binding: :release_group, binding: :release_group,
create_model: :release_group create_model: :release_group
}) })

View File

@ -56,5 +56,6 @@ describe MusicBrainz::Artist do
release_groups.first.type.should == "Single" release_groups.first.type.should == "Single"
release_groups.first.title.should == "Club Foot" release_groups.first.title.should == "Club Foot"
release_groups.first.first_release_date.should == Date.new(2004, 5, 10) release_groups.first.first_release_date.should == Date.new(2004, 5, 10)
release_groups.first.urls[:discogs].should == 'http://www.discogs.com/master/125150'
end end
end end

View File

@ -21,6 +21,7 @@ describe MusicBrainz::ReleaseGroup do
release_group.type.should == "Album" release_group.type.should == "Album"
release_group.title.should == "Empire" release_group.title.should == "Empire"
release_group.first_release_date.should == Date.new(2006, 8, 28) release_group.first_release_date.should == Date.new(2006, 8, 28)
release_group.urls[:wikipedia].should == 'http://en.wikipedia.org/wiki/Empire_(Kasabian_album)'
end end
end end