Created
December 22, 2020 19:21
-
-
Save jasonrobot/79b1511d26d88f2a53784402a47cb572 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
# foo_bar-qwe_asd/01.name.flac | |
require 'fileutils' | |
start_dir = Dir.pwd | |
ARGV.select do |arg| | |
# is a directory | |
isDir = File.directory? arg | |
# has a dash in it | |
hasDash = arg.include? '-' | |
# could even check if it contains flac files | |
# | |
isDir && hasDash | |
end.each do |dir| | |
# [ "artist name", "album name" ] | |
names = dir.split('-').map { |dirpart| dirpart.sub(/_/, ' ') } | |
artist = names[0] | |
album = names[1] | |
# does artist dir exist? | |
Dir.mkdir(artist) unless File.directory?(artist) | |
puts "moving #{album} into #{artist}" | |
dest_dir = "#{artist}/#{album}" | |
FileUtils.mv dir, dest_dir | |
Dir.chdir dest_dir | |
Dir.glob('*.flac').each do |file| | |
new_name = file.sub(/^(\d+)\./, '\1 - ') | |
puts "renaming #{file} to #{new_name}" | |
FileUtils.mv file, new_name | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment