imuzer 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a68ce8613fe16537351c9044ca646fbc10041de9
4
- data.tar.gz: 259522091d5b725f52a800bcb7bc734bee4b1150
3
+ metadata.gz: f60d92779e8bceab0ac1f98f86797bd008bd1ed9
4
+ data.tar.gz: 70810d9b916f35483cf47db657d926ce57bd5e83
5
5
  SHA512:
6
- metadata.gz: bde532ec27f9b9ee0412e9398677f98d55d23b63c5984c414dd3bab001478f13a270d4cedad1b1be73bb6728ef6420bc775f535ce81b1f74238ae0586f225e4d
7
- data.tar.gz: b0f479ec10dafe3fb2db0d25d293b765e0c5b82d525fd628ede90eed315d82e678f57f0394b309865c4ac924e9ffcb04185aa8d01130db3ebc47e530488a4811
6
+ metadata.gz: 74426b2fe5a9649f6c8a26d7790bb3e82115f047bfb26558ea234722526fc18d2cf53abe5b92443938dd2df695fff997a4695d51ebe70dadc2f6888f0e0e7af2
7
+ data.tar.gz: 50235a18ef3500e9b4730c1793298946a56aa908b6a1a8c63ac4d43e65f4905e87993704ab8be52c15e2b88562aefac6de117c05abbe1d367fdcc9d411bb1eba
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- imuzer (0.0.2)
4
+ imuzer (0.0.3)
5
5
  gli (= 2.13.4)
6
6
  json (~> 1.8.3)
7
7
  methadone (~> 1.9.2)
data/bin/imuzer CHANGED
@@ -8,6 +8,7 @@ require 'rainbow'
8
8
 
9
9
  include GLI::App
10
10
  program_desc 'a demo tool for iMuze API'
11
+ long_desc 'iMuzer is a tool that lets you interact with the music composition platform iMuze.io. You will need an account on iMuze.io in order to use the API. Email us at developers@imuze.io to get a developer account. You will need to have wget, curl and mpg123 installed on your computer to use all the feature of this tool.'
11
12
 
12
13
  desc 'Be verbose'
13
14
  switch [:v, :verbose]
@@ -22,8 +23,8 @@ flag [:p, :password]
22
23
 
23
24
  desc 'list all musical genres and subgenres'
24
25
  command :genres do |c|
25
- puts 'Listing iMuze musical genres with sub-genres...'
26
26
  c.action do |global_options, options, args|
27
+ puts 'Listing iMuze musical genres with sub-genres...'
27
28
  response = Imuze::GetGenres.call global_options
28
29
  response['genres'].each do |genre|
29
30
  print " #{genre['name']}: "
@@ -40,6 +41,7 @@ arg 'duration', :required
40
41
  arg 'structure', :required
41
42
  command :compose do |c|
42
43
  c.switch [:c, :crop]
44
+ c.switch [:d, :download]
43
45
  c.flag 'fadeout_ms', arg_name: 'fadeout_ms',
44
46
  type: Integer,
45
47
  desc: 'fadeout in milliseconds'
@@ -50,6 +52,10 @@ command :compose do |c|
50
52
  c.action do |global_options, options, args|
51
53
  help_now!('credentials required to compose music') if global_options[:email].nil? || global_options[:password].nil?
52
54
  help_now!('id is required') if args.size < 3
55
+ help_now!('You need wget installed on your computer to continue') unless FindExecutable.call('wget')
56
+ exit_now!('You need curl installed on your computer to continue') unless FindExecutable.call('curl')
57
+ exit_now!('You need mpg123 installed on your computer to continue') unless FindExecutable.call('mpg123')
58
+ exit_now!('You need mpg123 installed on your computer to continue') unless FindExecutable.call('mpg123')
53
59
  genre = args[0]
54
60
  subgenre = args[1]
55
61
  duration = args[2]
@@ -71,7 +77,7 @@ command :compose do |c|
71
77
  puts "Done composing your music in #{elapsed} seconds"
72
78
  mp3_uri = response['mp3_uri']
73
79
  puts "Playing your #{music} mp3 from iMuze ...."
74
- Imuze::GetMusic.call token, mp3_uri
80
+ Imuze::GetMusic.call token, mp3_uri, options
75
81
  end
76
82
  end
77
83
 
@@ -0,0 +1,25 @@
1
+ class FindExecutable < Struct.new(:executable)
2
+
3
+ def self.call(*args)
4
+ new(*args).call
5
+ end
6
+
7
+ def call
8
+ which(executable)
9
+ end
10
+
11
+ private
12
+ # Cross-platform way of finding an executable in the $PATH.
13
+ #
14
+ # which('ruby') #=> /usr/bin/ruby
15
+ def which(cmd)
16
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
17
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
18
+ exts.each { |ext|
19
+ exe = File.join(path, "#{cmd}#{ext}")
20
+ return exe if File.executable?(exe) && !File.directory?(exe)
21
+ }
22
+ end
23
+ nil
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  module Imuze
2
- class GetMusic < Struct.new(:token, :mp3_uri)
2
+ class GetMusic < Struct.new(:token, :mp3_uri, :options)
3
3
  include Methadone::CLILogging
4
4
  include Methadone::SH
5
5
  require 'uri'
@@ -11,15 +11,32 @@ module Imuze
11
11
  end
12
12
 
13
13
  def call
14
+ download? ? command_download : command_play
15
+ end
16
+
17
+ private
18
+
19
+ def command_play
20
+ command = %Q(curl "http:#{mp3_uri}" -s -H "Content-Type: application/json" -H "Authorization: #{token}" | mpg123 - 2> /dev/null)
14
21
  sh command do |stdout, stderr|
15
22
  puts 'We hope you liked it !'
16
23
  end
17
24
  end
18
25
 
19
- private
26
+ def command_download
27
+ command = %Q(wget "http:#{mp3_uri}" -O #{mp3_id}.mp3)
28
+ sh command do |stdout, stderr|
29
+ puts 'We hope you liked it !'
30
+ end
31
+ end
32
+
33
+ def download?
34
+ options.nil? ? false : options[:download]
35
+ end
20
36
 
21
- def command
22
- %Q(curl "http:#{mp3_uri}" -s -H "Content-Type: application/json" -H "Authorization: #{token}" | mpg123 - 2> /dev/null)
37
+ def mp3_id
38
+ puts mp3_uri.split('/')
39
+ mp3_uri.split('/')[4]
23
40
  end
24
41
  end
25
42
  end
@@ -1,3 +1,3 @@
1
1
  module Imuzer
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
data/lib/imuzer.rb CHANGED
@@ -4,6 +4,7 @@ require 'imuze/create_music'
4
4
  require 'imuze/get_music'
5
5
  require 'imuze/get_genres'
6
6
  require 'format_response'
7
+ require 'find_executable'
7
8
 
8
9
  module Imuzer
9
10
  # 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.2
4
+ version: 0.0.3
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-14 00:00:00.000000000 Z
11
+ date: 2016-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -157,6 +157,7 @@ files:
157
157
  - features/step_definitions/imuzer_steps.rb
158
158
  - features/support/env.rb
159
159
  - imuzer.gemspec
160
+ - lib/find_executable.rb
160
161
  - lib/format_response.rb
161
162
  - lib/imuze/create_music.rb
162
163
  - lib/imuze/create_token.rb