diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2010-10-07 11:05:33 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2010-10-07 11:05:33 -0700 |
commit | a02fb360906e1c955bb22f9b61b352d102734be2 (patch) | |
tree | 63e332a15af3905b38b2996eb6d34e316068841f | |
parent | 012fcec93c02c81f20aad7e2abb1d1ededeea60f (diff) | |
download | omptagger-a02fb360906e1c955bb22f9b61b352d102734be2.tar.gz omptagger-a02fb360906e1c955bb22f9b61b352d102734be2.tar.xz |
Support for viewing FLAC metadata.
-rwxr-xr-x | omptagger | 64 |
1 files changed, 53 insertions, 11 deletions
@@ -9,6 +9,45 @@ # See http://www.gnu.org/licenses/gpl.txt for the full license text. require 'getoptlong' +require 'rubygems' +require 'TagLib' + +class Metadata + def output(tag, val) + spacing = 2 + @tags.keys.inject(0) do |length, object| + object.length > length ? object.length : length + end - tag.length + + puts ' ' + tag + ' ' * spacing + val + end +end + +class VorbisComment < Metadata + def view + puts ' Viewing tags:' + + if @tags.empty? + puts ' No tags are set.' + return + end + + @tags.sort.each do |tag, val| + val.each do |val| + output(tag, val) + end + end + end +end + +class FLAC < VorbisComment + def initialize(file) + @filename = File.expand_path(file) + @write = false + + @file = TagLib::FLAC::File.new(file) + @tags = @file.xiphComment.fieldListMap.hash + end +end def help puts <<-end @@ -92,7 +131,7 @@ GetoptLong.new( when :generate, :rename actions << [option, scheme] else - actions << option + actions << [option] end end @@ -100,26 +139,29 @@ help if options.include?(:help) list if options.include?(:list) help if actions.empty? -puts 'No files specified.' if ARGV.empty? +if ARGV.empty? + puts 'No files specified.' + exit +end ARGV.each do |file| - puts file - - # Use absolute path internally. - file = File.expand_path(file) - begin raise 'File does not exist.' unless File.exist?(file) case File.extname(file).downcase when '.flac' - puts ' Treat this as a FLAC file.' - when '.ogg' - puts ' Treat this as a Vorbis file.' + track = FLAC.new(file) else raise 'File extension not recognised.' end + + puts file + ':' + + actions.each do |action| + track.send(*action) + end rescue RuntimeError => message - puts ' ' + message + $stderr.puts file + ':' + $stderr.puts ' ' + message end end |