From a02fb360906e1c955bb22f9b61b352d102734be2 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Thu, 7 Oct 2010 11:05:33 -0700 Subject: Support for viewing FLAC metadata. --- omptagger | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 11 deletions(-) diff --git a/omptagger b/omptagger index 4b2375a..f4198ca 100755 --- a/omptagger +++ b/omptagger @@ -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 -- cgit v1.2.3-70-g09d2