about summary refs log tree commit homepage
diff options
authorEric Wong <normalperson@yhbt.net>2013-08-26 07:59:00 +0000
committerEric Wong <normalperson@yhbt.net>2013-08-26 07:59:00 +0000
commitb975f4917639a43c76bec998e2c419f8b8be4291 (patch)
parent33ad8374da5d782d174c70a9023d181378151040 (diff)
soxi may not handle some files correctly and detect zero samples
without error-ing out.  If sox can't detect the sample count
or the file is really empty, then there's no point trying futher
and we'll fall back to avconv.
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/dtas/source/sox.rb b/lib/dtas/source/sox.rb
index e1baee9..eba53d4 100644
--- a/lib/dtas/source/sox.rb
+++ b/lib/dtas/source/sox.rb
@@ -22,8 +22,15 @@ class DTAS::Source::Sox # :nodoc:
   def try(infile, offset = nil)
     err = ""
-    qx(@env, %W(soxi #{infile}), err_str: err, no_raise: true)
+    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
     source_file_dup(infile, offset)