Allow `@file.groovy` syntax in `Format Editor` and `Preset Editor` (e.g. `@/path/to/MyFormat.groovy`)

This commit is contained in:
Reinhard Pointner 2019-05-26 22:41:10 +07:00
parent d6062c9423
commit 97aab5eab4
3 changed files with 23 additions and 3 deletions

View File

@ -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`)

View File

@ -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() {

View File

@ -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;