#!/usr/bin/env ruby require 'optparse' require 'methadone' require 'imuzer.rb' require 'json' require 'rainbow' class App include Methadone::Main include Methadone::CLILogging 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 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) 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 elapsed = Time.now - start info "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) 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