From 54df846c910a61c44200fd431e7deeb288c902e1 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 5 Nov 2011 00:29:59 +0000 Subject: [PATCH] * some finetuning + new sample script --- .../sourceforge/filebot/cli/CmdlineInterface.java | 3 +-- .../sourceforge/filebot/cli/CmdlineOperations.java | 14 +++++++------- .../net/sourceforge/filebot/cli/ScriptShell.java | 9 --------- .../sourceforge/filebot/cli/ScriptShell.lib.groovy | 9 ++++++--- website/data/shell/chkall.groovy | 9 +++++++++ website/data/shell/src.groovy | 3 +++ 6 files changed, 26 insertions(+), 21 deletions(-) create mode 100644 website/data/shell/chkall.groovy diff --git a/source/net/sourceforge/filebot/cli/CmdlineInterface.java b/source/net/sourceforge/filebot/cli/CmdlineInterface.java index 78874e29..bd52ea16 100644 --- a/source/net/sourceforge/filebot/cli/CmdlineInterface.java +++ b/source/net/sourceforge/filebot/cli/CmdlineInterface.java @@ -5,12 +5,11 @@ package net.sourceforge.filebot.cli; import java.io.File; import java.util.Collection; import java.util.List; -import java.util.Set; public interface CmdlineInterface { - Set rename(Collection files, String query, String format, String db, String lang, boolean strict) throws Exception; + List rename(Collection files, String query, String format, String db, String lang, boolean strict) throws Exception; List getSubtitles(Collection files, String query, String lang, String output, String encoding) throws Exception; diff --git a/source/net/sourceforge/filebot/cli/CmdlineOperations.java b/source/net/sourceforge/filebot/cli/CmdlineOperations.java index 8791dd70..71852653 100644 --- a/source/net/sourceforge/filebot/cli/CmdlineOperations.java +++ b/source/net/sourceforge/filebot/cli/CmdlineOperations.java @@ -67,7 +67,7 @@ import net.sourceforge.filebot.web.VideoHashSubtitleService; public class CmdlineOperations implements CmdlineInterface { @Override - public Set rename(Collection files, String query, String expression, String db, String languageName, boolean strict) throws Exception { + public List rename(Collection files, String query, String expression, String db, String languageName, boolean strict) throws Exception { ExpressionFormat format = (expression != null) ? new ExpressionFormat(expression) : null; Locale locale = getLanguage(languageName).toLocale(); @@ -119,7 +119,7 @@ public class CmdlineOperations implements CmdlineInterface { } - public Set renameSeries(Collection files, String query, ExpressionFormat format, EpisodeListProvider db, Locale locale, boolean strict) throws Exception { + public List renameSeries(Collection files, String query, ExpressionFormat format, EpisodeListProvider db, Locale locale, boolean strict) throws Exception { CLILogger.config(format("Rename episodes using [%s]", db.getName())); List mediaFiles = filter(files, VIDEO_FILES, SUBTITLE_FILES); Collection seriesNames; @@ -235,7 +235,7 @@ public class CmdlineOperations implements CmdlineInterface { } - public Set renameMovie(Collection mediaFiles, String query, ExpressionFormat format, MovieIdentificationService db, Locale locale, boolean strict) throws Exception { + public List renameMovie(Collection mediaFiles, String query, ExpressionFormat format, MovieIdentificationService db, Locale locale, boolean strict) throws Exception { CLILogger.config(format("Rename movies using [%s]", db.getName())); File[] movieFiles = filter(mediaFiles, VIDEO_FILES).toArray(new File[0]); @@ -423,7 +423,7 @@ public class CmdlineOperations implements CmdlineInterface { } - private Set renameAll(Map renameMap) throws Exception { + private List renameAll(Map renameMap) throws Exception { // rename files final List> renameLog = new ArrayList>(); @@ -471,11 +471,11 @@ public class CmdlineOperations implements CmdlineInterface { } // new file names - Set newFiles = new LinkedHashSet(); + List destinationList = new ArrayList(); for (Entry it : renameLog) - newFiles.add(it.getValue()); + destinationList.add(it.getValue()); - return newFiles; + return destinationList; } diff --git a/source/net/sourceforge/filebot/cli/ScriptShell.java b/source/net/sourceforge/filebot/cli/ScriptShell.java index 8324081b..e00a8cf1 100644 --- a/source/net/sourceforge/filebot/cli/ScriptShell.java +++ b/source/net/sourceforge/filebot/cli/ScriptShell.java @@ -14,7 +14,6 @@ import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; import java.security.ProtectionDomain; import java.util.PropertyPermission; -import java.util.logging.Logger; import javax.script.Bindings; import javax.script.ScriptContext; @@ -28,7 +27,6 @@ import org.codehaus.groovy.jsr223.GroovyScriptEngineFactory; import net.sourceforge.filebot.MediaTypes; import net.sourceforge.filebot.WebServices; import net.sourceforge.filebot.format.PrivilegedInvocation; -import net.sourceforge.filebot.mediainfo.MediaInfo; import net.sourceforge.filebot.web.EpisodeListProvider; import net.sourceforge.filebot.web.MovieIdentificationService; @@ -64,13 +62,6 @@ class ScriptShell { bindings.put(service.getName().toLowerCase(), PrivilegedInvocation.newProxy(MovieIdentificationService.class, service, acc)); } - // load media info native lib - try { - bindings.put("mi", new MediaInfo()); - } catch (LinkageError e) { - Logger.getLogger(MediaInfo.class.getName()).warning("Failed to load MediaInfo"); - } - return bindings; } diff --git a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy index 91227e89..a4b152f1 100644 --- a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy +++ b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy @@ -11,17 +11,20 @@ File.metaClass.hasFile = { c -> isDirectory() && listFiles().find{ c.call(it) }} File.metaClass.plus = { path -> new File(delegate, path) } File.metaClass.getFiles = { def files = []; traverse(type:FILES) { files += it }; return files } +String.metaClass.getFiles = { new File(delegate).getFiles() } List.metaClass.getFiles = { findResults{ it.getFiles() }.flatten().unique() } + File.metaClass.getFolders = { def folders = []; traverse(type:DIRECTORIES, visitRoot:true) { folders += it }; return folders } +String.metaClass.getFolders = { new File(delegate).getFolders() } List.metaClass.getFolders = { findResults{ it.getFolders() }.flatten().unique() } File.metaClass.eachMediaFolder = { c -> getFolders().findAll{ it.hasFile{ it.isVideo() } }.each(c) } +String.metaClass.eachMediaFolder = { c -> new File(delegate).eachMediaFolder(c) } List.metaClass.eachMediaFolder = { c -> getFolders().findAll{ it.hasFile{ it.isVideo() } }.each(c) } -def require(cond) { - if (!cond()) throw new Exception('Require failed') -} + +def require(cond) { if (!cond()) throw new Exception('Require failed') } def rename(args) { args = _defaults(args) diff --git a/website/data/shell/chkall.groovy b/website/data/shell/chkall.groovy new file mode 100644 index 00000000..f3fabb0e --- /dev/null +++ b/website/data/shell/chkall.groovy @@ -0,0 +1,9 @@ +// filebot -script "http://filebot.sourceforge.net/data/shell/chkall.groovy" + +/* + * Check all sfv/md5/sha1 files and stop if a conflict is found + */ +args.getFiles().findAll { it.isVerification() }.each { + if (!check(file:it)) + throw new Exception("*ERROR*") +} diff --git a/website/data/shell/src.groovy b/website/data/shell/src.groovy index d389edfc..8d16e672 100644 --- a/website/data/shell/src.groovy +++ b/website/data/shell/src.groovy @@ -1,5 +1,8 @@ // filebot -script "http://filebot.sourceforge.net/data/shell/src.groovy" +/* + * Fetch subtitles, rename and calculate checksums for all video files + */ args.eachMediaFolder { getSubtitles(folder:it) rename(folder:it)