Skip to content

Commit

Permalink
Added the artist, album and track title to analysis results, includin…
Browse files Browse the repository at this point in the history
…g RSpec tests and updated test .json
  • Loading branch information
chrism committed Apr 17, 2013
1 parent 3ebd63b commit 6fb0203
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 27 deletions.
16 changes: 16 additions & 0 deletions lib/echonest/analysis.rb
Expand Up @@ -18,6 +18,18 @@ def self.new_from_url(url)
end end
end end


def artist
meta_info['artist']
end

def album
meta_info['album']
end

def title
meta_info['title']
end

def tempo def tempo
track_info['tempo'] track_info['tempo']
end end
Expand Down Expand Up @@ -94,5 +106,9 @@ def segments
def track_info def track_info
@body['track'] @body['track']
end end

def meta_info
@body['meta']
end
end end
end end
62 changes: 37 additions & 25 deletions spec/analysis_spec.rb
Expand Up @@ -7,44 +7,56 @@
@analysis = Echonest::Analysis.new(open(fixture('analysis.json')).read) @analysis = Echonest::Analysis.new(open(fixture('analysis.json')).read)
end end


it "should have artist" do
@analysis.artist.should eql("Philip Glass")
end

it "should have album" do
@analysis.album.should eql("The Orange Mountain Music Philip Glass Sampler Vol.I")
end

it "should have title" do
@analysis.title.should eql("Neverwas Restored (from Neverwas Soundtrack)")
end

it "should have beats" do it "should have beats" do
beats = @analysis.beats beats = @analysis.beats


beats.size.should eql(324) beats.size.should eql(301)
beats.first.start.should eql(0.27661) beats.first.start.should eql(0.14982)
beats.first.duration.should eql(0.36476) beats.first.duration.should eql(0.42958)
beats.first.confidence.should eql(0.468) beats.first.confidence.should eql(0.0)
end end


it "should have segments" do it "should have segments" do
segments = @analysis.segments segments = @analysis.segments
segment = segments.first segment = segments.first


segments.size.should eql(274) segments.size.should eql(339)
segment.start.should eql(0.0) segment.start.should eql(0.0)
segment.duration.should eql(0.43909) segment.duration.should eql(0.10308)
segment.confidence.should eql(1.0) segment.confidence.should eql(0.0)
segment.loudness.time.should eql(0.0) segment.loudness.time.should eql(0.0)
segment.loudness.value.should eql(-60.0) segment.loudness.value.should eql(-60.0)
segment.max_loudness.time.should eql(0.11238) segment.max_loudness.time.should eql(0.07546)
segment.max_loudness.value.should eql(-33.563) segment.max_loudness.value.should eql(-57.86)
segment.pitches.size.should eql(12) segment.pitches.size.should eql(12)
segment.pitches.first.should eql(0.138) segment.pitches.first.should eql(1.0)
segment.timbre.size.should eql(12) segment.timbre.size.should eql(12)
segment.timbre.first.should eql(11.525) segment.timbre.first.should eql(1.178)
end end


it "should have bars" do it "should have bars" do
bars = @analysis.bars bars = @analysis.bars


bars.size.should eql(80) bars.size.should eql(75)
bars.first.start.should eql(1.00704) bars.first.start.should eql(0.14982)
bars.first.duration.should eql(1.48532) bars.first.duration.should eql(1.7004)
bars.first.confidence.should eql(0.188) bars.first.confidence.should eql(0.132)
end end


it "should have tempo" do it "should have tempo" do
@analysis.tempo.should eql(168.460) @analysis.tempo.should eql(151.019)
end end


it "should have sections" do it "should have sections" do
Expand All @@ -53,28 +65,28 @@


sections.size.should eql(7) sections.size.should eql(7)
section.start.should eql(0.0) section.start.should eql(0.0)
section.duration.should eql(20.04271) section.duration.should eql(21.14804)
section.confidence.should eql(1.0) section.confidence.should eql(1.0)
end end


it "should have durtion" do it "should have durtion" do
@analysis.duration.should eql(120.68526) @analysis.duration.should eql(120.68)
end end


it "should have end of fade in" do it "should have end of fade in" do
@analysis.end_of_fade_in.should eql(0.0) @analysis.end_of_fade_in.should eql(0.10308)
end end


it "should have start of fade out" do it "should have start of fade out" do
@analysis.start_of_fade_out.should eql(113.557) @analysis.start_of_fade_out.should eql(115.7863)
end end


it "should have key" do it "should have key" do
@analysis.key.should eql(7) @analysis.key.should eql(7)
end end


it "should have loudness" do it "should have loudness" do
@analysis.loudness.should eql(-19.140) @analysis.loudness.should eql(-18.825)
end end


it "should have mode" do it "should have mode" do
Expand All @@ -88,9 +100,9 @@
it "should have tatums" do it "should have tatums" do
tatums = @analysis.tatums tatums = @analysis.tatums


tatums.size.should eql(648) tatums.size.should eql(601)
tatums.first.start.should eql(0.09469) tatums.first.start.should eql(0.14982)
tatums.first.duration.should eql(0.18193) tatums.first.duration.should eql(0.21743)
tatums.first.confidence.should eql(0.286) tatums.first.confidence.should eql(0.311)
end end
end end
4 changes: 2 additions & 2 deletions spec/fixtures/analysis.json

Large diffs are not rendered by default.

0 comments on commit 6fb0203

Please sign in to comment.