* load ExpressionFormat convenience functions into script environment
* change media info sample into "write media info csv table"
This commit is contained in:
parent
397e7c5d38
commit
c37c38c2c7
|
@ -27,6 +27,7 @@ import org.codehaus.groovy.jsr223.GroovyScriptEngineFactory;
|
||||||
|
|
||||||
import net.sourceforge.filebot.MediaTypes;
|
import net.sourceforge.filebot.MediaTypes;
|
||||||
import net.sourceforge.filebot.WebServices;
|
import net.sourceforge.filebot.WebServices;
|
||||||
|
import net.sourceforge.filebot.format.ExpressionFormat;
|
||||||
import net.sourceforge.filebot.format.PrivilegedInvocation;
|
import net.sourceforge.filebot.format.PrivilegedInvocation;
|
||||||
import net.sourceforge.filebot.web.EpisodeListProvider;
|
import net.sourceforge.filebot.web.EpisodeListProvider;
|
||||||
import net.sourceforge.filebot.web.MovieIdentificationService;
|
import net.sourceforge.filebot.web.MovieIdentificationService;
|
||||||
|
@ -37,7 +38,7 @@ class ScriptShell {
|
||||||
private final ScriptEngine engine = new GroovyScriptEngineFactory().getScriptEngine();
|
private final ScriptEngine engine = new GroovyScriptEngineFactory().getScriptEngine();
|
||||||
private final boolean trustScript;
|
private final boolean trustScript;
|
||||||
|
|
||||||
|
|
||||||
public ScriptShell(CmdlineInterface cli, ArgumentBean args, boolean trustScript, AccessControlContext acc) throws ScriptException {
|
public ScriptShell(CmdlineInterface cli, ArgumentBean args, boolean trustScript, AccessControlContext acc) throws ScriptException {
|
||||||
this.trustScript = trustScript;
|
this.trustScript = trustScript;
|
||||||
|
|
||||||
|
@ -47,10 +48,11 @@ class ScriptShell {
|
||||||
engine.setContext(context);
|
engine.setContext(context);
|
||||||
|
|
||||||
// import additional functions into the shell environment
|
// import additional functions into the shell environment
|
||||||
|
engine.eval(new InputStreamReader(ExpressionFormat.class.getResourceAsStream("ExpressionFormat.lib.groovy")));
|
||||||
engine.eval(new InputStreamReader(ScriptShell.class.getResourceAsStream("ScriptShell.lib.groovy")));
|
engine.eval(new InputStreamReader(ScriptShell.class.getResourceAsStream("ScriptShell.lib.groovy")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected Bindings initializeBindings(CmdlineInterface cli, ArgumentBean args, AccessControlContext acc) {
|
protected Bindings initializeBindings(CmdlineInterface cli, ArgumentBean args, AccessControlContext acc) {
|
||||||
Bindings bindings = new SimpleBindings();
|
Bindings bindings = new SimpleBindings();
|
||||||
bindings.put("_script", new File(args.script));
|
bindings.put("_script", new File(args.script));
|
||||||
|
@ -71,7 +73,7 @@ class ScriptShell {
|
||||||
return bindings;
|
return bindings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Object evaluate(final String script, final Bindings bindings) throws Exception {
|
public Object evaluate(final String script, final Bindings bindings) throws Exception {
|
||||||
if (trustScript) {
|
if (trustScript) {
|
||||||
return engine.eval(script, bindings);
|
return engine.eval(script, bindings);
|
||||||
|
@ -90,7 +92,7 @@ class ScriptShell {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected AccessControlContext getSandboxAccessControlContext() {
|
protected AccessControlContext getSandboxAccessControlContext() {
|
||||||
Permissions permissions = new Permissions();
|
Permissions permissions = new Permissions();
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,24 @@
|
||||||
// filebot -script "http://filebot.sourceforge.net/data/shell/mi.groovy" <folder>
|
// filebot -script "http://filebot.sourceforge.net/data/shell/mi.groovy" -trust-script /path/to/media/ "MediaIndex.csv"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Print media info for all video files using given or default format pattern
|
* Print media info of all video files to CSV file
|
||||||
*/
|
*/
|
||||||
args.getFiles()
|
def model = 'Name;Container;Resolution;Video Codec;Video Format;Audio Codec;Audio Format;Audio Language(s);Duration;File Size;Path'
|
||||||
.findAll { it.isVideo() }
|
def template = '{fn};{cf};{resolution};{vc};{vf};{ac};{af};{media.AudioLanguageList};{media.DurationString3};{file.length()};{file.getCanonicalPath()}'
|
||||||
.sort { a, b -> a.name.compareTo(b.name) }
|
|
||||||
.each { println getMediaInfo(file:it, format:"{fn} [{resolution} {af} {vc} {ac}]") }
|
// open destination file (writing files requires -trust-script)
|
||||||
|
args[1].withWriter{ output ->
|
||||||
|
// print header
|
||||||
|
output.writeLine(model)
|
||||||
|
|
||||||
|
// print info for each video file (sorted by filename)
|
||||||
|
args[0].getFiles{ it.isVideo() }.sort{ a, b -> a.name.compareToIgnoreCase(b.name) }.each{
|
||||||
|
def mi = getMediaInfo(file:it, format:template)
|
||||||
|
|
||||||
|
// print to console
|
||||||
|
println mi
|
||||||
|
|
||||||
|
// append to file
|
||||||
|
output.writeLine(mi)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue