Skip to content

Instantly share code, notes, and snippets.

@alChaCC
Last active June 26, 2016 04:02
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 alChaCC/e1758b9be5472837c547bfe1ac38ed31 to your computer and use it in GitHub Desktop.
Save alChaCC/e1758b9be5472837c547bfe1ac38ed31 to your computer and use it in GitHub Desktop.
mp3 tag render using Ruby
#!/usr/bin/env ruby
require 'rubygems' # necessary for ruby v1.8.*
require 'micro-optparse'
options = Parser.new do |p|
p.option :path, 'folder location', default: 'String'
p.option :album, 'album name', default: 'String'
p.option :artist, 'artist name', default: 'String'
p.option :songuse, 'filename or tags', default: 'String'
end.process!
full_path = File.absolute_path(options[:path])
Dir["#{full_path}/*.mp3"].each do |f_filename|
song = File.basename(f_filename).gsub('.mp3', '')
if options[:songuse] == 'tags'
content = %x{ mutagen-inspect '#{f_filename}' }
song = content.match(/TIT2=(.*)/)[1]
%x{ mv '#{f_filename}' '#{full_path}/#{song}.mp3' }
next
end
%x{ mid3v2 --artist='#{options[:artist]}' --album='#{options[:album]}' --song='#{song}' '#{f_filename}' }
end
@alChaCC
Copy link
Author

alChaCC commented Jun 26, 2016

Before you use, please make sure you installed:

pip install mutagen
gem install micro-optparse

Usage:

If your MP3 tag info is correct, but file name is wrong: using tag info to update the file name

ruby mp3_tags_render.rb --path path/to/your/album_folder --album 'album name you want' --artist 'the artist name your want' --songuse 'tags'

If your file name is correct but tag info is not: Update tags by filename and input arguments

ruby mp3_tags_render.rb --path path/to/your/album_folder --album 'album name you want' --artist 'the artist name your want' --songuse 'filename'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment