youpy-ruby-echonest 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/Rakefile +1 -1
- data/lib/echonest/api.rb +25 -25
- data/lib/echonest/response.rb +6 -6
- data/lib/echonest/version.rb +1 -1
- data/spec/response_spec.rb +1 -1
- metadata +13 -4
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -60,7 +60,7 @@ spec = Gem::Specification.new do |s|
|
|
60
60
|
s.require_path = "lib"
|
61
61
|
s.test_files = Dir["test/test_*.rb"]
|
62
62
|
|
63
|
-
|
63
|
+
s.add_dependency('libxml-ruby')
|
64
64
|
#s.required_ruby_version = '>= 1.8.2'
|
65
65
|
|
66
66
|
s.files = %w(README.rdoc ChangeLog Rakefile) +
|
data/lib/echonest/api.rb
CHANGED
@@ -17,7 +17,7 @@ module Echonest
|
|
17
17
|
def get_bars(filename)
|
18
18
|
get_analysys(:get_bars, filename) do |analysis|
|
19
19
|
analysis.map do |bar|
|
20
|
-
Bar.new(bar.
|
20
|
+
Bar.new(bar.content.to_f, bar['confidence'].to_f)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -25,7 +25,7 @@ module Echonest
|
|
25
25
|
def get_beats(filename)
|
26
26
|
get_analysys(:get_beats, filename) do |analysis|
|
27
27
|
analysis.map do |beat|
|
28
|
-
Beat.new(beat.
|
28
|
+
Beat.new(beat.content.to_f, beat['confidence'].to_f)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -35,25 +35,25 @@ module Echonest
|
|
35
35
|
analysis.map do |segment|
|
36
36
|
max_loudness = loudness = nil
|
37
37
|
|
38
|
-
segment.
|
39
|
-
if db
|
40
|
-
max_loudness = Loudness.new(db
|
38
|
+
segment.find('loudness/dB').map do |db|
|
39
|
+
if db['type'] == 'max'
|
40
|
+
max_loudness = Loudness.new(db['time'].to_f, db.content.to_f)
|
41
41
|
else
|
42
|
-
loudness = Loudness.new(db
|
42
|
+
loudness = Loudness.new(db['time'].to_f, db.content.to_f)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
pitches = segment.
|
47
|
-
pitch.
|
46
|
+
pitches = segment.find('pitches/pitch').map do |pitch|
|
47
|
+
pitch.content.to_f
|
48
48
|
end
|
49
49
|
|
50
|
-
timbre = segment.
|
51
|
-
coeff.
|
50
|
+
timbre = segment.find('timbre/coeff').map do |coeff|
|
51
|
+
coeff.content.to_f
|
52
52
|
end
|
53
53
|
|
54
54
|
Segment.new(
|
55
|
-
segment
|
56
|
-
segment
|
55
|
+
segment['start'].to_f,
|
56
|
+
segment['duration'].to_f,
|
57
57
|
loudness,
|
58
58
|
max_loudness,
|
59
59
|
pitches,
|
@@ -65,7 +65,7 @@ module Echonest
|
|
65
65
|
|
66
66
|
def get_tempo(filename)
|
67
67
|
get_analysys(:get_tempo, filename) do |analysis|
|
68
|
-
analysis
|
68
|
+
analysis.first.content.to_f
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -73,8 +73,8 @@ module Echonest
|
|
73
73
|
get_analysys(:get_sections, filename) do |analysis|
|
74
74
|
analysis.map do |section|
|
75
75
|
Section.new(
|
76
|
-
section
|
77
|
-
section
|
76
|
+
section['start'].to_f,
|
77
|
+
section['duration'].to_f
|
78
78
|
)
|
79
79
|
end
|
80
80
|
end
|
@@ -82,32 +82,32 @@ module Echonest
|
|
82
82
|
|
83
83
|
def get_duration(filename)
|
84
84
|
get_analysys(:get_duration, filename) do |analysis|
|
85
|
-
analysis
|
85
|
+
analysis.first.content.to_f
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
89
|
def get_end_of_fade_in(filename)
|
90
90
|
get_analysys(:get_end_of_fade_in, filename) do |analysis|
|
91
|
-
analysis
|
91
|
+
analysis.first.content.to_f
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
95
|
def get_key(filename)
|
96
96
|
get_analysys(:get_key, filename) do |analysis|
|
97
|
-
ValueWithConfidence.new(analysis
|
97
|
+
ValueWithConfidence.new(analysis.first.content.to_i, analysis.first['confidence'].to_f)
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
101
|
def get_loudness(filename)
|
102
102
|
get_analysys(:get_loudness, filename) do |analysis|
|
103
|
-
analysis
|
103
|
+
analysis.first.content.to_f
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
107
|
def get_metadata(filename)
|
108
108
|
get_analysys(:get_metadata, filename) do |analysis|
|
109
109
|
analysis.inject({}) do |memo, key|
|
110
|
-
memo[key.name] = key.
|
110
|
+
memo[key.name] = key.content
|
111
111
|
memo
|
112
112
|
end
|
113
113
|
end
|
@@ -115,27 +115,27 @@ module Echonest
|
|
115
115
|
|
116
116
|
def get_mode(filename)
|
117
117
|
get_analysys(:get_mode, filename) do |analysis|
|
118
|
-
ValueWithConfidence.new(analysis
|
118
|
+
ValueWithConfidence.new(analysis.first.content.to_i, analysis.first['confidence'].to_f)
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
122
|
def get_start_of_fade_out(filename)
|
123
123
|
get_analysys(:get_start_of_fade_out, filename) do |analysis|
|
124
|
-
analysis
|
124
|
+
analysis.first.content.to_f
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
128
|
def get_tatums(filename)
|
129
129
|
get_analysys(:get_tatums, filename) do |analysis|
|
130
130
|
analysis.map do |tatum|
|
131
|
-
Tatum.new(tatum.
|
131
|
+
Tatum.new(tatum.content.to_f, tatum['confidence'].to_f)
|
132
132
|
end
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
136
136
|
def get_time_signature(filename)
|
137
137
|
get_analysys(:get_time_signature, filename) do |analysis|
|
138
|
-
ValueWithConfidence.new(analysis
|
138
|
+
ValueWithConfidence.new(analysis.first.content.to_i, analysis.first['confidence'].to_f)
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
@@ -147,7 +147,7 @@ module Echonest
|
|
147
147
|
|
148
148
|
def get_analysys(method, filename)
|
149
149
|
get_trackinfo(method, filename) do |response|
|
150
|
-
yield response.xml.
|
150
|
+
yield response.xml.find('/response/analysis').first
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
data/lib/echonest/response.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
require "
|
1
|
+
require "xml"
|
2
2
|
|
3
3
|
module Echonest
|
4
4
|
class Response
|
5
5
|
attr_reader :xml
|
6
6
|
|
7
7
|
def initialize(body)
|
8
|
-
@xml =
|
8
|
+
@xml = XML::Document.string(body)
|
9
9
|
end
|
10
10
|
|
11
11
|
def status
|
@@ -32,8 +32,8 @@ module Echonest
|
|
32
32
|
attr_reader :code, :message
|
33
33
|
|
34
34
|
def initialize(xml)
|
35
|
-
@code = xml.
|
36
|
-
@message = xml.
|
35
|
+
@code = xml.find('/response/status/code').first.content.to_s.to_i
|
36
|
+
@message = xml.find('/response/status/message').first.content.to_s
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -41,8 +41,8 @@ module Echonest
|
|
41
41
|
def initialize(xml)
|
42
42
|
@parameters = {}
|
43
43
|
|
44
|
-
xml.
|
45
|
-
@parameters[parameter
|
44
|
+
xml.find('/response/query/parameter').each do |parameter|
|
45
|
+
@parameters[parameter['name'].to_sym] = parameter.content
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
data/lib/echonest/version.rb
CHANGED
data/spec/response_spec.rb
CHANGED
@@ -46,7 +46,7 @@ EOM
|
|
46
46
|
@success.status.code.should eql(0)
|
47
47
|
@success.status.message.should eql('Success')
|
48
48
|
@success.success?.should be_true
|
49
|
-
@success.xml.
|
49
|
+
@success.xml.find('/response/artist/name').first.content.should eql('Radiohead')
|
50
50
|
|
51
51
|
@failure.status.code.should eql(1)
|
52
52
|
@failure.status.message.should eql('Invalid API key')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: youpy-ruby-echonest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- youpy
|
@@ -9,10 +9,19 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06
|
12
|
+
date: 2009-07-06 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: libxml-ruby
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
16
25
|
description: An Ruby interface for Echo Nest Developer API
|
17
26
|
email: youpy@buycheapviagraonlinenow.com
|
18
27
|
executables: []
|