musicbrainz 0.7.3 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -1
- data/lib/musicbrainz.rb +1 -0
- data/lib/musicbrainz/bindings/release.rb +5 -1
- data/lib/musicbrainz/bindings/release_group_search.rb +20 -0
- data/lib/musicbrainz/models/base_model.rb +9 -5
- data/lib/musicbrainz/models/release.rb +6 -2
- data/lib/musicbrainz/models/release_group.rb +18 -1
- data/lib/musicbrainz/version.rb +1 -1
- data/spec/bindings/release_group_search_spec.rb +17 -0
- data/spec/models/base_model_spec.rb +45 -0
- data/spec/models/release_group_spec.rb +56 -24
- data/spec/models/release_spec.rb +9 -5
- metadata +7 -2
data/README.md
CHANGED
@@ -80,6 +80,9 @@ MusicBrainz::ReleaseGroup
|
|
80
80
|
```ruby
|
81
81
|
# Class Methods
|
82
82
|
MusicBrainz::ReleaseGroup.find(id)
|
83
|
+
MusicBrainz::ReleaseGroup.find_by_artist_and_title(artist_name, title, type: 'Album')
|
84
|
+
MusicBrainz::ReleaseGroup.search(artist_name, title)
|
85
|
+
MusicBrainz::ReleaseGroup.search(artist_name, title, type: 'Album')
|
83
86
|
|
84
87
|
# Instance Methods
|
85
88
|
@release_group.releases
|
@@ -105,11 +108,15 @@ MusicBrainz::Release.find(id)
|
|
105
108
|
# Fields
|
106
109
|
{
|
107
110
|
:id => String,
|
111
|
+
:type => String,
|
108
112
|
:title => String,
|
109
113
|
:status => String,
|
110
114
|
:format => String,
|
111
115
|
:date => Date,
|
112
|
-
:country => String
|
116
|
+
:country => String,
|
117
|
+
:asin => String,
|
118
|
+
:barcode => String,
|
119
|
+
:quality => String
|
113
120
|
}
|
114
121
|
```
|
115
122
|
|
data/lib/musicbrainz.rb
CHANGED
@@ -24,6 +24,7 @@ require "musicbrainz/bindings/artist"
|
|
24
24
|
require "musicbrainz/bindings/artist_search"
|
25
25
|
require "musicbrainz/bindings/artist_release_groups"
|
26
26
|
require "musicbrainz/bindings/release_group"
|
27
|
+
require "musicbrainz/bindings/release_group_search"
|
27
28
|
require "musicbrainz/bindings/release_group_releases"
|
28
29
|
require "musicbrainz/bindings/release"
|
29
30
|
require "musicbrainz/bindings/release_tracks"
|
@@ -6,10 +6,14 @@ module MusicBrainz
|
|
6
6
|
|
7
7
|
hash = {
|
8
8
|
id: (xml.attribute('id').value rescue nil),
|
9
|
+
type: (xml.xpath('./release-group').attribute('type').value rescue nil),
|
9
10
|
title: (xml.xpath('./title').text rescue nil),
|
10
11
|
status: (xml.xpath('./status').text rescue nil),
|
11
12
|
country: (xml.xpath('./country').text rescue nil),
|
12
|
-
date: (xml.xpath('./date').text rescue nil)
|
13
|
+
date: (xml.xpath('./date').text rescue nil),
|
14
|
+
asin: (xml.xpath('./asin').text rescue nil),
|
15
|
+
barcode: (xml.xpath('./barcode').text rescue nil),
|
16
|
+
quality: (xml.xpath('./quality').text rescue nil)
|
13
17
|
}
|
14
18
|
|
15
19
|
formats = (xml.xpath('./medium-list/medium/format') rescue []).map(&:text)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module MusicBrainz
|
3
|
+
module Bindings
|
4
|
+
module ReleaseGroupSearch
|
5
|
+
def parse(xml)
|
6
|
+
xml.xpath('./release-group-list/release-group').map do |xml|
|
7
|
+
{
|
8
|
+
id: (xml.attribute('id').value rescue nil),
|
9
|
+
mbid: (xml.attribute('id').value rescue nil), # Old shit
|
10
|
+
title: (xml.xpath('./title').text.gsub(/[`’]/, "'") rescue nil),
|
11
|
+
type: (xml.attribute('type').value rescue nil),
|
12
|
+
score: (xml.attribute('score').value.to_i rescue nil)
|
13
|
+
} rescue nil
|
14
|
+
end.delete_if{ |item| item.nil? }
|
15
|
+
end
|
16
|
+
|
17
|
+
extend self
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -46,14 +46,18 @@ module MusicBrainz
|
|
46
46
|
elsif type == String
|
47
47
|
val.to_s
|
48
48
|
elsif type == Date
|
49
|
-
if val.nil? or val == ""
|
50
|
-
|
49
|
+
val = if val.nil? or val == ""
|
50
|
+
[2030, 12, 31]
|
51
51
|
elsif val.split("-").length == 1
|
52
|
-
val
|
52
|
+
[val.split("-").first.to_i, 12, 31]
|
53
53
|
elsif val.split("-").length == 2
|
54
|
-
val
|
54
|
+
val = val.split("-").map(&:to_i)
|
55
|
+
[val.first, val.last, -1]
|
56
|
+
else
|
57
|
+
val.split("-").map(&:to_i)
|
55
58
|
end
|
56
|
-
|
59
|
+
|
60
|
+
Date.new(*val)
|
57
61
|
else
|
58
62
|
val
|
59
63
|
end
|
@@ -1,12 +1,16 @@
|
|
1
1
|
module MusicBrainz
|
2
2
|
class Release < BaseModel
|
3
3
|
field :id, String
|
4
|
+
field :type, String
|
4
5
|
field :title, String
|
5
6
|
field :status, String
|
6
7
|
field :format, String
|
7
8
|
field :date, Date
|
8
9
|
field :country, String
|
9
|
-
|
10
|
+
field :asin, String
|
11
|
+
field :barcode, String
|
12
|
+
field :quality, String
|
13
|
+
|
10
14
|
def tracks
|
11
15
|
@tracks ||= client.load(:release, { id: id, inc: [:recordings, :media], limit: 100 }, {
|
12
16
|
binding: :release_tracks,
|
@@ -17,7 +21,7 @@ module MusicBrainz
|
|
17
21
|
|
18
22
|
class << self
|
19
23
|
def find(id)
|
20
|
-
client.load(:release, { id: id, inc: [:media] }, {
|
24
|
+
client.load(:release, { id: id, inc: [:media, :release_groups] }, {
|
21
25
|
binding: :release,
|
22
26
|
create_model: :release
|
23
27
|
})
|
@@ -9,7 +9,7 @@ module MusicBrainz
|
|
9
9
|
alias_method :disambiguation, :desc
|
10
10
|
|
11
11
|
def releases
|
12
|
-
@releases ||= client.load(:release, { release_group: id, inc: [:media], limit: 100 }, {
|
12
|
+
@releases ||= client.load(:release, { release_group: id, inc: [:media, :release_groups], limit: 100 }, {
|
13
13
|
binding: :release_group_releases,
|
14
14
|
create_models: :release,
|
15
15
|
sort: :date
|
@@ -23,6 +23,23 @@ module MusicBrainz
|
|
23
23
|
create_model: :release_group
|
24
24
|
})
|
25
25
|
end
|
26
|
+
|
27
|
+
def search(artist_name, title, options = {})
|
28
|
+
artist_name = CGI.escape(artist_name).gsub(/\!/, '\!')
|
29
|
+
title = CGI.escape(title).gsub(/\!/, '\!')
|
30
|
+
query = ["artist:\"#{artist_name}\"", "releasegroup:\"#{title}\""]
|
31
|
+
query << "type: #{options[:type]}" if options[:type]
|
32
|
+
|
33
|
+
client.load(
|
34
|
+
:release_group, { query: query.join(' AND '), limit: 10 },
|
35
|
+
{ binding: :release_group_search }
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
def find_by_artist_and_title(artist_name, title, options = {})
|
40
|
+
matches = search(artist_name, title, options)
|
41
|
+
matches.empty? ? nil : find(matches.first[:id])
|
42
|
+
end
|
26
43
|
end
|
27
44
|
end
|
28
45
|
end
|
data/lib/musicbrainz/version.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe MusicBrainz::Bindings::ReleaseGroupSearch do
|
6
|
+
describe '.parse' do
|
7
|
+
it "gets correct release group data" do
|
8
|
+
response = '<release-group-list><release-group id="246bc928-2dc8-35ba-80ee-7a0079de1632" type="Single" ext:score="100"><title>Empire</title></release-group>'
|
9
|
+
described_class.parse(Nokogiri::XML.parse(response)).should == [
|
10
|
+
{
|
11
|
+
id: '246bc928-2dc8-35ba-80ee-7a0079de1632', mbid: '246bc928-2dc8-35ba-80ee-7a0079de1632',
|
12
|
+
title: 'Empire', type: 'Single', score: 100
|
13
|
+
}
|
14
|
+
]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe MusicBrainz::BaseModel do
|
6
|
+
describe '#validate_type' do
|
7
|
+
describe 'Date' do
|
8
|
+
context 'nil value' do
|
9
|
+
it 'returns 2030-12-31' do
|
10
|
+
response = '<release-group><first-release-date></first-release-date></release-group>'
|
11
|
+
xml = Nokogiri::XML.parse(response)
|
12
|
+
release_group = MusicBrainz::ReleaseGroup.new MusicBrainz::Bindings::ReleaseGroup.parse(xml)
|
13
|
+
release_group.first_release_date.should == Date.new(2030, 12, 31)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'year only' do
|
18
|
+
it 'returns 1995-12-31' do
|
19
|
+
response = '<release-group><first-release-date>1995</first-release-date></release-group>'
|
20
|
+
xml = Nokogiri::XML.parse(response)
|
21
|
+
release_group = MusicBrainz::ReleaseGroup.new MusicBrainz::Bindings::ReleaseGroup.parse(xml)
|
22
|
+
release_group.first_release_date.should == Date.new(1995, 12, 31)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'year and month only' do
|
27
|
+
it 'returns 1995-04-30' do
|
28
|
+
response = '<release-group><first-release-date>1995-04</first-release-date></release-group>'
|
29
|
+
xml = Nokogiri::XML.parse(response)
|
30
|
+
release_group = MusicBrainz::ReleaseGroup.new MusicBrainz::Bindings::ReleaseGroup.parse(xml)
|
31
|
+
release_group.first_release_date.should == Date.new(1995, 4, 30)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'year, month and day' do
|
36
|
+
it 'returns 1995-04-30' do
|
37
|
+
response = '<release-group><first-release-date>1995-04-30</first-release-date></release-group>'
|
38
|
+
xml = Nokogiri::XML.parse(response)
|
39
|
+
release_group = MusicBrainz::ReleaseGroup.new MusicBrainz::Bindings::ReleaseGroup.parse(xml)
|
40
|
+
release_group.first_release_date.should == Date.new(1995, 4, 30)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -3,32 +3,64 @@
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
5
|
describe MusicBrainz::ReleaseGroup do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
describe '.find' do
|
7
|
+
it "gets no exception while loading release group info" do
|
8
|
+
lambda {
|
9
|
+
MusicBrainz::ReleaseGroup.find("6f33e0f0-cde2-38f9-9aee-2c60af8d1a61")
|
10
|
+
}.should_not raise_error(Exception)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "gets correct instance" do
|
14
|
+
release_group = MusicBrainz::ReleaseGroup.find("6f33e0f0-cde2-38f9-9aee-2c60af8d1a61")
|
15
|
+
release_group.should be_an_instance_of(MusicBrainz::ReleaseGroup)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "gets correct release group data" do
|
19
|
+
release_group = MusicBrainz::ReleaseGroup.find("6f33e0f0-cde2-38f9-9aee-2c60af8d1a61")
|
20
|
+
release_group.id.should == "6f33e0f0-cde2-38f9-9aee-2c60af8d1a61"
|
21
|
+
release_group.type.should == "Album"
|
22
|
+
release_group.title.should == "Empire"
|
23
|
+
release_group.first_release_date.should == Date.new(2006, 8, 28)
|
24
|
+
end
|
10
25
|
end
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
26
|
+
|
27
|
+
describe '.search' do
|
28
|
+
context 'without type filter' do
|
29
|
+
it "searches release group by artist name and title" do
|
30
|
+
matches = MusicBrainz::ReleaseGroup.search('Kasabian', 'Empire')
|
31
|
+
matches.length.should be > 0
|
32
|
+
matches.first[:title].should == 'Empire'
|
33
|
+
matches.first[:type].should == 'Single'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'with type filter' do
|
38
|
+
it "searches release group by artist name and title" do
|
39
|
+
matches = MusicBrainz::ReleaseGroup.search('Kasabian', 'Empire', type: 'Album')
|
40
|
+
matches.length.should be > 0
|
41
|
+
matches.first[:title].should == 'Empire'
|
42
|
+
matches.first[:type].should == 'Album'
|
43
|
+
end
|
44
|
+
end
|
15
45
|
end
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
release_group.first_release_date.should == Date.new(2006, 8, 28)
|
46
|
+
|
47
|
+
describe '.find_by_artist_and_title' do
|
48
|
+
it "gets first release group by artist name and title" do
|
49
|
+
release_group = MusicBrainz::ReleaseGroup.find_by_artist_and_title('Kasabian', 'Empire')
|
50
|
+
release_group.id.should == '246bc928-2dc8-35ba-80ee-7a0079de1632'
|
51
|
+
end
|
23
52
|
end
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
53
|
+
|
54
|
+
describe '#releases' do
|
55
|
+
it "gets correct release group's releases" do
|
56
|
+
releases = MusicBrainz::ReleaseGroup.find("6f33e0f0-cde2-38f9-9aee-2c60af8d1a61").releases
|
57
|
+
releases.length.should be >= 5
|
58
|
+
releases.first.id.should == "2225dd4c-ae9a-403b-8ea0-9e05014c778f"
|
59
|
+
releases.first.status.should == "Official"
|
60
|
+
releases.first.title.should == "Empire"
|
61
|
+
releases.first.date.should == Date.new(2006, 8, 28)
|
62
|
+
releases.first.country.should == "GB"
|
63
|
+
releases.first.type.should == "Album"
|
64
|
+
end
|
33
65
|
end
|
34
66
|
end
|
data/spec/models/release_spec.rb
CHANGED
@@ -15,12 +15,16 @@ describe MusicBrainz::Release do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it "gets correct release data" do
|
18
|
-
release = MusicBrainz::Release.find("
|
19
|
-
release.id.should == "
|
20
|
-
release.title.should == "
|
18
|
+
release = MusicBrainz::Release.find("b94cb547-cf7a-4357-894c-53c3bf33b093")
|
19
|
+
release.id.should == "b94cb547-cf7a-4357-894c-53c3bf33b093"
|
20
|
+
release.title.should == "Humanoid"
|
21
21
|
release.status.should == "Official"
|
22
|
-
release.date.should == Date.new(
|
23
|
-
release.country.should == "
|
22
|
+
release.date.should == Date.new(2009, 10, 6)
|
23
|
+
release.country.should == "US"
|
24
|
+
release.asin.should == 'B002NOYX6I'
|
25
|
+
release.barcode.should == '602527197692'
|
26
|
+
release.quality.should == 'normal'
|
27
|
+
release.type.should == 'Album'
|
24
28
|
end
|
25
29
|
|
26
30
|
it "gets correct release tracks" do
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: musicbrainz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.7.
|
5
|
+
version: 0.7.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Gregory Eremin
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- lib/musicbrainz/bindings/release.rb
|
98
98
|
- lib/musicbrainz/bindings/release_group.rb
|
99
99
|
- lib/musicbrainz/bindings/release_group_releases.rb
|
100
|
+
- lib/musicbrainz/bindings/release_group_search.rb
|
100
101
|
- lib/musicbrainz/bindings/release_tracks.rb
|
101
102
|
- lib/musicbrainz/bindings/track.rb
|
102
103
|
- lib/musicbrainz/client.rb
|
@@ -113,12 +114,14 @@ files:
|
|
113
114
|
- lib/musicbrainz/models/track.rb
|
114
115
|
- lib/musicbrainz/version.rb
|
115
116
|
- musicbrainz.gemspec
|
117
|
+
- spec/bindings/release_group_search_spec.rb
|
116
118
|
- spec/bindings/release_spec.rb
|
117
119
|
- spec/client_modules/cache_spec.rb
|
118
120
|
- spec/deprecated/cache_config_spec.rb
|
119
121
|
- spec/deprecated/proxy_config_spec.rb
|
120
122
|
- spec/fixtures/kasabian.xml
|
121
123
|
- spec/models/artist_spec.rb
|
124
|
+
- spec/models/base_model_spec.rb
|
122
125
|
- spec/models/release_group_spec.rb
|
123
126
|
- spec/models/release_spec.rb
|
124
127
|
- spec/models/track_spec.rb
|
@@ -149,12 +152,14 @@ signing_key:
|
|
149
152
|
specification_version: 3
|
150
153
|
summary: MusicBrainz Web Service wrapper with ActiveRecord-style models
|
151
154
|
test_files:
|
155
|
+
- spec/bindings/release_group_search_spec.rb
|
152
156
|
- spec/bindings/release_spec.rb
|
153
157
|
- spec/client_modules/cache_spec.rb
|
154
158
|
- spec/deprecated/cache_config_spec.rb
|
155
159
|
- spec/deprecated/proxy_config_spec.rb
|
156
160
|
- spec/fixtures/kasabian.xml
|
157
161
|
- spec/models/artist_spec.rb
|
162
|
+
- spec/models/base_model_spec.rb
|
158
163
|
- spec/models/release_group_spec.rb
|
159
164
|
- spec/models/release_spec.rb
|
160
165
|
- spec/models/track_spec.rb
|