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 +4 -4
- data/Gemfile.lock +1 -1
- data/bin/imuzer +8 -2
- data/lib/find_executable.rb +25 -0
- data/lib/imuze/get_music.rb +21 -4
- data/lib/imuzer/version.rb +1 -1
- data/lib/imuzer.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f60d92779e8bceab0ac1f98f86797bd008bd1ed9
|
4
|
+
data.tar.gz: 70810d9b916f35483cf47db657d926ce57bd5e83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74426b2fe5a9649f6c8a26d7790bb3e82115f047bfb26558ea234722526fc18d2cf53abe5b92443938dd2df695fff997a4695d51ebe70dadc2f6888f0e0e7af2
|
7
|
+
data.tar.gz: 50235a18ef3500e9b4730c1793298946a56aa908b6a1a8c63ac4d43e65f4905e87993704ab8be52c15e2b88562aefac6de117c05abbe1d367fdcc9d411bb1eba
|
data/Gemfile.lock
CHANGED
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
|
data/lib/imuze/get_music.rb
CHANGED
@@ -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
|
-
|
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
|
22
|
-
|
37
|
+
def mp3_id
|
38
|
+
puts mp3_uri.split('/')
|
39
|
+
mp3_uri.split('/')[4]
|
23
40
|
end
|
24
41
|
end
|
25
42
|
end
|
data/lib/imuzer/version.rb
CHANGED
data/lib/imuzer.rb
CHANGED
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.
|
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-
|
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
|