-
-
Save koyachi/479158 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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