scissor-echonest 0.0.8 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/examples/afromb.rb +8 -16
- data/lib/scissor/echonest.rb +21 -11
- data/spec/scissor-echonest_spec.rb +10 -0
- metadata +3 -3
data/Rakefile
CHANGED
@@ -21,7 +21,7 @@ DESCRIPTION = "Scissor extension to use Echo Nest Developers API"
|
|
21
21
|
RUBYFORGE_PROJECT = "scissorechonest"
|
22
22
|
HOMEPATH = "http://github.com/youpy/scissor-echonest"
|
23
23
|
BIN_FILES = %w( )
|
24
|
-
VERS = "0.0
|
24
|
+
VERS = "0.1.0"
|
25
25
|
|
26
26
|
REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
|
27
27
|
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
|
data/examples/afromb.rb
CHANGED
@@ -11,18 +11,12 @@
|
|
11
11
|
require 'rubygems'
|
12
12
|
require 'scissor/echonest'
|
13
13
|
require 'narray'
|
14
|
-
|
15
|
-
Scissor.logger.level = Logger::DEBUG
|
16
|
-
|
14
|
+
|
17
15
|
class AfromB
|
18
16
|
def initialize(a, b = nil)
|
19
17
|
@a, @b = [a, b || a]
|
20
18
|
|
21
|
-
@segments_of_a = @a.
|
22
|
-
memo += Scissor(file).segments
|
23
|
-
memo
|
24
|
-
end
|
25
|
-
|
19
|
+
@segments_of_a = Scissor(@a).segments
|
26
20
|
@segments_of_b = (@a == @b) ? @segments_of_a : Scissor(@b).segments
|
27
21
|
end
|
28
22
|
|
@@ -73,23 +67,21 @@ class AfromB
|
|
73
67
|
Scissor.join(result)
|
74
68
|
end
|
75
69
|
end
|
76
|
-
|
70
|
+
|
77
71
|
if __FILE__ == $0
|
78
72
|
require 'pit'
|
79
|
-
|
73
|
+
|
80
74
|
Scissor.echonest_api_key = Pit.get('echonest.com', :require => {
|
81
75
|
'api_key' => 'your Echo Nest API key'
|
82
76
|
})['api_key']
|
83
77
|
Scissor::Chunk.echonest.user_agent.send_timeout = 300
|
84
78
|
|
85
|
-
if ARGV.size ==
|
79
|
+
if ARGV.size == 3
|
80
|
+
a, b, outfile = ARGV
|
81
|
+
else
|
86
82
|
a, outfile = ARGV
|
87
83
|
b = a
|
88
|
-
else
|
89
|
-
a = ARGV
|
90
|
-
outfile = a.pop
|
91
|
-
b = a.pop
|
92
84
|
end
|
93
85
|
|
94
|
-
AfromB.new(a, b).run
|
86
|
+
AfromB.new(a, b).run >> outfile
|
95
87
|
end
|
data/lib/scissor/echonest.rb
CHANGED
@@ -16,12 +16,22 @@ module Scissor
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
def bars
|
20
|
+
analyze do |analysis|
|
21
|
+
bars = analysis.bars
|
22
|
+
bars.inject([]) do |chunks, bar|
|
23
|
+
chunk = self[bar.start, bar.duration]
|
24
|
+
chunk.set_delegate(bar)
|
25
|
+
chunks << chunk
|
26
|
+
chunks
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
19
31
|
def beats
|
20
|
-
|
32
|
+
analyze do |analysis|
|
21
33
|
chunks = []
|
22
|
-
|
23
|
-
|
24
|
-
beats = self.class.echonest.get_beats(tmpfile)
|
34
|
+
beats = analysis.beats
|
25
35
|
|
26
36
|
if beats.size != 0
|
27
37
|
chunk = self[0, beats.first.start]
|
@@ -42,10 +52,8 @@ module Scissor
|
|
42
52
|
end
|
43
53
|
|
44
54
|
def segments
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
segments = self.class.echonest.get_segments(tmpfile)
|
55
|
+
analyze do |analysis|
|
56
|
+
segments = analysis.segments
|
49
57
|
segments.inject([]) do |chunks, segment|
|
50
58
|
chunk = self[segment.start, segment.duration]
|
51
59
|
chunk.set_delegate(segment)
|
@@ -57,11 +65,13 @@ module Scissor
|
|
57
65
|
|
58
66
|
private
|
59
67
|
|
60
|
-
def
|
68
|
+
def analyze
|
61
69
|
tmpfile = Pathname.new('/tmp/scissor_echonest_temp_' + $$.to_s + '.mp3')
|
62
|
-
|
70
|
+
scissor = to_file(tmpfile, :bitrate => '64k')
|
71
|
+
|
72
|
+
yield self.class.echonest.track.analysis(tmpfile)
|
63
73
|
ensure
|
64
|
-
tmpfile.unlink
|
74
|
+
tmpfile.unlink if tmpfile.exist?
|
65
75
|
end
|
66
76
|
end
|
67
77
|
end
|
@@ -34,6 +34,16 @@ describe Scissor do
|
|
34
34
|
Scissor::Chunk.stub!(:echonest).and_return(api)
|
35
35
|
end
|
36
36
|
|
37
|
+
it 'should get bars' do
|
38
|
+
bars = @scissor.bars
|
39
|
+
bar = bars.first
|
40
|
+
|
41
|
+
bars.size.should eql(80)
|
42
|
+
bar.start.should be_close(1.0, 0.1)
|
43
|
+
bar.duration.should be_close(1.48, 0.01)
|
44
|
+
bar.confidence.should be_close(0.18, 0.01)
|
45
|
+
end
|
46
|
+
|
37
47
|
it 'should get beats' do
|
38
48
|
beats = @scissor.beats
|
39
49
|
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 0.0.8
|
9
|
+
version: 0.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- youpy
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2011-11-01 00:00:00 +09:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|