#!/usr/bin/env ruby require 'gli' require 'methadone' require 'imuzer.rb' require 'json' require 'rainbow' include GLI::App program_desc 'a demo tool for iMuze API' desc 'Be verbose' switch [:v, :verbose] desc 'Email from your iMuze user account' arg_name 'email' flag [:e, :email] 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 puts "Done composing your music in #{elapsed} seconds" mp3_uri = response['mp3_uri'] puts "Playing your #{music} mp3 from iMuze ...." Imuze::GetMusic.call token, mp3_uri end end exit run(ARGV)