That Stupid Thing I Wrote The Other Day, part 1
Published 2007-03-13 @ 15:13
Tagged ruby, toys
Hopefully this will become a series that will let me clean out my Work/misc dir, but “That Stupid Thing I Wrote The Other Day” needs to be changed because TSTIWTOD is a lame acronym. Suggestions?
I use this to populate my iPod with all my music so I don’t get confused in music stores:
music = Hash.new { |h,k| h[k] = [] }
Dir.chdir File.expand_path("~/Music/iTunes/iTunes Music") do
Dir["*"].sort.each do |artist|
artist_name = artist.sub(/^The (.*)/, '\1, The')
Dir.chdir artist do
Dir["*"].sort.each do |album|
music[artist_name] << album
end
end
end
end
dir = "/Volumes/NanoSpider/Notes/"
dir = test(?d, dir) ? dir : Dir.pwd
out = $stdout
last = nil
music.sort_by { |k,v| k.downcase }.each do |artist, albums|
letter = artist[0..0].downcase
if last != letter and dir then
out.close
out = File.open("#{dir}/music-#{letter}.txt", "w")
last = letter
end
out.puts "#{artist}:"
out.puts " #{albums.sort.join("\n ")}"
end
out.close if dir