diff --git a/source/net/sourceforge/filebot/cli/ScriptShell.java b/source/net/sourceforge/filebot/cli/ScriptShell.java index 5178d9ae..81831248 100644 --- a/source/net/sourceforge/filebot/cli/ScriptShell.java +++ b/source/net/sourceforge/filebot/cli/ScriptShell.java @@ -2,6 +2,7 @@ package net.sourceforge.filebot.cli; import groovy.lang.GroovyClassLoader; +import java.io.InputStreamReader; import java.net.URI; import java.util.Map; import java.util.ResourceBundle; @@ -37,6 +38,13 @@ public class ScriptShell { // setup script context engine.getContext().setBindings(bindings, ScriptContext.GLOBAL_SCOPE); + + // import additional functions into the shell environment + // TODO remove + // engine.eval(new InputStreamReader(ExpressionFormat.class.getResourceAsStream("ExpressionFormat.lib.groovy"))); + bindings.put("_shell", this); + bindings.put("_cli", new CmdlineOperations()); + engine.eval(new InputStreamReader(ScriptShell.class.getResourceAsStream("ScriptShell.lib.groovy"))); } public ScriptEngine createScriptEngine() { diff --git a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy index 7eff365c..4598339a 100644 --- a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy +++ b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy @@ -248,7 +248,7 @@ def detectMovie(File file, strict = true, queryLookupService = TheMovieDB, hashL return m // 2. perfect filename match - m = MediaDetection.matchMovieName(file.listPath(4, true).findResults{ it.name ?: null }, true, 0) + m = MediaDetection.matchMovieName(file.listPath(4).reverse().findResults{ it.name ?: null }, true, 0) if (m != null && m.size() > 0) return m[0] diff --git a/source/net/sourceforge/filebot/format/ExpressionFormatMethods.java b/source/net/sourceforge/filebot/format/ExpressionFormatMethods.java index ce4a335d..51fb767b 100644 --- a/source/net/sourceforge/filebot/format/ExpressionFormatMethods.java +++ b/source/net/sourceforge/filebot/format/ExpressionFormatMethods.java @@ -257,10 +257,14 @@ public class ExpressionFormatMethods { return FileUtilities.listPath(self).get(0); } - public static List getPathList(File self) { + public static List listPath(File self) { return FileUtilities.listPath(self); } + public static List listPath(File self, int tailSize) { + return FileUtilities.listPath(FileUtilities.getRelativePathTail(self, tailSize)); + } + public static File getRelativePathTail(File self, int tailSize) { return FileUtilities.getRelativePathTail(self, tailSize); }