summaryrefslogtreecommitdiff
path: root/omptagger
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2010-10-07 11:05:33 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2010-10-07 11:05:33 -0700
commita02fb360906e1c955bb22f9b61b352d102734be2 (patch)
tree63e332a15af3905b38b2996eb6d34e316068841f /omptagger
parent012fcec93c02c81f20aad7e2abb1d1ededeea60f (diff)
downloadomptagger-a02fb360906e1c955bb22f9b61b352d102734be2.tar.gz
omptagger-a02fb360906e1c955bb22f9b61b352d102734be2.tar.xz
Support for viewing FLAC metadata.
Diffstat (limited to 'omptagger')
-rwxr-xr-xomptagger64
1 files 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