imuzer 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cfeef28b31dedd79ffe26e97ef422b17a81e283a
4
+ data.tar.gz: 32f935c175d2fd389ff948085fb9fd9b50ec8b54
5
+ SHA512:
6
+ metadata.gz: 34fda419761cbd11f5501cdf62ff555d6b49f1d84e114ee8753bb730859ed2923ab73024db248ddee7dae37498556aa46288e723221c88735deb4745b802bc41
7
+ data.tar.gz: 509ef1b1e26dd3490313c9794a90117a2ac581c0f51d4ee561f8b759974d1efcb72b4a1852868461ea0fa7fad34bb187df4ade9230024075cc4b3a96a0025252
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ results.html
3
+ pkg
4
+ html
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in imuzer.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,70 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ imuzer (0.0.1)
5
+ json (~> 1.8.3)
6
+ methadone (~> 1.9.2)
7
+ rainbow (~> 2.1.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ aruba (0.13.0)
13
+ childprocess (~> 0.5.6)
14
+ contracts (~> 0.9)
15
+ cucumber (>= 1.3.19)
16
+ ffi (~> 1.9.10)
17
+ rspec-expectations (>= 2.99)
18
+ thor (~> 0.19)
19
+ builder (3.2.2)
20
+ childprocess (0.5.9)
21
+ ffi (~> 1.0, >= 1.0.11)
22
+ contracts (0.13.0)
23
+ cucumber (2.3.2)
24
+ builder (>= 2.1.2)
25
+ cucumber-core (~> 1.4.0)
26
+ cucumber-wire (~> 0.0.1)
27
+ diff-lcs (>= 1.1.3)
28
+ gherkin (~> 3.2.0)
29
+ multi_json (>= 1.7.5, < 2.0)
30
+ multi_test (>= 0.1.2)
31
+ cucumber-core (1.4.0)
32
+ gherkin (~> 3.2.0)
33
+ cucumber-wire (0.0.1)
34
+ diff-lcs (1.2.5)
35
+ ffi (1.9.10)
36
+ gherkin (3.2.0)
37
+ json (1.8.3)
38
+ methadone (1.9.2)
39
+ bundler
40
+ multi_json (1.11.2)
41
+ multi_test (0.1.2)
42
+ rainbow (2.1.0)
43
+ rake (10.5.0)
44
+ rdoc (4.2.2)
45
+ json (~> 1.4)
46
+ rspec (3.4.0)
47
+ rspec-core (~> 3.4.0)
48
+ rspec-expectations (~> 3.4.0)
49
+ rspec-mocks (~> 3.4.0)
50
+ rspec-core (3.4.3)
51
+ rspec-support (~> 3.4.0)
52
+ rspec-expectations (3.4.0)
53
+ diff-lcs (>= 1.2.0, < 2.0)
54
+ rspec-support (~> 3.4.0)
55
+ rspec-mocks (3.4.1)
56
+ diff-lcs (>= 1.2.0, < 2.0)
57
+ rspec-support (~> 3.4.0)
58
+ rspec-support (3.4.1)
59
+ thor (0.19.1)
60
+
61
+ PLATFORMS
62
+ ruby
63
+
64
+ DEPENDENCIES
65
+ aruba
66
+ bundler (~> 1.7)
67
+ imuzer!
68
+ rake (~> 10.0)
69
+ rdoc
70
+ rspec (~> 3)
data/LICENSE.txt ADDED
@@ -0,0 +1 @@
1
+
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Imuzer
2
+
3
+ imuzer is a minimalistic gem that lets you generate music from the online music generation platform imuze.io.
4
+
5
+ # Pre-requisits
6
+
7
+ * You will need an account on iMuze in order to use it.
8
+ * You will need to install `mpg123` to actually listen the mp3
9
+
10
+ ## Installation
11
+
12
+ $ gem install imuzer
13
+
14
+ ## Usage
15
+
16
+ [yacin@mac imuzer (master)]$ bundle exec bin/imuzer -h
17
+ Usage: imuzer [options] duration genre subgenre structure
18
+
19
+ Composes a track with iMuze
20
+
21
+ v0.0.1
22
+
23
+ Options:
24
+ -h, --help Show command line help
25
+ -e, --email email your imuze account email
26
+ -p, --password password your imuze password
27
+ -v, --verbose Be verbose
28
+ --version Show help/version info
29
+ --log-level LEVEL Set the logging level
30
+ (debug|info|warn|error|fatal)
31
+ (Default: info)
32
+
33
+ Arguments:
34
+
35
+ duration
36
+ Track duration
37
+ genre
38
+ Track genre
39
+ subgenre
40
+ Track subgenre
41
+ structure
42
+ Track structure
43
+
44
+ Bellow is an example on how to use the tool:
45
+
46
+ bundle exec bin/imuzer -v -e beguelin@gmail.com -p cH5tRaXu 30000 edm soft 'calm:0.3,medium:0.3,dynamic:0.3'
47
+
48
+ ## Contributing
49
+
50
+ 1. Fork it ( https://github.com/[my-github-username]/imuzer/fork )
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create a new Pull Request
data/README.rdoc ADDED
@@ -0,0 +1,23 @@
1
+ = imuzer - DESCRIBE YOUR GEM
2
+
3
+ Author:: Yacin Bahi (yacin@imuze.io)
4
+ Copyright:: Copyright (c) 2016 iMuze Inc.
5
+
6
+
7
+ License:: INSERT LICENSE HERE
8
+
9
+
10
+
11
+ DESCRIBE YOUR GEM HERE
12
+
13
+ == Links
14
+
15
+ * {Source on Github}[LINK TO GITHUB]
16
+ * RDoc[LINK TO RDOC.INFO]
17
+
18
+ == Install
19
+
20
+ == Examples
21
+
22
+ == Contributing
23
+
data/Rakefile ADDED
@@ -0,0 +1,66 @@
1
+ def dump_load_path
2
+ puts $LOAD_PATH.join("\n")
3
+ found = nil
4
+ $LOAD_PATH.each do |path|
5
+ if File.exists?(File.join(path,"rspec"))
6
+ puts "Found rspec in #{path}"
7
+ if File.exists?(File.join(path,"rspec","core"))
8
+ puts "Found core"
9
+ if File.exists?(File.join(path,"rspec","core","rake_task"))
10
+ puts "Found rake_task"
11
+ found = path
12
+ else
13
+ puts "!! no rake_task"
14
+ end
15
+ else
16
+ puts "!!! no core"
17
+ end
18
+ end
19
+ end
20
+ if found.nil?
21
+ puts "Didn't find rspec/core/rake_task anywhere"
22
+ else
23
+ puts "Found in #{path}"
24
+ end
25
+ end
26
+ require 'bundler'
27
+ require 'rake/clean'
28
+
29
+ begin
30
+ require 'rspec/core/rake_task'
31
+ rescue LoadError
32
+ dump_load_path
33
+ raise
34
+ end
35
+
36
+ require 'cucumber'
37
+ require 'cucumber/rake/task'
38
+ gem 'rdoc' # we need the installed RDoc gem, not the system one
39
+ require 'rdoc/task'
40
+
41
+ include Rake::DSL
42
+
43
+ Bundler::GemHelper.install_tasks
44
+
45
+
46
+ RSpec::Core::RakeTask.new do |t|
47
+ # Put spec opts in a file named .rspec in root
48
+ end
49
+
50
+
51
+ CUKE_RESULTS = 'results.html'
52
+ CLEAN << CUKE_RESULTS
53
+ Cucumber::Rake::Task.new(:features) do |t|
54
+ t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty --no-source -x"
55
+ t.fork = false
56
+ end
57
+
58
+ Rake::RDocTask.new do |rd|
59
+
60
+ rd.main = "README.rdoc"
61
+
62
+ rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
63
+ end
64
+
65
+ task :default => [:spec,:features]
66
+
data/bin/imuzer ADDED
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'methadone'
5
+ require 'imuzer.rb'
6
+ require 'json'
7
+ require 'rainbow'
8
+
9
+ class App
10
+ include Methadone::Main
11
+ include Methadone::CLILogging
12
+
13
+ main do |duration, genre, subgenre, structure|
14
+ info 'Authenticating to iMuze ....'
15
+ response = Imuze::CreateToken.call(options[:email], options[:password])
16
+ formated_json = JSON.pretty_generate(response)
17
+ if response['status'] == 500
18
+ puts Rainbow(formated_json).red
19
+ exit
20
+ else
21
+ puts Rainbow(formated_json).green if options[:verbose]
22
+ end
23
+
24
+ token = response['token']
25
+ info "Composing your track \"#{subgenre}\" \"#{genre}\" on iMuze .... please wait"
26
+ start = Time.now
27
+ response = Imuze::CreateMusic.call(token, duration,
28
+ genre, subgenre, structure)
29
+
30
+ formated_json = JSON.pretty_generate(response)
31
+ if response['status'] == 500
32
+ puts Rainbow(formated_json).red
33
+ exit
34
+ else
35
+ puts Rainbow(formated_json).green if options[:verbose]
36
+ end
37
+
38
+ elapsed = Time.now - start
39
+ info "Done composing your music in #{elapsed} seconds"
40
+ mp3_uri = response['mp3_uri']
41
+ info "Playing your \"#{subgenre}\" \"#{genre}\" mp3 from iMuze ...."
42
+ Imuze::GetMusic.call(token, mp3_uri)
43
+ end
44
+
45
+ on('-e email','--email','your imuze account email')
46
+ on('-p password','--password','your imuze password')
47
+ on('-v','--verbose','Be verbose')
48
+
49
+ version Imuzer::VERSION
50
+ description 'Composes a track with iMuze'
51
+ arg :duration, 'Track duration'
52
+ arg :genre, 'Track genre'
53
+ arg :subgenre, 'Track subgenre'
54
+ arg :structure, 'Track structure'
55
+ use_log_level_option toggle_debug_on_signal: 'USR1'
56
+ go!
57
+ end
@@ -0,0 +1,13 @@
1
+ Feature: My bootstrapped app kinda works
2
+ In order to get going on coding my awesome app
3
+ I want to have aruba and cucumber setup
4
+ So I don't have to do it myself
5
+
6
+ Scenario: App just runs
7
+ When I get help for "imuzer"
8
+ Then the exit status should be 0
9
+ And the banner should be present
10
+ And the banner should document that this app takes options
11
+ And the following options should be documented:
12
+ |--version|
13
+ And the banner should document that this app takes no arguments
@@ -0,0 +1 @@
1
+ # Put your step definitions here
@@ -0,0 +1,16 @@
1
+ require 'aruba/cucumber'
2
+ require 'methadone/cucumber'
3
+
4
+ ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
5
+ LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
6
+
7
+ Before do
8
+ # Using "announce" causes massive warnings on 1.9.2
9
+ @puts = true
10
+ @original_rubylib = ENV['RUBYLIB']
11
+ ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
12
+ end
13
+
14
+ After do
15
+ ENV['RUBYLIB'] = @original_rubylib
16
+ end
data/imuzer.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'imuzer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "imuzer"
8
+ spec.version = Imuzer::VERSION
9
+ spec.authors = ["Yacin Bahi"]
10
+ spec.email = ["yacin@imuze.io"]
11
+ spec.summary = %q{Generate music with iMuze.}
12
+ spec.description = %q{This gem uses the iMuze (imuze.io) API to generate music. You'll need an account on iMuze.io in order to use it.}
13
+ spec.homepage = ""
14
+ spec.license = "custom"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency('rdoc')
24
+ spec.add_development_dependency('aruba')
25
+ spec.add_development_dependency('rspec', '~> 3')
26
+
27
+ spec.add_dependency('methadone', '~> 1.9.2')
28
+ spec.add_dependency('json', '~> 1.8.3')
29
+ spec.add_dependency('rainbow', '~> 2.1.0')
30
+ end
@@ -0,0 +1,60 @@
1
+ module Imuze
2
+ class CreateMusic < Struct.new(:token, :duration, :genre, :subgenre, :structure)
3
+ require 'uri'
4
+ require 'net/http'
5
+ require 'json'
6
+
7
+ def self.call(*args)
8
+ new(*args).call
9
+ end
10
+
11
+ def call
12
+ response = http.request(put_request)
13
+ JSON.parse(response.read_body)
14
+ end
15
+
16
+ private
17
+
18
+ def url
19
+ @url ||= URI('http://joplin.imuze.io/musics')
20
+ end
21
+
22
+ def http
23
+ @http ||= Net::HTTP.new(url.host, url.port)
24
+ end
25
+
26
+ def put_request
27
+ request = Net::HTTP::Post.new(url)
28
+ request['content-type'] = 'application/json'
29
+ request['authorization'] = token
30
+ request['cache-control'] = 'no-cache'
31
+ request.body = request_body
32
+ request
33
+ end
34
+
35
+ def request_body
36
+ {
37
+ genre: genre,
38
+ subgenre: subgenre,
39
+ duration_ms: duration.to_i,
40
+ structure: music_structure
41
+ }.to_json
42
+ end
43
+
44
+ def music_structure
45
+ array = []
46
+ time = 0.0
47
+ structure.split(',').each do |mov|
48
+ type, duration = mov.split(':')
49
+ hash = {
50
+ energy: type,
51
+ start: time.to_f,
52
+ duration: duration.to_f
53
+ }
54
+ array << hash
55
+ time += duration.to_f
56
+ end
57
+ array
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,41 @@
1
+ module Imuze
2
+ class CreateToken < Struct.new(:email, :password)
3
+ require 'uri'
4
+ require 'net/http'
5
+ require 'json'
6
+
7
+ def self.call(*args)
8
+ new(*args).call
9
+ end
10
+
11
+ def call
12
+ response = http.request(put_request)
13
+ JSON.parse(response.read_body)
14
+ end
15
+
16
+ private
17
+
18
+ def url
19
+ @url ||= URI('http://joplin.imuze.io/accounts/token')
20
+ end
21
+
22
+ def http
23
+ @http ||= Net::HTTP.new(url.host, url.port)
24
+ end
25
+
26
+ def put_request
27
+ request = Net::HTTP::Put.new(url)
28
+ request['content-type'] = 'application/json'
29
+ request['cache-control'] = 'no-cache'
30
+ request.body = request_body
31
+ request
32
+ end
33
+
34
+ def request_body
35
+ {
36
+ email: email,
37
+ password: password
38
+ }.to_json
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,24 @@
1
+ module Imuze
2
+ class GetMusic < Struct.new(:token, :mp3_uri)
3
+ include Methadone::CLILogging
4
+ include Methadone::SH
5
+ require 'uri'
6
+ require 'net/http'
7
+ require 'json'
8
+
9
+ def self.call(*args)
10
+ new(*args).call
11
+ end
12
+
13
+ def call
14
+ sh command do |stdout, stderr|
15
+ puts 'We hope you liked it !'
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def command
22
+ %Q(curl "http:#{mp3_uri}" -s -H "Content-Type: application/json" -H "Authorization: #{token}" | mpg123 - 2> /dev/null) end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Imuzer
2
+ VERSION = "0.0.1"
3
+ end
data/lib/imuzer.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'imuzer/version'
2
+ require 'imuze/create_token'
3
+ require 'imuze/create_music'
4
+ require 'imuze/get_music'
5
+
6
+ module Imuzer
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,5 @@
1
+ describe "TestSomething" do
2
+ it "should be true" do
3
+ expect(true).to eq(true)
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: imuzer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yacin Bahi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rdoc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: aruba
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: methadone
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.9.2
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.9.2
97
+ - !ruby/object:Gem::Dependency
98
+ name: json
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.8.3
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.8.3
111
+ - !ruby/object:Gem::Dependency
112
+ name: rainbow
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 2.1.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 2.1.0
125
+ description: This gem uses the iMuze (imuze.io) API to generate music. You'll need
126
+ an account on iMuze.io in order to use it.
127
+ email:
128
+ - yacin@imuze.io
129
+ executables:
130
+ - imuzer
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - ".gitignore"
135
+ - Gemfile
136
+ - Gemfile.lock
137
+ - LICENSE.txt
138
+ - README.md
139
+ - README.rdoc
140
+ - Rakefile
141
+ - bin/imuzer
142
+ - features/imuzer.feature
143
+ - features/step_definitions/imuzer_steps.rb
144
+ - features/support/env.rb
145
+ - imuzer.gemspec
146
+ - lib/imuze/create_music.rb
147
+ - lib/imuze/create_token.rb
148
+ - lib/imuze/get_music.rb
149
+ - lib/imuzer.rb
150
+ - lib/imuzer/version.rb
151
+ - spec/something_spec.rb
152
+ homepage: ''
153
+ licenses:
154
+ - custom
155
+ metadata: {}
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 2.4.3
173
+ signing_key:
174
+ specification_version: 4
175
+ summary: Generate music with iMuze.
176
+ test_files:
177
+ - features/imuzer.feature
178
+ - features/step_definitions/imuzer_steps.rb
179
+ - features/support/env.rb
180
+ - spec/something_spec.rb