Renaming MP3 files based on ID3 tag information

Posted on November 27, 2007. Filed under: ID3, ruby, software |

Here is a neat little trick that I often find useful for renaming mp3 files with wrong names and correct tag titles. Just run this ruby script in the directory where you have stored your songs and it will read the tag title and rename the current file using it.

   1: require "rubygems"
   2: require "id3lib"
   3: require "fileutils"
   5: files = `dir /s /b *.mp3`
   7: files.split("\n").each do |file|
   8:   dir = File.dirname(file)
   9:   tag =
  10:   new_name = tag.title.gsub("00",'') if tag.title
  11:   FileUtils.move(file, File.join(dir, new_name + ".mp3")) if new_name and !new_name.empty? rescue nil
  12: end

This script requires id3lib gem for ruby which can be installed simply by running the command:

gem install id3lib-ruby

One thing to notice in the script is that currently it works only on windows, but only with a little modification it can be made to work on other OSes as well (The only change I guess will be in the 5th line).

Here is the pastie link for this code. Tags: ,,

Make a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

4 Responses to “Renaming MP3 files based on ID3 tag information”

RSS Feed for Blogging on Technology Comments RSS Feed

[…] March 9, 2008 · No Comments I wanted to blog about this feature from so long (as it got released with Winamp 5.5 a long way back), but I couldn’t find enough time to do this.This weekend however, I had decided to use this feature heavily to tag almost all of my mp3s and hence I decided to blog about it too.What I’m talking about ? Auto-tagging in Winamp 5.5It’s a new feature introduced in Winamp 5.5 that tags your mp3 files using the Gracenote’s CDDB server. It doesn’t relies on any kind of meta-data present in file, neither it does uses the file name for this purpose. I suspect it sends some kind og hash (that I’ll have to hack around …).But what stands out is that Winamp was even able to tag a file name “dsfdsferfermvmev.mp3″ correctly. Using this feature you can tag and categorize unused songs in your mp3 archieve.How to find this feature in Winamp:There are two ways to use this feature:1.  Double click on the scrolling title(or press Alt-3) to open file info dialog, in bottom right you’ll see Auto-tag button. 2. Create a playlist and select files and then right click on them, select send-to and select Auto-tag. A word of caution:Nothing is perfect ! so is this. Please keep an eye on the results of the auto-tagging, if you suspect anything wrong don’t apply the tag at all.Now what to do when your files have been tagged, but still their names are like r3rff34f.mp3, well you can use any software available in the market that can rename files based on their tag information or you can use the following ruby-script to rename them.Click here   […]

I’ve written a program in Java that is very small (300kb) and does all the work!
Check it out:

Note it’s still beta version. 🙂

u shall replace
files = `dir /s /b *.mp3`
with Dir[“*.mp3”], this will work on all platforms

Where's The Comment Form?

Liked it here?
Why not try sites on the blogroll...

%d bloggers like this: