Class: Echonest::Song
Instance Method Summary collapse
-
#echoprint_code(filepath) ⇒ Object
Generates an acoustic fingerprint using the echoprint-codegen binary.
- #identify(code) ⇒ Object
-
#initialize(api_key) ⇒ Song
constructor
A new instance of Song.
- #search(options = {}) ⇒ Object
Methods inherited from Base
base_uri, #endpoint, #entity_name, #get, #get_response, version, #which
Constructor Details
#initialize(api_key) ⇒ Song
Returns a new instance of Song.
10 11 12 |
# File 'lib/echonest-ruby-api/song.rb', line 10 def initialize(api_key) @api_key = api_key end |
Instance Method Details
#echoprint_code(filepath) ⇒ Object
Generates an acoustic fingerprint using the echoprint-codegen binary.
Examples:
echoprint_code('path/to/song.mp3')
#=> Echoprint code as String
Raises an Echoprint::Error
if the echoprint-codegen binary is not accessible to Ruby on $PATH
-
filepath
- Path (absolute or relative) to an audio file atleast 21 seconds in length
Returns a String
46 47 48 49 50 51 52 53 54 |
# File 'lib/echonest-ruby-api/song.rb', line 46 def echoprint_code(filepath) if which('echoprint-codegen').nil? error = Error.new(6) raise Error.new(6), error.description else response = `echoprint-codegen #{ filepath } 1 20` JSON.parse(response)[0]['code'] end end |
#identify(code) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/echonest-ruby-api/song.rb', line 23 def identify(code) raise ArgumentError, 'Not a valid Echoprint or ENFMP fingerprint' if code.empty? response = get_response(code: code) results = [] response[:songs].each do |song| results << { score: song[:score], title: song[:title], artist_name: song[:artist_name] } end results end |
#search(options = {}) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/echonest-ruby-api/song.rb', line 14 def search( = {}) defaults = { api_key: @api_key } response = get_response() songs = [] response[:songs].each do |song| songs << song end end |