Tech Tidbits - Ruby, Ruby On Rails, Merb, .Net, Javascript, jQuery, Ajax, CSS...and other random bits and pieces.

Saturday, July 12, 2008

ruby-mp3info

I have an old SanDisk mp3 player that I use to listen to music and podcasts. Though it's a rather small card (512M), it's still annoying to have to scroll through my single playlist to get to a specific file.

The SanDisk sorts by the mp3 info title tag, so I wrote a small script that I run on my podcast files before I load them on my player so that they will show up first in the playlist by prepending '01_' to the mp3 title tag (and using the mp3 filename if the title is nil).

First, install the ruby-mp3info gem if you don't have it:

gem install ruby-mp3info

edit_mp3info_title.rb

require 'rubygems'
require "mp3info"

dir = Dir.open('/Users/dsparlingimbp/PODCAST/mp3')
puts "mp3 directory: #{dir.path}"

dir.each do |file|
next unless /\.mp3$/ =~ file
puts "mp3: #{file}"

mp3file = "#{dir.path}/#{file}"

Mp3Info.open(mp3file) do |mp3|
puts "original title: #{mp3.tag.title}"
title = '01_' + (mp3.tag.title || file)
mp3.tag.title = title
puts "new title: #{mp3.tag.title}"
end

end

No comments:

About Me

My photo
Developer (Ruby on Rails, iOS), musician/composer, Buddhist, HSP, Vegan, Aspie.

Labels