Created
May 31, 2012 20:01
-
-
Save jeffreybaird/2845856 to your computer and use it in GitHub Desktop.
Script for creating a playlist Chapter 11 exercises
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Dir.chdir #add your music directory here | |
| all_music = (Dir['**/*.mp3'].shuffle) | |
| puts "what do you want to name your playlist?" | |
| answer = gets.chomp | |
| File.open "#{answer}.m3u",'w' do |file| | |
| all_music.each do |mp3_file_name| | |
| file.write "#{mp3_file_name}\n" | |
| end | |
| end | |
| puts "Wrote #{all_music.size} entries" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tend to write most of these utilities by supplying the options on the command line rather than having "Where do you want X?" prompts and input capture in the app. It follows the "unix model" where you supply options on the command line and only output data to STDOUT that would be useful output to the user or to another program that would consume it (via pipes)
For example:
randomize_amazon_playlist /path/to/mp3folder /path/to/output_playlist.m3uOr better yet to use a command line parser:
randomize_amazon_playlist --playlist /path/to/output_playlist.m3u -- mp3_folder /path/to/mp3folder--optionstyle you are now free from order dependency.