bin/imuzer in imuzer-0.0.1 vs bin/imuzer in imuzer-0.0.2

- old
+ new

@@ -1,57 +1,78 @@ #!/usr/bin/env ruby -require 'optparse' +require 'gli' require 'methadone' require 'imuzer.rb' require 'json' require 'rainbow' -class App - include Methadone::Main - include Methadone::CLILogging +include GLI::App +program_desc 'a demo tool for iMuze API' - main do |duration, genre, subgenre, structure| - info 'Authenticating to iMuze ....' - response = Imuze::CreateToken.call(options[:email], options[:password]) - formated_json = JSON.pretty_generate(response) - if response['status'] == 500 - puts Rainbow(formated_json).red - exit - else - puts Rainbow(formated_json).green if options[:verbose] - end +desc 'Be verbose' +switch [:v, :verbose] - token = response['token'] - info "Composing your track \"#{subgenre}\" \"#{genre}\" on iMuze .... please wait" - start = Time.now - response = Imuze::CreateMusic.call(token, duration, - genre, subgenre, structure) +desc 'Email from your iMuze user account' +arg_name 'email' +flag [:e, :email] - formated_json = JSON.pretty_generate(response) - if response['status'] == 500 - puts Rainbow(formated_json).red - exit - else - puts Rainbow(formated_json).green if options[:verbose] +desc 'Password from your iMuze user account' +arg_name 'password' +flag [:p, :password] + +desc 'list all musical genres and subgenres' +command :genres do |c| + puts 'Listing iMuze musical genres with sub-genres...' + c.action do |global_options, options, args| + response = Imuze::GetGenres.call global_options + response['genres'].each do |genre| + print " #{genre['name']}: " + genre['subgenres'].each{|sg| print Rainbow("#{sg}, ").bright} + puts end + end +end +desc 'composes a music' +arg 'genre', :required +arg 'subgenre', :required +arg 'duration', :required +arg 'structure', :required +command :compose do |c| + c.switch [:c, :crop] + c.flag 'fadeout_ms', arg_name: 'fadeout_ms', + type: Integer, + desc: 'fadeout in milliseconds' + c.flag 'voices_volume', arg_name: 'voices_volume', + type: Integer, + desc: 'volume of voice track' + + c.action do |global_options, options, args| + help_now!('credentials required to compose music') if global_options[:email].nil? || global_options[:password].nil? + help_now!('id is required') if args.size < 3 + genre = args[0] + subgenre = args[1] + duration = args[2] + structure = args[3] + puts 'Authenticating to iMuze ....' + response = Imuze::CreateToken.call global_options[:email], + global_options[:password] + FormatResponse.call response, options + token = response['token'] + music = "\"#{subgenre}\" \"#{genre}\"" + puts "Composing your track #{music} on iMuze .... please wait" + start = Time.now + response = Imuze::CreateMusic.call token, + duration, + genre, subgenre, structure, + options + FormatResponse.call response, global_options elapsed = Time.now - start - info "Done composing your music in #{elapsed} seconds" + puts "Done composing your music in #{elapsed} seconds" mp3_uri = response['mp3_uri'] - info "Playing your \"#{subgenre}\" \"#{genre}\" mp3 from iMuze ...." - Imuze::GetMusic.call(token, mp3_uri) + puts "Playing your #{music} mp3 from iMuze ...." + Imuze::GetMusic.call token, mp3_uri end - - on('-e email','--email','your imuze account email') - on('-p password','--password','your imuze password') - on('-v','--verbose','Be verbose') - - version Imuzer::VERSION - description 'Composes a track with iMuze' - arg :duration, 'Track duration' - arg :genre, 'Track genre' - arg :subgenre, 'Track subgenre' - arg :structure, 'Track structure' - use_log_level_option toggle_debug_on_signal: 'USR1' - go! end + +exit run(ARGV)