Created
March 18, 2010 11:35
-
-
Save steshaw/336272 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
#!/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 | |
# Note: avoids printing comment tags. The fear-the-boom-and-bust.mp3 comment is just so big! | |
v1_tags = [:title, :artist, :album, :year, :composer, :genre, :track] | |
v1_max_len = v1_tags.map {|i| i.to_s.length}.max | |
tags = ID3Lib::Tag.new(file) | |
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 {" | |
tags.select {|frame| frame[:id] != :COMM}.each do |frame| | |
puts " #{frame[:id]}: \"#{frame[:text]}\"" | |
end | |
puts "}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment