1
0
Fork 0

Merge remote-tracking branch 'danbee/feature/find-release-by-discid' into feature/find-release-by-discid

This commit is contained in:
Jason Voegele 2015-03-13 15:58:04 -04:00
commit 33e280ec2c
4 changed files with 30 additions and 1 deletions

View File

@ -24,6 +24,7 @@ require "musicbrainz/models/track"
require "musicbrainz/bindings/artist" require "musicbrainz/bindings/artist"
require "musicbrainz/bindings/artist_search" require "musicbrainz/bindings/artist_search"
require "musicbrainz/bindings/artist_release_groups" require "musicbrainz/bindings/artist_release_groups"
require "musicbrainz/bindings/discid_releases"
require "musicbrainz/bindings/relations" require "musicbrainz/bindings/relations"
require "musicbrainz/bindings/release_group" require "musicbrainz/bindings/release_group"
require "musicbrainz/bindings/release_group_search" require "musicbrainz/bindings/release_group_search"

View File

@ -0,0 +1,13 @@
module MusicBrainz
module Bindings
module DiscidReleases
def parse(xml)
xml.xpath('./disc/release-list/release').map do |xml|
MusicBrainz::Bindings::Release.parse(xml)
end
end
extend self
end
end
end

View File

@ -10,7 +10,7 @@ module MusicBrainz
field :asin, String field :asin, String
field :barcode, String field :barcode, String
field :quality, String field :quality, String
def tracks def tracks
@tracks ||= client.load(:release, { id: id, inc: [:recordings, :media], limit: 100 }, { @tracks ||= client.load(:release, { id: id, inc: [:recordings, :media], limit: 100 }, {
binding: :release_tracks, binding: :release_tracks,
@ -26,6 +26,13 @@ module MusicBrainz
create_model: :release create_model: :release
}) })
end end
def find_by_discid(id)
client.load(:discid, { id: id }, {
binding: :discid_releases,
create_models: :release
})
end
end end
end end
end end

View File

@ -35,4 +35,12 @@ describe MusicBrainz::Release do
expect(tracks.first.title).to eq "Empire" expect(tracks.first.title).to eq "Empire"
expect(tracks.first.length).to eq 233013 expect(tracks.first.length).to eq 233013
end end
it "gets a list of matching releases for a discid" do
releases = MusicBrainz::Release.find_by_discid("pmzhT6ZlFiwSRCdVwV0eqire5_Y-")
releases.length.should == 2
releases.first.id.should == "7a31cd5f-6a57-4fca-a731-c521df1d3b78"
releases.first.title.should == "Kveikur"
releases.first.asin.should == "B00C1GBOU6"
end
end end