openmind ☃   April 25, 2008  ☃  bitrate.rb  (, )

I have been mentally writing a bitrate display patch for cmus for a while now. It can’t be that hard to do it in C. If only I had time to patch other peoples’ C code! :)

Alternatives?

As far as I’m concerned, the last remaining reason to have xmms installed is that xmms (like Winamp before it) displays bitrates in a nice little window. It’s not so great to have to open up xmms just to tell what bitrate a file is. Oh, and you have to play the file, which necessiates turning off whatever else is accessing the sound card (cmus). Plus there’s the whole idea of having a GUI program just for one discrete function that’s just abhorrent..

So . . . imagine my delight in discovering that one can extract bitrates from mp3 files using the lovely ruby-mp3info library (!). 10 minutes later, I had bitrate.rb:

#!/usr/bin/env ruby

%w[rubygems pp mp3info].each{|lib| require lib}

if ARGV.length == 0
  puts "Usage:  #{File.basename $0} <mp3>"
  exit
end

ARGV.each do |arg|
  file = File.basename arg
  next if file.split('.')[-1] != "mp3"
  Mp3Info.open(arg) do |mp3|
    begin
      puts [(mp3.vbr ? "VBR: ": ""), mp3.bitrate, " ++++++ ", arg].join(" ")
    rescue Mp3InfoError => e
    end
  end  
end

Maybe I’ll learn some C next week, after I’m done adding support for ogg and flac to bitrate.rb :0

blog comments powered by Disqus