about summary refs log tree commit homepage
path: root/lib/dtas/source/sox.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-08-26 08:45:33 +0000
committerEric Wong <normalperson@yhbt.net>2013-08-26 08:45:33 +0000
commitda7f831f1a0404992329690c45a5000837bc2660 (patch)
treec5ad39b80c39403615357da01dd3c03fbfaa764d /lib/dtas/source/sox.rb
parent75c4d7f89942b85ebf040a6c0ee142a9960f171f (diff)
downloaddtas-da7f831f1a0404992329690c45a5000837bc2660.tar.gz
Showing the warning for the same file over and over again is
annoying when seeking a file handled by avconv/ffmpeg, so stop
doing it.

While we're at it, the error handling for __load_comments is totally
redundant (absent of race conditions if another process modifies the
file).  However, if we do hit races, all the other soxi invocations
would be racy, too; but we really just shouldn't care about such
a corner case in here.
Diffstat (limited to 'lib/dtas/source/sox.rb')
-rw-r--r--lib/dtas/source/sox.rb43
1 files changed, 22 insertions, 21 deletions
diff --git a/lib/dtas/source/sox.rb b/lib/dtas/source/sox.rb
index eba53d4..8ac7573 100644
--- a/lib/dtas/source/sox.rb
+++ b/lib/dtas/source/sox.rb
@@ -16,6 +16,22 @@ class DTAS::Source::Sox # :nodoc:
     "tryorder" => 0,
   )
 
+  # we use this to be less noisy when seeking a file
+  @last_failed = nil
+  def self.try_to_fail_harder(infile, s, cmd)
+    msg = nil
+    case s
+    when %r{\A0\s*\z} then msg = "detected zero samples"
+    when Process::Status then msg = "failed with #{s.exitstatus}"
+    end
+    if msg
+      return if @last_failed == infile
+      @last_failed = infile
+      return warn("`#{Shellwords.join(cmd)}' #{msg}")
+    end
+    true
+  end
+
   def initialize
     command_init(SOX_DEFAULTS)
   end
@@ -25,12 +41,7 @@ class DTAS::Source::Sox # :nodoc:
     cmd = %W(soxi -s #{infile})
     s = qx(@env, cmd, err_str: err, no_raise: true)
     return if err =~ /soxi FAIL formats:/
-    case s
-    when %r{\A0\s*\z}
-      return warn "`#{Shellwords.join(cmd)}' detected zero samples"
-    when Process::Status
-      return warn "`#{Shellwords.join(cmd)}' failed with #{s.exitstatus}"
-    end
+    self.class.try_to_fail_harder(infile, s, cmd) or return
     source_file_dup(infile, offset)
   end
 
@@ -70,21 +81,11 @@ class DTAS::Source::Sox # :nodoc:
     tmp = {}
     case @infile
     when String
-      err = ""
-      cmd = %W(soxi -a #@infile)
-      begin
-        qx(@env, cmd, err_str: err).split(/\n/).each do |line|
-          key, value = line.split(/=/, 2)
-          key && value or next
-          # TODO: multi-line/multi-value/repeated tags
-          tmp[key.upcase] = value
-        end
-      rescue => e
-        if /FAIL formats: no handler for file extension/ =~ err
-          warn("#{Shellwords.escape(cmd)}: #{err}")
-        else
-          warn("#{e.message} (#{e.class})")
-        end
+      qx(@env, %W(soxi -a #@infile)).split(/\n/).each do |line|
+        key, value = line.split(/=/, 2)
+        key && value or next
+        # TODO: multi-line/multi-value/repeated tags
+        tmp[key.upcase] = value
       end
     end
     tmp