Skip to content

Instantly share code, notes, and snippets.

@jhsu
Created March 10, 2011 15:13
Show Gist options
  • Save jhsu/864227 to your computer and use it in GitHub Desktop.
Save jhsu/864227 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'fileutils'
require 'colorize'
MUSIC_DIR="/home/jshsu/Media/music/"
songs = Dir.glob("*.mp3").select do |song|
(( Time.now - File.ctime(song) ) / 60 / 60 / 24) >= 1
end
confirm_all = false
songs.each do |song|
artist, song_title = song.split('-').map(&:strip!)
if artist && song_title
print "Move song #{song.colorize(:green)}? (y/n/A): "
confirm = gets.chomp
confirm_all = true if confirm == "A"
if confirm_all || confirm == "y"
artist_dir = "#{MUSIC_DIR}#{artist}/"
Dir.mkdir(artist_dir) unless Dir.exists?(artist_dir)
FileUtils.mv(song, artist_dir)
if File.exists?("#{artist_dir}#{song}")
print "[#{ "MOVED".colorize(:green) }]\t"
else
print "[#{ "FAILED".colorize(:red) }]\t"
end
print "#{artist_dir}#{song}"
puts
else
puts "[#{ "SKIP".colorize(:yellow) }] #{song}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment