music dilemma

If you're anything like me, you've got about a million music files that aren't tagged properly. Specifically, they are missing their track number tags. (They have the track number as part of their file name though, such as "06-the_curse_of_feanor.ogg") This isn't a big deal if you use players like XMMS, which are capable of ordering files in alphabetical order by filename. Unfortunately, a recent trend in audio players has been to leave that capability out. (I'm looking at you, iTunes. But there are many guilty parties.)

Here's a script that will fix your dilemma. I wanted to do it all in Ruby, but I found that the Ruby TagLib library was simply too crappy to do so. So this script requires that vorbiscomment be installed. (It's in the vorbis-tools package on Ubuntu.) Save what's below as allofogg.rb

 #/usr/bin/env ruby
 require 'find'
 Find.find(ARGV[0]) do |f|
 next unless f.include? ARGV[1] || '.ogg'
 next unless f.include?('/') && (tracknum = f[f.rindex('/')+1 .. 
 f.rindex('/') + 2].to_i) > 0
 sanitized = f.gsub('(',  '\(').gsub(')',  '\)')

 `vorbiscomment -a #{sanitized} -t "tracknumber=#{tracknum}"`

Syntax: allofogg.rb FILES [EXTENSION]

« older | 2005-11-23T11:48:19Z | newer »