Class: Crossfader::CLI

Inherits:
Thor
  • Object
show all
Includes:
HTTMultiParty
Defined in:
lib/crossfader/cli.rb

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



8
9
10
11
12
# File 'lib/crossfader/cli.rb', line 8

def initialize(*)
 		@rcfile = Crossfader::RCFile.instance
 		@loop_ids = []
 		super
end

Instance Method Details

#authObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/crossfader/cli.rb', line 15

def auth
	say "Welcome! Before you can use crossfader, you'll first need to log in"
      	say 'to your account and get an access token. Follow the steps below:'
      	email = ask 'Enter your crossdfader.fm email address: '
      	password = ask('Enter your crossfader.fm password: ', :echo => false)
      	options = { :body => {email: email, password: password } }
  		response = self.class.post('/users/login', options)
  		if response.code == 200
       	@rcfile[email] = { email: email, api_access_token: response['api_access_token'], dj_name: response['dj_name'] }
       	say "\nAuthorized successfully!\n"
       else
       	say "\nSomething went wrong. Tell Adam.\n"
       end
end

#batchObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/crossfader/cli.rb', line 76

def batch
	say "Time to batch convert and upload!"
	pack_name = ask "What do you want to name your new pack?"
	pack_sub = ask "Enter the subtitle for this pack:"
	dir = ask('Select a folder of loops to process and upload:')
	clean_dir = dir.gsub(/\\/, '').strip
	say clean_dir
	Dir.foreach(clean_dir) { |file| convert_wav_to_mp3(file.to_s, clean_dir.to_s) }
	Dir.foreach(clean_dir) { |file| create_loop_from_file(file.to_s, clean_dir.to_s) }
	response = create_new_pack(pack_name, pack_sub)
	if response.code == 200
		say "Success!"
	else
		say "Something went wrong."
	end
end

#convertObject



31
32
33
34
35
36
37
# File 'lib/crossfader/cli.rb', line 31

def convert
	say "Let's convert wavs to MP3s!"
	dir = ask('Select a folder of loops to convert: ')
	dir = dir.gsub(/\\/, "").strip
	Dir.foreach(dir) { |file| convert_wav_to_mp3(file.to_s, dir.to_s) }
	say "The loops were converted successfully"
end

#create_packObject



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/crossfader/cli.rb', line 49

def create_pack
	say "Create a new pack? That's a great idea!"
	pack_name = ask "What should we call this pack?"
	pack_sub = ask "Enter the subtitle for this pack:"
	response = create_new_pack(pack_name, pack_sub)
	say response
	if response.code == 200
		say "Successfully created a pack named #{pack_name}"
	else
		say "Something went wrong."
	end
end

#helpObject



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/crossfader/cli.rb', line 63

def help
	say "\nYou can perform the following actions:"
	say "---\n\n"
	say "\`crossfader auth\` Authorize this app to work with the Crossfader.fm API.\n"
	say "\`crossfader convert\` : Convert a folder of .wav files to .mp3.\n"
	say "\`crossfader upload\` : Upload a folder of .mp3s to the server to create new loops.\n"
	say "\`crossfader batch\` : Create a new pack, convert a folder of .wav files to .mp3 files and upload them to the server in one step.\n" 
	say "\`crossfader create_pack\` : Create a new empty pack.\n\n"
	say "---\n"
	say "Have questions, comments, or feed back? Contact Adam at [email protected]\n\n"
end

#uploadObject



40
41
42
43
44
45
46
# File 'lib/crossfader/cli.rb', line 40

def upload
	say "Time to upload some loops!"
	dir = ask('Select a folder of loops to upload: ')
	dir = dir.gsub(/\\/, "").strip
	Dir.foreach(dir) { |file| create_loop_from_file(file, dir) }
	say "The loops were uploaded successfully"
end