From ac25d4cdb32edad43e82c9528132b7313b2f6973 Mon Sep 17 00:00:00 2001 From: lionel Date: Wed, 6 Feb 2013 14:07:20 +0100 Subject: [PATCH] Adds release group urls --- README.md | 3 ++- lib/musicbrainz/bindings/release_group.rb | 5 ++++- lib/musicbrainz/models/artist.rb | 2 +- lib/musicbrainz/models/release_group.rb | 3 ++- spec/models/artist_spec.rb | 1 + spec/models/release_group_spec.rb | 1 + 6 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7932ceb..c4ebef1 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,8 @@ MusicBrainz::ReleaseGroup.search(artist_name, title, type: 'Album') :type => String, :title => String, :desc => String, - :first_release_date => Date + :first_release_date => Date, + :urls => Hash } ``` diff --git a/lib/musicbrainz/bindings/release_group.rb b/lib/musicbrainz/bindings/release_group.rb index 9efa9f5..7181d9b 100644 --- a/lib/musicbrainz/bindings/release_group.rb +++ b/lib/musicbrainz/bindings/release_group.rb @@ -8,7 +8,10 @@ module MusicBrainz type: (xml.attribute('type').value rescue nil), title: (xml.xpath('./title').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 diff --git a/lib/musicbrainz/models/artist.rb b/lib/musicbrainz/models/artist.rb index e077d1b..6ada1f4 100644 --- a/lib/musicbrainz/models/artist.rb +++ b/lib/musicbrainz/models/artist.rb @@ -9,7 +9,7 @@ module MusicBrainz field :urls, Hash 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, create_models: :release_group, sort: :first_release_date diff --git a/lib/musicbrainz/models/release_group.rb b/lib/musicbrainz/models/release_group.rb index 2e1e24b..c3a7f8a 100644 --- a/lib/musicbrainz/models/release_group.rb +++ b/lib/musicbrainz/models/release_group.rb @@ -5,6 +5,7 @@ module MusicBrainz field :title, String field :desc, String field :first_release_date, Date + field :urls, Hash alias_method :disambiguation, :desc @@ -18,7 +19,7 @@ module MusicBrainz class << self def find(id) - client.load(:release_group, { id: id }, { + client.load(:release_group, { id: id, inc: [:url_rels] }, { binding: :release_group, create_model: :release_group }) diff --git a/spec/models/artist_spec.rb b/spec/models/artist_spec.rb index 59e31cb..8391ff3 100644 --- a/spec/models/artist_spec.rb +++ b/spec/models/artist_spec.rb @@ -56,5 +56,6 @@ describe MusicBrainz::Artist do release_groups.first.type.should == "Single" release_groups.first.title.should == "Club Foot" 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 diff --git a/spec/models/release_group_spec.rb b/spec/models/release_group_spec.rb index 4656198..fccd221 100644 --- a/spec/models/release_group_spec.rb +++ b/spec/models/release_group_spec.rb @@ -21,6 +21,7 @@ describe MusicBrainz::ReleaseGroup do release_group.type.should == "Album" release_group.title.should == "Empire" 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