Skip to content

Instantly share code, notes, and snippets.

@steshaw
Created March 22, 2010 09:41
Show Gist options
  • Save steshaw/339914 to your computer and use it in GitHub Desktop.
Save steshaw/339914 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'rubygems'
require 'id3lib'
def usage()
STDERR.puts "Usage: id3dump <mp3-file>"
exit 1
end
if ARGV.length != 1 then
usage
end
file = ARGV[0]
if !File.readable? ARGV[0] then
STDERR.puts "Error: Cannot read the file you provided. [#{file}]"
usage
end
tags = ID3Lib::Tag.new(file)
v1_tags = [:title, :artist, :album, :year, :composer, :genre, :track]
v1_max_len = v1_tags.map {|i| i.to_s.length}.max
puts "some common v1 tags {"
v1_tags.each { |tag|
printf " %-#{v1_max_len + 1}s \"%s\"\n", tag.to_s + ":", tags.send(tag)
}
puts "}"
puts "v2 tags {"
avoid = [:COMM, :APIC]
tags.reject{|frame| avoid.any?{|n| n == frame[:id]}}.each do |frame|
text = frame[:text]
data = frame[:data]
owner = frame[:owner]
frameBit = " #{frame[:id]}:"
if text != nil then
textBit = "text = #{text.inspect}"
end
if data != nil then
dataBit = "data = [[#{data.inspect}]]"
end
if owner != nil then
ownerBit = "owner = [[#{owner.inspect}]]"
end
puts [frameBit, ownerBit, textBit, dataBit].reject{|i| i == nil}.join(" ")
end
puts "}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment