|
|
@@ -1,11 +1,16 @@ |
|
|
|
package jvc.operation.exec; |
|
|
|
|
|
|
|
import jvc.model.JAsset; |
|
|
|
import jvc.model.JSpec; |
|
|
|
import jvc.model.JStreamType; |
|
|
|
import jvc.model.operation.JOperation; |
|
|
|
import jvc.service.AssetManager; |
|
|
|
import jvc.service.Toolbox; |
|
|
|
import lombok.Getter; |
|
|
|
import lombok.Setter; |
|
|
|
import lombok.experimental.Accessors; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.cobbzilla.util.collection.NameAndValue; |
|
|
|
import org.cobbzilla.util.handlebars.HandlebarsUtil; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
@@ -15,13 +20,22 @@ import java.util.Map; |
|
|
|
|
|
|
|
import static jvc.service.Toolbox.jsContext; |
|
|
|
import static org.cobbzilla.util.daemon.ZillaRuntime.die; |
|
|
|
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 |
|
|
|
@Slf4j @Accessors(chain=true) |
|
|
|
public abstract class ExecBase<OP extends JOperation> { |
|
|
|
|
|
|
|
@Getter @Setter private JSpec spec; |
|
|
|
|
|
|
|
public NameAndValue[] getVars () { |
|
|
|
return spec == null || empty(spec.getVars()) |
|
|
|
? NameAndValue.EMPTY_ARRAY |
|
|
|
: spec.getVars(); |
|
|
|
} |
|
|
|
|
|
|
|
public abstract Map<String, Object> operate(OP operation, Toolbox toolbox, AssetManager assetManager); |
|
|
|
|
|
|
|
protected String renderScript(Toolbox toolbox, Map<String, Object> ctx, String template) { |
|
|
@@ -43,10 +57,19 @@ public abstract class ExecBase<OP extends JOperation> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected Map<String, Object> initialContext(Toolbox toolbox, JAsset source) { |
|
|
|
protected Map<String, Object> initialContext(Toolbox toolbox, JAsset source, NameAndValue[] vars) { |
|
|
|
final Map<String, Object> ctx = new HashMap<>(); |
|
|
|
ctx.put("ffmpeg", toolbox.getFfmpeg()); |
|
|
|
ctx.put("source", source); |
|
|
|
if (!empty(vars)) { |
|
|
|
for (NameAndValue var : vars) { |
|
|
|
final String name = var.getName(); |
|
|
|
if (ctx.containsKey(name)) { |
|
|
|
log.warn("initialContext: spec variable "+ name +" will mask existing value: "+ctx.get(name)); |
|
|
|
} |
|
|
|
ctx.put(name, var.getValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
return ctx; |
|
|
|
} |
|
|
|
|
|
|
|