Skip to content

Instantly share code, notes, and snippets.

@ivan-leschinsky
Created November 27, 2015 00:49
Show Gist options
  • Save ivan-leschinsky/cb29c4f93b508f614b0e to your computer and use it in GitHub Desktop.
Save ivan-leschinsky/cb29c4f93b508f614b0e to your computer and use it in GitHub Desktop.
Renames music files accoriding to their netadata
#!/usr/bin/env ruby
require 'mp3info'
dir = ARGV[0]
Dir["#{dir}/*.mp3"].each do |filename|
new_file_name = ' - '
begin
Mp3Info.open(filename) do |mp3|
file_name = "#{mp3.tag.title} - #{mp3.tag.artist} (#{File.basename(filename)}).mp3"
file_name.gsub!('/', '-') if file_name.include?('/')
new_file_name = "#{dir}/#{file_name}"
end
rescue
nil
end
File.rename(filename, new_file_name)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment