BradTrupp.com - Little slices of my life and my projects BradTrupp.com -- Tags -- Code
BradTrupp.com -- Tags -- Code -- Using Ruby to fix id3 tags on mp3 files (Ruby)

Using Ruby to fix id3 tags on mp3 files (Ruby)
(2008/11/10)

If you listen to a lot of podcasts on your mp3 player, you likely are annoyed by the fact that every podcast uses different tags for genres, artists, and more -- or leaves them blank. You are constantly jumping around from artist to artist or genre to genre to find all your intended listening.

It can be a real pain.

The little ruby script will rewrite the ID3 tags on all the mp3 files in a selected directory -- in this case 'C:/Podcasts/' -- and change those id3 tags to something consistent so all the files are grouped together.

In this case, the script--

  • Sets genre to 'Podcasts'
  • Sets album to 'Podcast Album'
  • Sets artist to 'Podcast Artists'
  • Sets the title to a combination of the old album and title

Run this script after downloading your podcasts and before loading your player.

Also, some podcast receiver allow you to run a script automatically once downloads are complete.

#!/usr/bin/ruby -w
require 'id3lib'

pathOut = 'C:/Podcasts/'

#----------------------------------------------------------------------
# Pass 2 - fix id3 tags next
#----------------------------------------------------------------------

theFileList = [];
Dir[pathOut + '*.mp3'].each do |fnn|
theFileList << fnn.downcase;
end;

#----------------------------------------------------------------------
# Pass 1 - fix id3 tags
#----------------------------------------------------------------------

itrack = 0;
theFileList.each do |file_name|

if file_name =~ /\.mp3$/ then
itrack = itrack + 1
puts
puts "Processing #{itrack} - #{file_name}"

file_path = file_name
tag = ID3Lib::Tag.new(file_path)
parts = file_name.split(/ \- /)

if tag.album != 'Podcast Album' then
if tag.album == nil then tag.album = 'null'; end;
if tag.album.length < 1 then tag.album = '?'; end;
if tag.title == nil then tag.title = 'null'; end;
if tag.title.length < 1 then tag.title = '?'; end;
mytitle = tag.album + ' - ' + tag.title;
tag.title = mytitle;
tag.album = 'Podcast Album'
tag.genre = 'Podcasts'
tag.artist = 'Podcast Artists'
tag.year = 2008
end;

tag.track = itrack;
tag.update!

puts "Artist: #{tag.artist}"
puts "Title: #{tag.title}"
puts "Genre: #{tag.genre}"

end

end;

#----------------------------------------------------------------------
puts 'press return to continue...'
gets

Installing id3lib

If you use RubyGems, run the following and select the newest version marked "ruby" --

gem install id3lib-ruby

"Enjoy..."

Tags: Code | Music

Share: Del.icio.us | Digg | Facebook | Google Bookmarks | Reddit | Technorati | Twitter | Windows Live | Yahoo! My Web

View Comments (0)


 

Tag: Code
A Little Bit of Automation for your Backups (2010/02/25)
A Simple CSV to iCalendar Conversion Utility written in Ruby (2009/06/29)
A Simple iCalendar to Task Coach Conversion Utility written in Ruby (2009/05/09)
Using Ruby to generate Social Bookmarks for your Web Pages (2008/11/23)
Using Ruby to fix id3 tags on mp3 files (Ruby) (2008/11/10)
Copy all files in a directory tree to a common destination. (Ruby) (2008/10/08)
Check for File Changes using Ruby and MD5 (Ruby) (2008/08/20)
Create Checkpoints using Ruby and MD5 (Ruby) (2008/07/30)
Bash - A Basic Greeting Program. (Bash) (2007/10/31)
Bash - An Introduction to Scripting (Bash) (2007/10/10)
UUMerge Command Line Text File Merge (Delphi) (2007/07/01)
Explorer-Style Fly-By Buttons (Delphi) (2006/01/14)
Handle-Free Checkboxes in a String Grid (Delphi) (2006/01/14)

All Tags
Business Tips (5)
Code (13)
Life Skills (1)
Music (2)
My 15 minutes (5)
Old Articles (39)
Photos (10)

Advertisement