Created
January 9, 2009 20:16
-
-
Save jseifer/45254 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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