Skip to content

Instantly share code, notes, and snippets.

@koyachi
Forked from youpy/gist:467883
Created July 17, 2010 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koyachi/479158 to your computer and use it in GitHub Desktop.
Save koyachi/479158 to your computer and use it in GitHub Desktop.
class Echonest::Api
def analysis(filename)
analysis_url = analysis_url(filename)
Analysis.new_from_url(analysis_url)
end
def analysis_url(filename)
loop = true
analysis_url = nil
while loop
response = profile(filename)
case response.track.status
when 'unknown'
upload(filename)
when 'pending'
sleep 60
when 'complete'
loop = false
analysis_url = response.track.audio_summary.analysis_url
when 'error'
raise Error.new(response.track.status)
when 'unavailable'
analyze(filename)
end
sleep 5
end
analysis_url
end
end
# new
require 'echonest'
filename = 'xxx.mp3'
echonest = Echonest('XXXXXX')
analysis = echonest.analysis(filename)
beats = analysis.beats
class Echonest
module TraditionalInterface
def get_beats(filename)
# ...
analysis(filename).beats
end
end
class Api
include TraditionalInterface
end
end
# traditional
require 'echonest'
require 'echonest/traditional_interface'
filename = 'xxx.mp3'
echonest = Echonest('XXXXXX')
beats = echonest.get_beats(filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment