diff --git a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy index 4c55843d..2e99c32f 100644 --- a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy +++ b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy @@ -1,15 +1,12 @@ import static groovy.io.FileType.* -import static net.sourceforge.tuned.FileUtilities.*; -File.metaClass.plus = { path -> new File(delegate, path) } - File.metaClass.isVideo = { _types.getFilter("video").accept(delegate) } File.metaClass.isAudio = { _types.getFilter("audio").accept(delegate) } File.metaClass.isSubtitle = { _types.getFilter("subtitle").accept(delegate) } File.metaClass.isVerification = { _types.getFilter("verification").accept(delegate) } -File.metaClass.isDerived = { file -> isDerived(delegate, file) } +File.metaClass.plus = { path -> new File(delegate, path) } File.metaClass.hasFile = { c -> isDirectory() && listFiles().find{ c.call(it) }} File.metaClass.getFiles = { def files = []; traverse(type:FILES) { files += it }; return files } @@ -25,6 +22,22 @@ String.metaClass.eachMediaFolder = { c -> new File(delegate).eachMediaFolder(c) List.metaClass.eachMediaFolder = { c -> getFolders().findAll{ it.hasFile{ it.isVideo() } }.each(c) } +// FileUtilities +import static net.sourceforge.tuned.FileUtilities.*; + +File.metaClass.getNameWithoutExtension = { getNameWithoutExtension(delegate.getName()) } +File.metaClass.getExtension = { getExtension(delegate) } +File.metaClass.hasExtension = { String... ext -> hasExtension(delegate, ext) } +File.metaClass.isDerived = { f -> isDerived(delegate, f) } +File.metaClass.validateFileName = { validateFileName(delegate) } +File.metaClass.validateFilePath = { validateFilePath(delegate) } +File.metaClass.moveTo = { f -> renameFile(delegate, f) } + +List.metaClass.mapByFolder = { mapByFolder(delegate) } +List.metaClass.mapByExtension = { mapByExtension(delegate) } + + + def require(cond) { if (!cond()) throw new Exception('Require failed') } diff --git a/source/net/sourceforge/tuned/FileUtilities.java b/source/net/sourceforge/tuned/FileUtilities.java index e39986c2..074b810d 100644 --- a/source/net/sourceforge/tuned/FileUtilities.java +++ b/source/net/sourceforge/tuned/FileUtilities.java @@ -346,11 +346,15 @@ public final class FileUtilities { SortedMap> map = new TreeMap>(); for (File file : files) { - List valueList = map.get(file.getParentFile()); + File key = file.getParentFile(); + if (key == null) { + throw new IllegalArgumentException("Parent is null: " + file); + } + List valueList = map.get(key); if (valueList == null) { valueList = new ArrayList(); - map.put(file.getParentFile(), valueList); + map.put(key, valueList); } valueList.add(file);