@@ -33,8 +33,8 @@ echo " | |||
}, | |||
\"perform\": { | |||
\"trim\": \"input\", | |||
\"start\": \"${T_START}\", | |||
\"end\": \"${T_END}\" | |||
\"start\": \"${T_START}s\", | |||
\"end\": \"${T_END}s\" | |||
} | |||
} | |||
] | |||
@@ -55,26 +55,16 @@ public class ConcatOperation implements JOperator { | |||
// create output object | |||
final JAsset output = json2asset(op.getCreates()); | |||
if (output.hasDest() && output.destExists()) { | |||
log.info("operate: dest exists, not re-creating: "+output.destPath()); | |||
return; | |||
} | |||
// if any format settings are missing, use settings from first source | |||
output.mergeFormat(sources.get(0).getFormat()); | |||
// set the path, check if output asset already exists | |||
final JFileExtension formatType = output.getFormat().getFileExtension(); | |||
final File outfile = output.hasDest() | |||
? new File(output.destPath()) | |||
: assetManager.assetPath(op, sources, formatType); | |||
if (outfile.exists()) { | |||
log.info("operate: outfile exists, not re-creating: "+abs(outfile)); | |||
return; | |||
} | |||
if (!outfile.getParentFile().canWrite()) die("operate: cannot write file (parent directory not writeable): "+abs(outfile)); | |||
output.setPath(abs(outfile)); | |||
final File defaultOutfile = assetManager.assetPath(op, sources, formatType); | |||
final File path = resolveOutputPath(output, defaultOutfile); | |||
if (path == null) return; | |||
output.setPath(abs(path)); | |||
final Map<String, Object> ctx = new HashMap<>(); | |||
ctx.put("ffmpeg", toolbox.getFfmpeg()); | |||
@@ -22,7 +22,6 @@ import static jvcl.service.Toolbox.getDuration; | |||
import static org.cobbzilla.util.daemon.ZillaRuntime.big; | |||
import static org.cobbzilla.util.daemon.ZillaRuntime.empty; | |||
import static org.cobbzilla.util.io.FileUtil.abs; | |||
import static org.cobbzilla.util.io.FileUtil.basename; | |||
import static org.cobbzilla.util.system.CommandShell.execScript; | |||
@Slf4j | |||
@@ -45,17 +44,11 @@ public class OverlayOperation implements JOperator { | |||
output.mergeFormat(source.getFormat()); | |||
final JFileExtension formatType = output.getFormat().getFileExtension(); | |||
if (output.hasDest()) { | |||
if (output.destExists() && !output.destIsDirectory()) { | |||
log.info("operate: dest exists, not trimming: " + output.getDest()); | |||
return; | |||
} else if (output.destIsDirectory()) { | |||
final File defaultFile = assetManager.assetPath(op, source, formatType, new Object[]{config}); | |||
output.setPath(abs(new File(output.destDirectory(), basename(abs(defaultFile))))); | |||
} else { | |||
output.setPath(output.destPath()); | |||
} | |||
} | |||
final File defaultOutfile = assetManager.assetPath(op, source, formatType, new Object[]{config}); | |||
final File path = resolveOutputPath(output, defaultOutfile); | |||
if (path == null) return; | |||
output.setPath(abs(path)); | |||
final Map<String, Object> ctx = new HashMap<>(); | |||
ctx.put("ffmpeg", toolbox.getFfmpeg()); | |||
@@ -63,18 +63,9 @@ public class TrimOperation implements JOperator { | |||
} | |||
} else { | |||
final File defaultOutfile = assetManager.assetPath(op, source, formatType, new Object[]{config}); | |||
if (output.hasDest()) { | |||
if (output.destExists() && !output.destIsDirectory()) { | |||
log.info("operate: dest exists, not trimming: " + output.getDest()); | |||
return; | |||
} else if (output.destIsDirectory()) { | |||
output.setPath(abs(new File(output.destDirectory(), basename(abs(defaultOutfile))))); | |||
} else { | |||
output.setPath(output.destPath()); | |||
} | |||
} else { | |||
output.setPath(abs(defaultOutfile)); | |||
} | |||
final File path = resolveOutputPath(output, defaultOutfile); | |||
if (path == null) return; | |||
output.setPath(abs(path)); | |||
trim(config, source, output, output, toolbox, assetManager); | |||
} | |||
} | |||
@@ -1,14 +1,22 @@ | |||
package jvcl.service; | |||
import jvcl.model.JAsset; | |||
import jvcl.model.JOperation; | |||
import org.cobbzilla.util.handlebars.HandlebarsUtil; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import java.io.File; | |||
import java.util.Map; | |||
import static org.cobbzilla.util.io.FileUtil.abs; | |||
import static org.cobbzilla.util.io.FileUtil.basename; | |||
import static org.cobbzilla.util.json.JsonUtil.json; | |||
public interface JOperator { | |||
Logger log = LoggerFactory.getLogger(JOperator.class); | |||
void operate(JOperation op, Toolbox toolbox, AssetManager assetManager); | |||
default <T> T loadConfig(JOperation op, Class<T> configClass) { | |||
@@ -19,4 +27,20 @@ public interface JOperator { | |||
return HandlebarsUtil.apply(toolbox.getHandlebars(), template, ctx); | |||
} | |||
default File resolveOutputPath(JAsset output, File defaultOutfile) { | |||
if (output.hasDest()) { | |||
if (output.destExists() && !output.destIsDirectory()) { | |||
log.info("resolveOutputPath: dest exists: " + output.getDest()); | |||
return null; | |||
} else if (output.destIsDirectory()) { | |||
return new File(output.destDirectory(), basename(abs(defaultOutfile))); | |||
} else { | |||
return new File(output.destPath()); | |||
} | |||
} else { | |||
return defaultOutfile; | |||
} | |||
} | |||
} |