Skip to content

Instantly share code, notes, and snippets.

@jasonrobot
Created December 22, 2020 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonrobot/79b1511d26d88f2a53784402a47cb572 to your computer and use it in GitHub Desktop.
Save jasonrobot/79b1511d26d88f2a53784402a47cb572 to your computer and use it in GitHub Desktop.
#!/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