imuzer 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cfeef28b31dedd79ffe26e97ef422b17a81e283a
4
- data.tar.gz: 32f935c175d2fd389ff948085fb9fd9b50ec8b54
3
+ metadata.gz: a68ce8613fe16537351c9044ca646fbc10041de9
4
+ data.tar.gz: 259522091d5b725f52a800bcb7bc734bee4b1150
5
5
  SHA512:
6
- metadata.gz: 34fda419761cbd11f5501cdf62ff555d6b49f1d84e114ee8753bb730859ed2923ab73024db248ddee7dae37498556aa46288e723221c88735deb4745b802bc41
7
- data.tar.gz: 509ef1b1e26dd3490313c9794a90117a2ac581c0f51d4ee561f8b759974d1efcb72b4a1852868461ea0fa7fad34bb187df4ade9230024075cc4b3a96a0025252
6
+ metadata.gz: bde532ec27f9b9ee0412e9398677f98d55d23b63c5984c414dd3bab001478f13a270d4cedad1b1be73bb6728ef6420bc775f535ce81b1f74238ae0586f225e4d
7
+ data.tar.gz: b0f479ec10dafe3fb2db0d25d293b765e0c5b82d525fd628ede90eed315d82e678f57f0394b309865c4ac924e9ffcb04185aa8d01130db3ebc47e530488a4811
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- imuzer (0.0.1)
4
+ imuzer (0.0.2)
5
+ gli (= 2.13.4)
5
6
  json (~> 1.8.3)
6
7
  methadone (~> 1.9.2)
7
8
  rainbow (~> 2.1.0)
@@ -9,7 +10,7 @@ PATH
9
10
  GEM
10
11
  remote: https://rubygems.org/
11
12
  specs:
12
- aruba (0.13.0)
13
+ aruba (0.14.0)
13
14
  childprocess (~> 0.5.6)
14
15
  contracts (~> 0.9)
15
16
  cucumber (>= 1.3.19)
@@ -34,6 +35,7 @@ GEM
34
35
  diff-lcs (1.2.5)
35
36
  ffi (1.9.10)
36
37
  gherkin (3.2.0)
38
+ gli (2.13.4)
37
39
  json (1.8.3)
38
40
  methadone (1.9.2)
39
41
  bundler
@@ -68,3 +70,6 @@ DEPENDENCIES
68
70
  rake (~> 10.0)
69
71
  rdoc
70
72
  rspec (~> 3)
73
+
74
+ BUNDLED WITH
75
+ 1.11.2
data/README.md CHANGED
@@ -13,7 +13,8 @@ imuzer is a minimalistic gem that lets you generate music from the online music
13
13
 
14
14
  ## Usage
15
15
 
16
- [yacin@mac imuzer (master)]$ bundle exec bin/imuzer -h
16
+ [yacin@mac imuzer (master)]$ imuzer -h
17
+
17
18
  Usage: imuzer [options] duration genre subgenre structure
18
19
 
19
20
  Composes a track with iMuze
@@ -43,7 +44,7 @@ imuzer is a minimalistic gem that lets you generate music from the online music
43
44
 
44
45
  Bellow is an example on how to use the tool:
45
46
 
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
+ [yacin@mac imuzer (master)]$ imuzer -v -e MYEMAIL -p MYPASSWORD 30000 edm soft 'calm:0.3,medium:0.3,dynamic:0.3'
47
48
 
48
49
  ## Contributing
49
50
 
data/bin/imuzer CHANGED
@@ -1,57 +1,78 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'optparse'
3
+ require 'gli'
4
4
  require 'methadone'
5
5
  require 'imuzer.rb'
6
6
  require 'json'
7
7
  require 'rainbow'
8
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]
9
+ include GLI::App
10
+ program_desc 'a demo tool for iMuze API'
11
+
12
+ desc 'Be verbose'
13
+ switch [:v, :verbose]
14
+
15
+ desc 'Email from your iMuze user account'
16
+ arg_name 'email'
17
+ flag [:e, :email]
18
+
19
+ desc 'Password from your iMuze user account'
20
+ arg_name 'password'
21
+ flag [:p, :password]
22
+
23
+ desc 'list all musical genres and subgenres'
24
+ command :genres do |c|
25
+ puts 'Listing iMuze musical genres with sub-genres...'
26
+ c.action do |global_options, options, args|
27
+ response = Imuze::GetGenres.call global_options
28
+ response['genres'].each do |genre|
29
+ print " #{genre['name']}: "
30
+ genre['subgenres'].each{|sg| print Rainbow("#{sg}, ").bright}
31
+ puts
22
32
  end
