Sha256: e0ce28acba7f6f368abff0dda5a52934846337f6e0323391417ccae0e988d1f9

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

#!/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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
imuzer-0.0.1 bin/imuzer