Last active
December 17, 2015 03:38
-
-
Save kevbuchanan/5544194 to your computer and use it in GitHub Desktop.
From Pine's Learn to Program. This program creates a music playlist in the specified directory.
This file contains 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
directory = '/Users/kevinbuchanan/Music' | |
Dir.chdir directory | |
playlist = {} | |
while true | |
puts 'Enter a song name to add to the playlist: (Press enter when done)' | |
song = gets.chomp | |
if song != '' | |
file = Dir.glob("**/*#{song}*.???") | |
if !file.empty? | |
playlist[song] = file | |
puts "#{song} was added to the playlist." | |
else | |
puts "#{song} was not found." | |
end | |
else | |
break | |
end | |
end | |
puts "What would you like to title the playlist? (No Spaces)" | |
title = gets.chomp | |
File.open "#{title}.m3u", 'w' do |f| | |
playlist.values.flatten.each {|song| f.write song + "\n"} | |
end | |
puts "Your playlist has been created here: #{directory}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This actually returns all songs containing the word that is entered when searching. I need to figure out how to return only exact matches.