Allow `@file.groovy` syntax in `Format Editor` and `Preset Editor` (e.g. `@/path/to/MyFormat.groovy`)
This commit is contained in:
parent
d6062c9423
commit
97aab5eab4
|
@ -1,11 +1,12 @@
|
|||
Next Release (4.8.6)
|
||||
====================
|
||||
* Improved `SelectDialog` with thumbnails and tooltips
|
||||
* Enhanced `Selection Dialog` with thumbnails and tooltips
|
||||
* Added `{history}` binding for looking up the original file path of `{f}` (e.g. useful for `-exec` post-processing commands)
|
||||
* Evaluate `{closures}` automatically in `String.plus(Closure)` constructs (e.g. `{"[" + {n} + " " + {s00e00} + "]"}`)
|
||||
* Ensure that `ActionPopup` is always displayed on top of the Windows Task Bar
|
||||
* Improved `-mediainfo -exec` pipeline
|
||||
* Added `-no-history` CLI option
|
||||
* Allow `@file.groovy` syntax in `Format Editor` and `Preset Editor` (e.g. `@/path/to/MyFormat.groovy`)
|
||||
* Allow `*.groovy` files as argument value for `--format`, `--filter` and `--file-filter` CLI options (e.g. `--format /path/to/MyFormat.groovy`)
|
||||
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ public class ExpressionFilter {
|
|||
|
||||
public ExpressionFilter(String expression) throws ScriptException {
|
||||
this.expression = expression;
|
||||
this.compiledExpression = new SecureCompiledScript(compileScriptlet(expression));
|
||||
this.compiledExpression = new SecureCompiledScript(compileScriptlet(asExpression(expression)));
|
||||
}
|
||||
|
||||
public String getExpression() {
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package net.filebot.format;
|
||||
|
||||
import static net.filebot.util.ExceptionUtilities.*;
|
||||
import static net.filebot.util.FileUtilities.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.security.AccessController;
|
||||
import java.text.FieldPosition;
|
||||
import java.text.Format;
|
||||
|
@ -39,7 +41,7 @@ public class ExpressionFormat extends Format {
|
|||
|
||||
public ExpressionFormat(String expression) throws ScriptException {
|
||||
this.expression = expression;
|
||||
this.compilation = secure(compile(expression));
|
||||
this.compilation = secure(compile(asExpression(expression)));
|
||||
}
|
||||
|
||||
public String getExpression() {
|
||||
|
@ -253,6 +255,23 @@ public class ExpressionFormat extends Format {
|
|||
}
|
||||
}
|
||||
|
||||
protected static String asExpression(String s) {
|
||||
// try as file path
|
||||
if (s.startsWith("@") && s.endsWith(".groovy")) {
|
||||
File f = new File(s.substring(1));
|
||||
if (f.isFile()) {
|
||||
try {
|
||||
return readTextFile(f);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("Failed to read text file: " + f, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// or default to literal value
|
||||
return s;
|
||||
}
|
||||
|
||||
private static class Variable extends CompiledScript {
|
||||
|
||||
private String name;
|
||||
|
|
Loading…
Reference in New Issue