Renaming MP3 tags with Ruby and the mp3info gem
Occasionally you get MP3s which have unconventional tags. I usually get this problem with compilation albums and it’s a bit dull to rename them in iTunes.
There’s a ruby gem which let’s you easily edit id3 tags called ‘mp3info‘.
Here is a script to get you started:
require "mp3info" dir = '/opt/music/album_name/' Dir.entries(dir).each do |file| next if file !~ /.mp3$/ # skip files not ending with .mp3 Mp3Info.open(dir + file) do |mp3| puts mp3.tag.title puts mp3.tag.artist puts mp3.tag.album puts mp3.tag.tracknum # You would perform your text transform here, here's a simple change instead mp3.tag.title = mp3.tag.title + ' with my change' mp3.tag.artist = mp3.tag.artist + ' with my change' end endTweet