Class: Crossfader::CLI
- Inherits:
-
Thor
- Object
- Thor
- Crossfader::CLI
- Includes:
- HTTMultiParty
- Defined in:
- lib/crossfader/cli.rb
Instance Method Summary collapse
- #auth ⇒ Object
- #batch ⇒ Object
- #clean ⇒ Object
- #convert ⇒ Object
- #create_pack ⇒ Object
- #help ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #upload ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
10 11 12 13 |
# File 'lib/crossfader/cli.rb', line 10 def initialize(*) @rcfile = Crossfader::RCFile.instance super end |
Instance Method Details
#auth ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/crossfader/cli.rb', line 16 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) = { :body => {email: email, password: password } } response = self.class.post('/users/login', ) 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 |
#batch ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/crossfader/cli.rb', line 78 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:') files = FileList.new("#{dir}/*.wav") files.each{|file| convert_wav_to_mp3(file) } loop_responses = files.map{|file| create_loop_from_file(file) } loop_ids = loop_responses.map{|r| r['id'] } response = create_new_pack(pack_name, pack_sub, loop_ids) if response.code == 200 say "Success!" else say "Something went wrong." end end |
#clean ⇒ Object
96 97 98 99 100 101 |
# File 'lib/crossfader/cli.rb', line 96 def clean dir = ask('Select a folder of MP3s to delete: ') mp3s = FileList["#{dir}/*.mp3"] Rake::Cleaner.cleanup_files(mp3s) say "Removed MP3s successfully." end |
#convert ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/crossfader/cli.rb', line 32 def convert say "Let's convert wavs to MP3s!" dir = ask('Select a folder of loops to convert: ') files = FileList.new("#{dir}/*.wav") files.each{|file| convert_wav_to_mp3(file) } say "The loops were converted successfully" end |
#create_pack ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/crossfader/cli.rb', line 50 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.code if response.code == 200 say "Successfully created a pack named #{pack_name}" else say "Something went wrong." end end |
#help ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/crossfader/cli.rb', line 64 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 "\`crossfader clean\` : Remove all MP3s from a folder.\n\n" say "---\n" say "Have questions, comments, or feed back? Contact Adam at [email protected]\n\n" end |
#upload ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/crossfader/cli.rb', line 41 def upload say "Time to upload some loops!" dir = ask('Select a folder of loops to upload: ') wavs = FileList["#{dir}/*.wav"] wavs.each{|file| create_loop_from_file(file) } say "The loops were uploaded successfully" end |