echonest-ruby-api 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +11 -2
- data/README.md +73 -18
- data/echonest-ruby-api.gemspec +1 -0
- data/lib/echonest-ruby-api.rb +1 -0
- data/lib/echonest-ruby-api/artist.rb +1 -1
- data/lib/echonest-ruby-api/base.rb +14 -1
- data/lib/echonest-ruby-api/error.rb +27 -0
- data/lib/echonest-ruby-api/song.rb +24 -1
- data/lib/echonest-ruby-api/version.rb +1 -1
- data/spec/artist_spec.rb +1 -1
- data/spec/error_spec.rb +22 -0
- data/spec/song_spec.rb +31 -0
- metadata +21 -28
- data/Gemfile.lock +0 -56
- data/doc/Biography.html +0 -368
- data/doc/Blog.html +0 -422
- data/doc/Echonest.html +0 -129
- data/doc/Echonest/Artist.html +0 -839
- data/doc/Echonest/Base.html +0 -471
- data/doc/Echonest/Base/EchonestConnectionError.html +0 -123
- data/doc/_index.html +0 -157
- data/doc/class_list.html +0 -53
- data/doc/css/common.css +0 -1
- data/doc/css/full_list.css +0 -57
- data/doc/css/style.css +0 -328
- data/doc/file.README.html +0 -128
- data/doc/file_list.html +0 -55
- data/doc/frames.html +0 -28
- data/doc/index.html +0 -128
- data/doc/js/app.js +0 -214
- data/doc/js/full_list.js +0 -173
- data/doc/js/jquery.js +0 -4
- data/doc/method_list.html +0 -252
- data/doc/top-level-namespace.html +0 -114
- data/echonest-ruby-api-0.0.5.gem +0 -0
- data/pkg/echonest-ruby-api-0.0.1.gem +0 -0
- data/pkg/echonest-ruby-api-0.0.3.gem +0 -0
- data/pkg/echonest-ruby-api-0.0.4.gem +0 -0
- data/pkg/echonest-ruby-api-0.0.5.gem +0 -0
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,21 +1,26 @@
|
|
1
|
-
# echonest-ruby-api
|
2
|
-
[![Code Climate](https://codeclimate.com/github/maxehmookau/echonest-ruby-api.png)](https://codeclimate.com/github/maxehmookau/echonest-ruby-api)
|
3
|
-
[![Build Status](https://travis-ci.org/maxehmookau/echonest-ruby-api.png)](https://travis-ci.org/maxehmookau/echonest-ruby-api)
|
4
|
-
[![Dependency Status](https://gemnasium.com/maxehmookau/echonest-ruby-api.png)](https://gemnasium.com/maxehmookau/echonest-ruby-api)
|
1
|
+
# echonest-ruby-api [![Code Climate](https://codeclimate.com/github/maxehmookau/echonest-ruby-api.png)](https://codeclimate.com/github/maxehmookau/echonest-ruby-api) [![Build Status](https://travis-ci.org/maxehmookau/echonest-ruby-api.png)](https://travis-ci.org/maxehmookau/echonest-ruby-api) [![Dependency Status](https://gemnasium.com/maxehmookau/echonest-ruby-api.png)](https://gemnasium.com/maxehmookau/echonest-ruby-api)
|
5
2
|
|
6
|
-
## Installation
|
7
3
|
|
8
|
-
|
4
|
+
![Echonest] (http://the.echonest.com/static/img/logos/250x80_lt.gif)
|
9
5
|
|
10
|
-
|
6
|
+
**echonesst-ruby-api** is a pure Ruby wrapper around the Echonest APIs.
|
7
|
+
|
8
|
+
## Requirements
|
9
|
+
* An API Key (available free)
|
10
|
+
* Ruby 1.9.3+
|
11
|
+
* [echonest/echoprint-codegen](https://github.com/echonest/echoprint-codegen) binary in your `$PATH` if you want to identify audio files. (yeah, *identify!*)
|
11
12
|
|
12
|
-
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
In your Gemfile:
|
13
16
|
|
14
|
-
|
17
|
+
gem 'echonest-ruby-api'
|
18
|
+
|
19
|
+
and then `bundle install`
|
15
20
|
|
16
|
-
Or install
|
21
|
+
Or install locally:
|
17
22
|
|
18
|
-
$ gem install echonest-ruby-api
|
23
|
+
$ (sudo) gem install echonest-ruby-api
|
19
24
|
|
20
25
|
|
21
26
|
## Usage
|
@@ -24,8 +29,7 @@ Require the gem in your file:
|
|
24
29
|
|
25
30
|
require 'echonest-ruby-api'
|
26
31
|
|
27
|
-
|
28
|
-
|
32
|
+
## Artist
|
29
33
|
|
30
34
|
Create an instance of an object
|
31
35
|
|
@@ -40,8 +44,10 @@ Then you have access to a bunch of methods:
|
|
40
44
|
artist.hotttnesss
|
41
45
|
artist.images
|
42
46
|
artist.songs
|
47
|
+
|
48
|
+
*Exact response are specified in the RDoc but the method names try to be as self-explanatory as possible.*
|
43
49
|
|
44
|
-
|
50
|
+
## Song
|
45
51
|
|
46
52
|
Create an instance of the Song module.
|
47
53
|
|
@@ -55,13 +61,62 @@ Then you have access to the song/search endpoint:
|
|
55
61
|
|
56
62
|
See the full list of params [here](http://developer.echonest.com/docs/v4/song.html#search)
|
57
63
|
|
58
|
-
|
64
|
+
## Identification
|
65
|
+
|
66
|
+
> **Note:** This stuff is flakey as hell. Seems to work pretty well on OSX, but it doesn't work out of the box. You'll need to follow these instructions to get it working.
|
67
|
+
|
68
|
+
You can even **identify** a song simply from its fingerprint! Support for this is flaky so far and only tested on OS X.
|
59
69
|
|
60
|
-
Firstly
|
70
|
+
Firstly, make sure that the `echoprint-codegen` binary is available on your local `$PATH`.
|
71
|
+
|
72
|
+
Just run: `echoprint-codegen` on the terminal and see if it returns anything other than an error.
|
73
|
+
|
74
|
+
If it's not installed, you'll need to compile it from source. **It's not as scary as it sounds.**
|
61
75
|
|
62
|
-
song.idenfity(YOUR_ECHOPRINT_CODE)
|
63
76
|
|
64
|
-
|
77
|
+
brew install ffmpeg boost taglib # Install dependencies
|
78
|
+
|
79
|
+
cd ~/Desktop/ # or somewhere else sensible, you can delete it later anyway
|
80
|
+
|
81
|
+
git clone https://github.com/echonest/echoprint-codegen.git
|
82
|
+
|
83
|
+
cd echoprint-codegen
|
84
|
+
|
85
|
+
make
|
86
|
+
|
87
|
+
make install
|
88
|
+
|
89
|
+
This should then allow you to use the `echoprint-codegen` command at the command line. If not, try following the instructions here: [echonest/echoprint-codegen](https://github.com/echonest/echoprint-codegen)
|
90
|
+
|
91
|
+
Then just use this method call:
|
92
|
+
|
93
|
+
song = Echonest::Song.new('YOUR-API-KEY')
|
94
|
+
code = song.echoprint_code('path/to/audio/file')
|
95
|
+
puts code.identify(code)
|
96
|
+
|
97
|
+
If there's a positive match, it'll return something like this:
|
98
|
+
|
99
|
+
{
|
100
|
+
"response": {
|
101
|
+
"status": {
|
102
|
+
"code": 0,
|
103
|
+
"message": "Success",
|
104
|
+
"version": "4.2"
|
105
|
+
},
|
106
|
+
"songs": [
|
107
|
+
{
|
108
|
+
"title": "Billie Jean",
|
109
|
+
"artist_name": "Michael Jackson",
|
110
|
+
"artist_id": "ARXPPEY1187FB51DF4",
|
111
|
+
"score": 49,
|
112
|
+
"message": "OK (match type 5)",
|
113
|
+
"id": "SOKHYNL12A8C142FC7"
|
114
|
+
}
|
115
|
+
]
|
116
|
+
}
|
117
|
+
}
|
118
|
+
|
119
|
+
Checkout `spec/song_spec.rb` for an example code to test it out.
|
65
120
|
|
66
121
|
Note that this calls the song/identify API endpoint and does *not* support other Echoprint servers.
|
67
122
|
|
data/echonest-ruby-api.gemspec
CHANGED
data/lib/echonest-ruby-api.rb
CHANGED
@@ -60,8 +60,21 @@ module Echonest
|
|
60
60
|
json = MultiJson.load(response.body, symbolize_keys: true)
|
61
61
|
response_code = json[:response][:status][:code]
|
62
62
|
|
63
|
-
response_code.eql?(0) ? json[:response] : raise(
|
63
|
+
response_code.eql?(0) ? json[:response] : raise(Echonest::Error.new(response_code), "Error code #{ response_code }")
|
64
|
+
end
|
64
65
|
|
66
|
+
# Cross-platform way of finding an executable in the $PATH.
|
67
|
+
#
|
68
|
+
# which('ruby') #=> /usr/bin/ruby
|
69
|
+
def which(cmd)
|
70
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
71
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
72
|
+
exts.each { |ext|
|
73
|
+
exe = File.join(path, "#{ cmd }#{ ext }")
|
74
|
+
return exe if File.executable? exe
|
75
|
+
}
|
76
|
+
end
|
77
|
+
return nil
|
65
78
|
end
|
66
79
|
|
67
80
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Echonest
|
2
|
+
|
3
|
+
class Error < Exception
|
4
|
+
ERRORS = { '-1' => 'Unknown Error',
|
5
|
+
'0' => 'Success',
|
6
|
+
'1' => 'Invalid/Missing API Key',
|
7
|
+
'2' => 'This API key is not allowed to call that method',
|
8
|
+
'3' => 'Rate limit exceeded',
|
9
|
+
'4' => 'Missing parameter',
|
10
|
+
'5' => 'Invalid parameter',
|
11
|
+
'6' => 'Missing echoprint-codegen binary on $PATH'
|
12
|
+
}
|
13
|
+
|
14
|
+
|
15
|
+
# Create a new Echonest::Error object
|
16
|
+
def initialize(error_code)
|
17
|
+
@error_code = error_code
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def description
|
22
|
+
ERRORS[@error_code.to_s]
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -30,5 +30,28 @@ module Echonest
|
|
30
30
|
results
|
31
31
|
end
|
32
32
|
|
33
|
+
# Generates an acoustic fingerprint using the echoprint-codegen
|
34
|
+
# binary.
|
35
|
+
#
|
36
|
+
# Examples:
|
37
|
+
# echoprint_code('path/to/song.mp3')
|
38
|
+
# #=> Echoprint code as String
|
39
|
+
#
|
40
|
+
# Raises an +Echoprint::Error+ if the echoprint-codegen binary
|
41
|
+
# is not accessible to Ruby on $PATH
|
42
|
+
#
|
43
|
+
# * +filepath+ - Path (absolute or relative) to an audio file atleast 21 seconds in length
|
44
|
+
#
|
45
|
+
# Returns a String
|
46
|
+
def echoprint_code(filepath)
|
47
|
+
if which('echoprint-codegen').nil?
|
48
|
+
error = Error.new(6)
|
49
|
+
raise Error.new(6), error.description
|
50
|
+
else
|
51
|
+
response = `echoprint-codegen #{ filepath } 1 20`
|
52
|
+
JSON.parse(response)[0]['code']
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
33
56
|
end
|
34
|
-
end
|
57
|
+
end
|
data/spec/artist_spec.rb
CHANGED
@@ -35,7 +35,7 @@ describe Echonest::Artist do
|
|
35
35
|
|
36
36
|
it 'should deal gracefully with an invalid API key' do
|
37
37
|
a = Echonest::Artist.new('Weezer', 'THISISNOTAKEY')
|
38
|
-
expect { a.biographies }.to raise_error(
|
38
|
+
expect { a.biographies }.to raise_error(Echonest::Error)
|
39
39
|
end
|
40
40
|
|
41
41
|
end
|
data/spec/error_spec.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Echonest::Error do
|
4
|
+
|
5
|
+
describe '#initialize' do
|
6
|
+
|
7
|
+
it 'should accept an error code as the only parameter' do
|
8
|
+
err = Echonest::Error.new(3)
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#description' do
|
14
|
+
|
15
|
+
it 'should return the errors description' do
|
16
|
+
err = Echonest::Error.new(5)
|
17
|
+
err.description.should eql 'Invalid parameter'
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/spec/song_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'mocha/setup'
|
2
3
|
|
3
4
|
describe Echonest::Song do
|
4
5
|
|
@@ -52,5 +53,35 @@ describe Echonest::Song do
|
|
52
53
|
end
|
53
54
|
|
54
55
|
end
|
56
|
+
|
57
|
+
describe '#echoprint_code' do
|
58
|
+
# This is all very hard to test in a sensible way since it relies on
|
59
|
+
# a binary existing on the users machine.
|
60
|
+
|
61
|
+
# it 'should raise Exception if echoprint-codegen binary is not present' do
|
62
|
+
# a = Echonest::Song.new('BNOAEBT3IZYZI6WXI')
|
63
|
+
# a.stubs(:which).returns(nil)
|
64
|
+
# expect { a.echoprint_code('path-to-mp3') }.to raise_error(Echonest::Error)
|
65
|
+
# end
|
66
|
+
|
67
|
+
# it 'should call the echoprint-binary if it exists' do
|
68
|
+
# a = Echonest::Song.new('BNOAEBT3IZYZI6WXI')
|
69
|
+
# a.echoprint_code('/Users/maxwoolf/Desktop/example.mp3')
|
70
|
+
# end
|
71
|
+
|
72
|
+
# it 'should return a massive string if it was successful' do
|
73
|
+
# a = Echonest::Song.new('BNOAEBT3IZYZI6WXI')
|
74
|
+
# a.echoprint_code('/Users/maxwoolf/Desktop/example.mp3').should be_a String
|
75
|
+
# a.echoprint_code('/Users/maxwoolf/Desktop/example.mp3').length.should be > 400
|
76
|
+
# end
|
77
|
+
|
78
|
+
# it 'should identify a song using a generated code' do
|
79
|
+
# a = Echonest::Song.new('BNOAEBT3IZYZI6WXI')
|
80
|
+
# code = a.echoprint_code('/Users/maxwoolf/Desktop/example.mp3')
|
81
|
+
# puts code
|
82
|
+
# puts
|
83
|
+
# end
|
84
|
+
end
|
85
|
+
|
55
86
|
|
56
87
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: echonest-ruby-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
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: 2013-02-
|
12
|
+
date: 2013-02-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -91,6 +91,22 @@ dependencies:
|
|
91
91
|
- - ~>
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: 0.9.1
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: mocha
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
94
110
|
description: A simple ruby wrapper around the Echonest API
|
95
111
|
email:
|
96
112
|
- max.woolf@boxuk.com
|
@@ -100,46 +116,22 @@ extra_rdoc_files: []
|
|
100
116
|
files:
|
101
117
|
- .gitignore
|
102
118
|
- Gemfile
|
103
|
-
- Gemfile.lock
|
104
119
|
- Guardfile
|
105
120
|
- LICENSE.txt
|
106
121
|
- README.md
|
107
122
|
- Rakefile
|
108
|
-
- doc/Biography.html
|
109
|
-
- doc/Blog.html
|
110
|
-
- doc/Echonest.html
|
111
|
-
- doc/Echonest/Artist.html
|
112
|
-
- doc/Echonest/Base.html
|
113
|
-
- doc/Echonest/Base/EchonestConnectionError.html
|
114
|
-
- doc/_index.html
|
115
|
-
- doc/class_list.html
|
116
|
-
- doc/css/common.css
|
117
|
-
- doc/css/full_list.css
|
118
|
-
- doc/css/style.css
|
119
|
-
- doc/file.README.html
|
120
|
-
- doc/file_list.html
|
121
|
-
- doc/frames.html
|
122
|
-
- doc/index.html
|
123
|
-
- doc/js/app.js
|
124
|
-
- doc/js/full_list.js
|
125
|
-
- doc/js/jquery.js
|
126
|
-
- doc/method_list.html
|
127
|
-
- doc/top-level-namespace.html
|
128
|
-
- echonest-ruby-api-0.0.5.gem
|
129
123
|
- echonest-ruby-api.gemspec
|
130
124
|
- lib/echonest-ruby-api.rb
|
131
125
|
- lib/echonest-ruby-api/artist.rb
|
132
126
|
- lib/echonest-ruby-api/base.rb
|
133
127
|
- lib/echonest-ruby-api/biography.rb
|
134
128
|
- lib/echonest-ruby-api/blog.rb
|
129
|
+
- lib/echonest-ruby-api/error.rb
|
135
130
|
- lib/echonest-ruby-api/song.rb
|
136
131
|
- lib/echonest-ruby-api/version.rb
|
137
|
-
- pkg/echonest-ruby-api-0.0.1.gem
|
138
|
-
- pkg/echonest-ruby-api-0.0.3.gem
|
139
|
-
- pkg/echonest-ruby-api-0.0.4.gem
|
140
|
-
- pkg/echonest-ruby-api-0.0.5.gem
|
141
132
|
- spec/artist_spec.rb
|
142
133
|
- spec/base_spec.rb
|
134
|
+
- spec/error_spec.rb
|
143
135
|
- spec/song_spec.rb
|
144
136
|
- spec/spec_helper.rb
|
145
137
|
- tmp/rspec_guard_result
|
@@ -170,6 +162,7 @@ summary: A gem to get hold of some echonest stuff!
|
|
170
162
|
test_files:
|
171
163
|
- spec/artist_spec.rb
|
172
164
|
- spec/base_spec.rb
|
165
|
+
- spec/error_spec.rb
|
173
166
|
- spec/song_spec.rb
|
174
167
|
- spec/spec_helper.rb
|
175
168
|
has_rdoc:
|
data/Gemfile.lock
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
echonest-ruby-api (0.0.5)
|
5
|
-
httparty
|
6
|
-
multi_json
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
coderay (1.0.8)
|
12
|
-
diff-lcs (1.1.3)
|
13
|
-
guard (1.6.2)
|
14
|
-
listen (>= 0.6.0)
|
15
|
-
lumberjack (>= 1.0.2)
|
16
|
-
pry (>= 0.9.10)
|
17
|
-
terminal-table (>= 1.4.3)
|
18
|
-
thor (>= 0.14.6)
|
19
|
-
guard-rspec (2.4.0)
|
20
|
-
guard (>= 1.1)
|
21
|
-
rspec (~> 2.11)
|
22
|
-
httparty (0.10.2)
|
23
|
-
multi_json (~> 1.0)
|
24
|
-
multi_xml (>= 0.5.2)
|
25
|
-
listen (0.7.2)
|
26
|
-
lumberjack (1.0.2)
|
27
|
-
method_source (0.8.1)
|
28
|
-
multi_json (1.5.0)
|
29
|
-
multi_xml (0.5.2)
|
30
|
-
pry (0.9.10)
|
31
|
-
coderay (~> 1.0.5)
|
32
|
-
method_source (~> 0.8)
|
33
|
-
slop (~> 3.3.1)
|
34
|
-
rake (10.0.3)
|
35
|
-
rb-fsevent (0.9.3)
|
36
|
-
rspec (2.12.0)
|
37
|
-
rspec-core (~> 2.12.0)
|
38
|
-
rspec-expectations (~> 2.12.0)
|
39
|
-
rspec-mocks (~> 2.12.0)
|
40
|
-
rspec-core (2.12.0)
|
41
|
-
rspec-expectations (2.12.0)
|
42
|
-
diff-lcs (~> 1.1.3)
|
43
|
-
rspec-mocks (2.12.0)
|
44
|
-
slop (3.3.3)
|
45
|
-
terminal-table (1.4.5)
|
46
|
-
thor (0.16.0)
|
47
|
-
|
48
|
-
PLATFORMS
|
49
|
-
ruby
|
50
|
-
|
51
|
-
DEPENDENCIES
|
52
|
-
echonest-ruby-api!
|
53
|
-
guard-rspec
|
54
|
-
rake
|
55
|
-
rb-fsevent (~> 0.9.1)
|
56
|
-
rspec (~> 2.6)
|