about summary refs log tree commit homepage
path: root/lib/dtas/splitfx.rb
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-05-10 09:06:35 +0000
committerEric Wong <e@80x24.org>2015-05-10 09:35:49 +0000
commit619b08c9d4e43d94bac39cd395c1def6fa796f06 (patch)
treef4381ed9d40414e5340519c181ee207d26e40794 /lib/dtas/splitfx.rb
parent1e7eeebd9d6b2cdce7a803fcce8a50310482905c (diff)
downloaddtas-619b08c9d4e43d94bac39cd395c1def6fa796f06.tar.gz
It is useful to force output to a writable directory if the YAML
file is on a read-only mount point or to force the output to a
large tmpfs mount point to avoid SSD/HDD wear.
Diffstat (limited to 'lib/dtas/splitfx.rb')
-rw-r--r--lib/dtas/splitfx.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/dtas/splitfx.rb b/lib/dtas/splitfx.rb
index 208ff67..3f673ee 100644
--- a/lib/dtas/splitfx.rb
+++ b/lib/dtas/splitfx.rb
@@ -10,7 +10,7 @@ require 'tempfile'
 # Unlike the stuff for dtas-player, dtas-splitfx is fairly tied to sox
 # (but we may still pipe to ecasound or anything else)
 class DTAS::SplitFX # :nodoc:
-  CMD = 'sox "$INFILE" $COMMENTS $OUTFMT "$TRACKNUMBER.$SUFFIX" '\
+  CMD = 'sox "$INFILE" $COMMENTS $OUTFMT "$OUTDIR$TRACKNUMBER.$SUFFIX" '\
         '$TRIMFX $FX $RATEFX $DITHERFX'
   include DTAS::Process
   include DTAS::XS
@@ -55,6 +55,7 @@ class DTAS::SplitFX # :nodoc:
     @track_zpad = true
     @t2s = method(:t2s)
     @infile = nil
+    @outdir = nil
     @targets = {
       "flac-cdda" => {
         "command" => CMD,
@@ -72,7 +73,7 @@ class DTAS::SplitFX # :nodoc:
            '$OPUSENC_BITRATE --raw-rate $RATE --raw-chan $CHANNELS ' \
            '--raw-endianness $ENDIAN_OPUSENC ' \
            '$OPUSENC_COMMENTS ' \
-           '- $TRACKNUMBER.opus',
+           '- $OUTDIR$TRACKNUMBER.opus',
         "format" => {
           "bits" => 16,
           "rate" => 48000,
@@ -197,6 +198,7 @@ class DTAS::SplitFX # :nodoc:
     infile_env(env, @infile)
     env["OUTFMT"] = xs(outfmt.to_sox_arg)
     env["SUFFIX"] = outfmt.type
+    env["OUTDIR"] = @outdir ? "#@outdir/".squeeze('/') : ''
     env.merge!(t.env)
 
     command = target["command"]
@@ -323,6 +325,11 @@ class DTAS::SplitFX # :nodoc:
   end
 
   def run(target, opts = {})
+    if @outdir = opts[:outdir]
+      require 'fileutils'
+      FileUtils.mkpath(@outdir)
+    end
+
     fails = []
     tracks = @tracks.dup
     pids = {}