Skip to content

Instantly share code, notes, and snippets.

@jseifer
Created January 9, 2009 20:16
Show Gist options
  • Save jseifer/45254 to your computer and use it in GitHub Desktop.
Save jseifer/45254 to your computer and use it in GitHub Desktop.
# This is my Rails Envy mp3 tagger script because I'm too lazy to do it every week manually.
require 'rubygems'
require 'id3lib'
require 'optparse'
require 'pp'
app = Hash.new
opts = OptionParser.new do |opts|
opts.banner = "Usage: id3tagger.rb [options]"
opts.separator ""
opts.separator "Specific options:"
opts.on("-f", "--file MP3", "File is required") do |opt|
app[:file] = opt
end
opts.on('-e', '--episode NUM', 'Episode Number') do |opt|
app[:episode] = opt
end
opts.on('-d', '--date DATE', 'Date') do |opt|
app[:date] = opt
end
end
begin
opts.parse!(ARGV)
rescue OptionParser::ParseError => e
puts e
end
# Load a tag from a file
tag = ID3Lib::Tag.new(File.join(File.expand_path(File.dirname(__FILE__), app[:file])))
# Get and set text frames with convenience methods
tag.title = "Rails Envy Podcast - Episode ##{app[:episode]} - #{app[:date]}"
tag.album = "Rails Envy Podcast"
tag.track = app[:episode]
tag.genre = "Podcast"
# Remove all comment frames
tag.delete_if{ |frame| frame[:id] == :COMM }
# Get info about APIC frame to see which fields are allowed
ID3Lib::Info.frame(:APIC)
# Add an attached picture frame
cover = {
:id => :APIC,
:mimetype => 'image/jpeg',
:picturetype => 3,
:description => 'Rails Envy Podcast',
:textenc => 0,
:data => File.read(File.expand_path(File.dirname(__FILE__) + '/podcast.jpg'))
}
tag << cover
if tag.update!
puts "Succesfully updated tag"
else
puts "Did not update tag!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment