musicbrainz_automatcher 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/musicbrainz_automatcher.rb +20 -17
- metadata +35 -29
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'active_support'
|
2
2
|
require 'rbrainz'
|
3
|
+
require 'logger'
|
3
4
|
require 'iconv'
|
5
|
+
require 'time'
|
4
6
|
require 'text'
|
5
7
|
|
6
8
|
# Monkey patch String class to add our escaping method
|
@@ -40,10 +42,9 @@ class MusicbrainzAutomatcher
|
|
40
42
|
# Given an array of artists and a track title, return an rbrainz artist object.
|
41
43
|
# If there is no match in MusicBrainz, then false is returned
|
42
44
|
def match_artist(artists, title=nil)
|
43
|
-
|
44
45
|
# Only interested in first item of title array
|
45
46
|
title = title.first if title.is_a?(Array)
|
46
|
-
|
47
|
+
|
47
48
|
# Remove excess whitespace from the title
|
48
49
|
title.strip! unless title.nil?
|
49
50
|
|
@@ -52,7 +53,7 @@ class MusicbrainzAutomatcher
|
|
52
53
|
|
53
54
|
# Return false if no artist names given
|
54
55
|
return false if artists.empty?
|
55
|
-
|
56
|
+
|
56
57
|
# Set title to nil, if it is an empty string
|
57
58
|
title = nil if !title.nil? and title.size<1
|
58
59
|
|
@@ -62,14 +63,14 @@ class MusicbrainzAutomatcher
|
|
62
63
|
|
63
64
|
# Remove items from the artist array until we get a match
|
64
65
|
mbartist_id = false
|
65
|
-
|
66
|
+
|
66
67
|
## Ignore if artist name contains two consecutive stars (they contain a sware words)
|
67
68
|
unless artist =~ /\*\*/
|
68
|
-
|
69
|
+
|
69
70
|
## First: lookup based on track name and artist
|
70
71
|
unless title.nil?
|
71
72
|
mbartist_id = lookup_by_track( artist, title )
|
72
|
-
|
73
|
+
|
73
74
|
## Second: try removing brackets from the track name
|
74
75
|
if !mbartist_id
|
75
76
|
matches = title.match(/^(.+)\s+\(.+\)$/)
|
@@ -86,7 +87,7 @@ class MusicbrainzAutomatcher
|
|
86
87
|
end
|
87
88
|
end
|
88
89
|
end
|
89
|
-
|
90
|
+
|
90
91
|
# Response is the MusicBrainz ID
|
91
92
|
mbartist_id
|
92
93
|
end
|
@@ -96,18 +97,20 @@ class MusicbrainzAutomatcher
|
|
96
97
|
protected
|
97
98
|
|
98
99
|
## Perform a block if key isn't already cached.
|
99
|
-
def do_cached(
|
100
|
-
key = Digest::SHA1.hexdigest(string)
|
101
|
-
|
100
|
+
def do_cached( key, &block )
|
102
101
|
# have a look in the cache
|
103
102
|
value = @cache.fetch( key )
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
103
|
+
|
104
|
+
# Cache HIT?
|
105
|
+
return value unless value.nil?
|
106
|
+
|
107
|
+
# Cache MISS : execute the block
|
108
|
+
value = block.call( key )
|
109
|
+
|
110
|
+
# Store value in the cache
|
111
|
+
@cache.write( key, value, :expires_at => Time.parse("18:00"))
|
112
|
+
|
113
|
+
return value
|
111
114
|
end
|
112
115
|
|
113
116
|
# Clean up the artist name array
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: musicbrainz_automatcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease:
|
5
|
+
version: 0.2.0
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Patrick Sinclair
|
@@ -9,59 +10,64 @@ autorequire:
|
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
12
|
|
12
|
-
date:
|
13
|
+
date: 2011-06-05 00:00:00 +01:00
|
13
14
|
default_executable:
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
name: text
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
20
21
|
requirements:
|
21
22
|
- - ~>
|
22
23
|
- !ruby/object:Gem::Version
|
23
|
-
version: "
|
24
|
-
|
24
|
+
version: "0.2"
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: rbrainz
|
27
|
-
|
28
|
-
|
29
|
-
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
30
32
|
requirements:
|
31
33
|
- - ~>
|
32
34
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
-
|
35
|
+
version: 0.5.1
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id002
|
35
38
|
- !ruby/object:Gem::Dependency
|
36
39
|
name: activesupport
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
40
43
|
requirements:
|
41
44
|
- - ~>
|
42
45
|
- !ruby/object:Gem::Version
|
43
|
-
version: "
|
44
|
-
|
46
|
+
version: "3.0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id003
|
45
49
|
- !ruby/object:Gem::Dependency
|
46
50
|
name: rspec
|
47
|
-
|
48
|
-
|
49
|
-
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
50
54
|
requirements:
|
51
55
|
- - ">="
|
52
56
|
- !ruby/object:Gem::Version
|
53
57
|
version: "0"
|
54
|
-
|
58
|
+
type: :development
|
59
|
+
version_requirements: *id004
|
55
60
|
- !ruby/object:Gem::Dependency
|
56
61
|
name: mocha
|
57
|
-
|
58
|
-
|
59
|
-
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
60
65
|
requirements:
|
61
66
|
- - ">="
|
62
67
|
- !ruby/object:Gem::Version
|
63
68
|
version: "0"
|
64
|
-
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id005
|
65
71
|
description:
|
66
72
|
email: metade@gmail.com
|
67
73
|
executables: []
|
@@ -84,21 +90,21 @@ rdoc_options:
|
|
84
90
|
require_paths:
|
85
91
|
- lib
|
86
92
|
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
87
94
|
requirements:
|
88
95
|
- - ">="
|
89
96
|
- !ruby/object:Gem::Version
|
90
97
|
version: "0"
|
91
|
-
version:
|
92
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
93
100
|
requirements:
|
94
101
|
- - ">="
|
95
102
|
- !ruby/object:Gem::Version
|
96
103
|
version: "0"
|
97
|
-
version:
|
98
104
|
requirements: []
|
99
105
|
|
100
106
|
rubyforge_project: musicbrainz_automatcher
|
101
|
-
rubygems_version: 1.
|
107
|
+
rubygems_version: 1.6.2
|
102
108
|
signing_key:
|
103
109
|
specification_version: 3
|
104
110
|
summary: musicbrainz_automatcher matches artists/tracks names to MusicBrainz intelligently
|