33
+ end
34
+ end
23
35
 
36
+ desc 'composes a music'
37
+ arg 'genre', :required
38
+ arg 'subgenre', :required
39
+ arg 'duration', :required
40
+ arg 'structure', :required
41
+ command :compose do |c|
42
+ c.switch [:c, :crop]
43
+ c.flag 'fadeout_ms', arg_name: 'fadeout_ms',
44
+ type: Integer,
45
+ desc: 'fadeout in milliseconds'
46
+ c.flag 'voices_volume', arg_name: 'voices_volume',
47
+ type: Integer,
48
+ desc: 'volume of voice track'
49
+
50
+ c.action do |global_options, options, args|
51
+ help_now!('credentials required to compose music') if global_options[:email].nil? || global_options[:password].nil?
52
+ help_now!('id is required') if args.size < 3
53
+ genre = args[0]
54
+ subgenre = args[1]
55
+ duration = args[2]
56
+ structure = args[3]
57
+ puts 'Authenticating to iMuze ....'
58
+ response = Imuze::CreateToken.call global_options[:email],
59
+ global_options[:password]
60
+ FormatResponse.call response, options
24
61
  token = response['token']
25
- info "Composing your track \"#{subgenre}\" \"#{genre}\" on iMuze .... please wait"
62
+ music = "\"#{subgenre}\" \"#{genre}\""
63
+ puts "Composing your track #{music} on iMuze .... please wait"
26
64
  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
-
65
+ response = Imuze::CreateMusic.call token,
66
+ duration,
67
+ genre, subgenre, structure,
68
+ options
69
+ FormatResponse.call response, global_options
38
70
  elapsed = Time.now - start
39
- info "Done composing your music in #{elapsed} seconds"
71
+ puts "Done composing your music in #{elapsed} seconds"
40
72
  mp3_uri = response['mp3_uri']
41
- info "Playing your \"#{subgenre}\" \"#{genre}\" mp3 from iMuze ...."
42
- Imuze::GetMusic.call(token, mp3_uri)
73
+ puts "Playing your #{music} mp3 from iMuze ...."
74
+ Imuze::GetMusic.call token, mp3_uri
43
75
  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
76
  end
77
+
78
+ exit run(ARGV)
data/imuzer.gemspec CHANGED
@@ -4,27 +4,28 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'imuzer/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "imuzer"
7
+ spec.name = 'imuzer'
8
8
  spec.version = Imuzer::VERSION
9
- spec.authors = ["Yacin Bahi"]
10
- spec.email = ["yacin@imuze.io"]
9
+ spec.authors = ['Yacin Bahi']
10
+ spec.email = ['yacin@imuze.io']
11
11
  spec.summary = %q{Generate music with iMuze.}
12
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"
13
+ spec.homepage = 'https://rubygems.org/gems/imuzer'
14
+ spec.license = 'custom'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.7"
22
- spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
23
  spec.add_development_dependency('rdoc')
24
24
  spec.add_development_dependency('aruba')
25
25
  spec.add_development_dependency('rspec', '~> 3')
26
26
 
27
27
  spec.add_dependency('methadone', '~> 1.9.2')
28
+ spec.add_dependency('gli', '2.13.4')
28
29
  spec.add_dependency('json', '~> 1.8.3')
29
30
  spec.add_dependency('rainbow', '~> 2.1.0')
30
31
  end
@@ -0,0 +1,16 @@
1
+ class FormatResponse < Struct.new(:response, :options)
2
+
3
+ def self.call(*args)
4
+ new(*args).call
5
+ end
6
+
7
+ def call
8
+ formated_json = JSON.pretty_generate(response)
9
+ if response['status'] == 500 || response['status'] == 403
10
+ puts Rainbow(formated_json).red
11
+ exit
12
+ else
13
+ puts Rainbow(formated_json).green if options[:verbose]
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,5 @@
1
1
  module Imuze
