musicbrainz 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Contributors +1 -0
- data/lib/musicbrainz/artist.rb +3 -17
- data/lib/parsers/artist.rb +3 -5
- data/lib/version.rb +1 -1
- data/spec/requests/artist_spec.rb +16 -1
- metadata +8 -2
data/Contributors
CHANGED
data/lib/musicbrainz/artist.rb
CHANGED
@@ -39,27 +39,13 @@ module MusicBrainz
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def search(name)
|
42
|
-
|
42
|
+
load({
|
43
43
|
:parser => :artist_search
|
44
44
|
}, {
|
45
45
|
:resource => :artist,
|
46
|
-
:query => CGI.escape(name).gsub(/\!/, '\!')
|
47
|
-
:limit =>
|
46
|
+
:query => "artist:" << CGI.escape(name).gsub(/\!/, '\!'),
|
47
|
+
:limit => 10
|
48
48
|
})
|
49
|
-
artists.each { |artist|
|
50
|
-
if artist[:name].downcase == name.downcase
|
51
|
-
artist[:weight] += 80
|
52
|
-
elsif artist[:name].downcase.gsub(/\s/, "") == name.downcase.gsub(/\s/, "")
|
53
|
-
artist[:weight] += 25
|
54
|
-
elsif artist[:aliases].include? name
|
55
|
-
artist[:weight] += 20
|
56
|
-
elsif artist[:aliases].map { |item| item.downcase }.include?(name.downcase)
|
57
|
-
artist[:weight] += 10
|
58
|
-
elsif artist[:aliases].map { |item| item.downcase.gsub(/\s/, "") }.include?(name.downcase.gsub(/\s/, ""))
|
59
|
-
artist[:weight] += 5
|
60
|
-
end
|
61
|
-
}
|
62
|
-
artists.sort{ |a, b| b[:weight] <=> a[:weight] }.take(10)
|
63
49
|
end
|
64
50
|
|
65
51
|
def discography(mbid)
|
data/lib/parsers/artist.rb
CHANGED
@@ -21,19 +21,17 @@ module MusicBrainz
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def search(xml)
|
24
|
-
|
25
|
-
|
26
|
-
artists << {
|
24
|
+
xml.css("artist-list > artist").map do |a|
|
25
|
+
{
|
27
26
|
:name => a.first_element_child.text.gsub(/[`’]/, "'"),
|
28
27
|
:sort_name => safe_get_value(a, "sort-name").gsub(/[`’]/, "'"),
|
29
|
-
:
|
28
|
+
:score => (safe_get_attr(a, nil, "score").to_i rescue 0),
|
30
29
|
:desc => safe_get_value(a, "disambiguation"),
|
31
30
|
:type => safe_get_attr(a, nil, "type"),
|
32
31
|
:mbid => safe_get_attr(a, nil, "id"),
|
33
32
|
:aliases => a.css("alias-list > alias").map { |item| item.text }
|
34
33
|
}
|
35
34
|
end
|
36
|
-
artists
|
37
35
|
end
|
38
36
|
|
39
37
|
def release_groups(xml)
|
data/lib/version.rb
CHANGED
@@ -20,10 +20,25 @@ describe MusicBrainz::Artist do
|
|
20
20
|
matches.first[:name].should == "Kasabian"
|
21
21
|
end
|
22
22
|
|
23
|
+
it "should return search results in the right order and pass back the correct score" do
|
24
|
+
matches = MusicBrainz::Artist.search('Chris Martin')
|
25
|
+
|
26
|
+
matches[0][:score].should == 100
|
27
|
+
matches[0][:mbid].should == "98d1ec5a-dd97-4c0b-9c83-7928aac89bca"
|
28
|
+
matches[1][:score].should == 100
|
29
|
+
matches[1][:mbid].should == "af2ab893-3212-4226-9e73-73a1660b6952"
|
30
|
+
matches[2][:score].should == 95
|
31
|
+
matches[2][:mbid].should == "444d1b63-534b-4ea6-89f0-0af6ab2e20c3"
|
32
|
+
matches[3][:score].should == 95
|
33
|
+
matches[3][:mbid].should == "b732a912-af95-472c-be52-b14610734c64"
|
34
|
+
matches[4][:score].should == 95
|
35
|
+
matches[4][:mbid].should == "90fff570-a4ef-4cd4-ba21-e00c7261b05a"
|
36
|
+
end
|
37
|
+
|
23
38
|
it "finds name first than alias" do
|
24
39
|
matches = MusicBrainz::Artist.search('Chris Martin')
|
25
40
|
matches.length.should be > 0
|
26
|
-
matches.first[:mbid].should == "
|
41
|
+
matches.first[:mbid].should == "98d1ec5a-dd97-4c0b-9c83-7928aac89bca"
|
27
42
|
end
|
28
43
|
|
29
44
|
it "gets correct result by name" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: musicbrainz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -127,12 +127,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
127
127
|
- - ! '>='
|
128
128
|
- !ruby/object:Gem::Version
|
129
129
|
version: '0'
|
130
|
+
segments:
|
131
|
+
- 0
|
132
|
+
hash: 4552071205810046641
|
130
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
134
|
none: false
|
132
135
|
requirements:
|
133
136
|
- - ! '>='
|
134
137
|
- !ruby/object:Gem::Version
|
135
138
|
version: '0'
|
139
|
+
segments:
|
140
|
+
- 0
|
141
|
+
hash: 4552071205810046641
|
136
142
|
requirements: []
|
137
143
|
rubyforge_project:
|
138
144
|
rubygems_version: 1.8.23
|