1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-21 23:38:50 -05:00

Allow custom parallelism for formats

This commit is contained in:
Reinhard Pointner 2019-05-18 02:26:57 +07:00
parent b6251a7aa5
commit d28df06818

View File

@ -18,7 +18,7 @@ import net.filebot.similarity.Match;
class ExpressionFormatter implements MatchFormatter {
private final String expression;
private String expression;
private ExpressionFileFormat format;
private Format preview;
@ -41,6 +41,13 @@ class ExpressionFormatter implements MatchFormatter {
this.format = format;
}
public synchronized ExpressionFileFormat getFormat() throws ScriptException {
if (format == null) {
format = new ExpressionFileFormat(expression);
}
return format;
}
public Class<?> getTargetClass() {
return target;
}
@ -57,15 +64,12 @@ class ExpressionFormatter implements MatchFormatter {
}
@Override
public synchronized String format(Match<?, ?> match, boolean extension, Map<?, ?> context) throws ScriptException {
// lazy initialize script engine
if (format == null) {
format = new ExpressionFileFormat(expression);
}
public String format(Match<?, ?> match, boolean extension, Map<?, ?> context) throws ScriptException {
// evaluate the expression using the given bindings
Object bindingBean = new MediaBindingBean(match.getValue(), (File) match.getCandidate(), (Map) context);
String destination = format.format(bindingBean);
// lazy initialize script engine
String destination = getFormat().format(bindingBean);
return getPath((File) match.getCandidate(), destination);
}