2
- class CreateMusic < Struct.new(:token, :duration, :genre, :subgenre, :structure)
2
+ class CreateMusic < Struct.new(:token, :duration, :genre, :subgenre, :structure, :options)
3
3
  require 'uri'
4
4
  require 'net/http'
5
5
  require 'json'
@@ -33,12 +33,28 @@ module Imuze
33
33
  end
34
34
 
35
35
  def request_body
36
- {
36
+ hash = {
37
37
  genre: genre,
38
38
  subgenre: subgenre,
39
39
  duration_ms: duration.to_i,
40
40
  structure: music_structure
41
- }.to_json
41
+ }
42
+ hash.merge!(crop: crop) if crop
43
+ hash.merge!(fadeout_ms: fadeout_ms) if fadeout_ms
44
+ hash.merge!(voices_volume: voices_volume) if voices_volume
45
+ hash.to_json
46
+ end
47
+
48
+ def crop
49
+ options.nil? ? nil : options[:crop]
50
+ end
51
+
52
+ def fadeout_ms
53
+ options.nil? ? nil : options[:fadeout_ms]
54
+ end
55
+
56
+ def voices_volume
57
+ options.nil? ? nil : options[:voices_volume]
42
58
  end
43
59
 
44
60
  def music_structure
@@ -0,0 +1,33 @@
1
+ module Imuze
2
+ class GetGenres < Struct.new(:global_options)
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(get_request)
13
+ JSON.parse(response.read_body)
14
+ end
15
+
16
+ private
17
+
18
+ def url
19
+ @url ||= URI('http://joplin.imuze.io/genres')
20
+ end
21
+
22
+ def http
23
+ @http ||= Net::HTTP.new(url.host, url.port)
24
+ end
25
+
26
+ def get_request
27
+ request = Net::HTTP::Get.new(url)
28
+ request['content-type'] = 'application/json'
29
+ request['cache-control'] = 'no-cache'
30
+ request
31
+ end
32
+ end
33
+ end
@@ -19,6 +19,7 @@ module Imuze
19
19
  private
20
20
 
21
21
  def command
22
- %Q(curl "http:#{mp3_uri}" -s -H "Content-Type: application/json" -H "Authorization: #{token}" | mpg123 - 2> /dev/null) end
22
+ %Q(curl "http:#{mp3_uri}" -s -H "Content-Type: application/json" -H "Authorization: #{token}" | mpg123 - 2> /dev/null)
23
+ end
23
24
  end
24
25
  end
@@ -1,3 +1,3 @@
1
1
  module Imuzer
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
3
3
  end
data/lib/imuzer.rb CHANGED
@@ -2,6 +2,8 @@ require 'imuzer/version'
2
2
  require 'imuze/create_token'
3
3
  require 'imuze/create_music'
4
4
  require 'imuze/get_music'
5
+ require 'imuze/get_genres'
6
+ require 'format_response'
5
7
 
6
8
  module Imuzer
7
9
  # Your code goes here...
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imuzer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yacin Bahi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-11 00:00:00.000000000 Z
11
+ date: 2016-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 1.9.2
97
+ - !ruby/object:Gem::Dependency
98
+ name: gli
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 2.13.4
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 2.13.4
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: json
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -143,13 +157,15 @@ files:
143
157
  - features/step_definitions/imuzer_steps.rb
144
158
  - features/support/env.rb
145
159
  - imuzer.gemspec
160
+ - lib/format_response.rb
146
161
  - lib/imuze/create_music.rb
147
162
  - lib/imuze/create_token.rb
163
+ - lib/imuze/get_genres.rb
148
164
  - lib/imuze/get_music.rb
149
165
  - lib/imuzer.rb
150
166
  - lib/imuzer/version.rb
151
167
  - spec/something_spec.rb
152
- homepage: ''
168
+ homepage: https://rubygems.org/gems/imuzer
153
169
  licenses:
154
170
  - custom
155
171
  metadata: {}
@@ -169,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
185
  version: '0'
170
186
  requirements: []
171
187
  rubyforge_project:
172
- rubygems_version: 2.4.3
188
+ rubygems_version: 2.6.2
173
189
  signing_key:
174
190
  specification_version: 4
175
191
  summary: Generate music with iMuze.