From 8d19863283a027336acd9b3526ad846d6ff6bbed Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Thu, 30 Jul 2015 13:08:03 +0000 Subject: [PATCH] + Support --filter (file filter expression) in filebot -mediainfo calls --- source/net/filebot/cli/ArgumentProcessor.java | 4 ++-- source/net/filebot/cli/CmdlineInterface.java | 2 +- source/net/filebot/cli/CmdlineOperations.java | 21 ++++++++++++++++--- .../net/filebot/cli/ScriptShellBaseClass.java | 7 ++++++- .../ExpressionFileFilter.java | 5 +---- source/net/filebot/ui/rename/Preset.java | 1 + website/data/add-series-alias.txt | 4 ++-- 7 files changed, 31 insertions(+), 13 deletions(-) rename source/net/filebot/{ui/rename => format}/ExpressionFileFilter.java (85%) diff --git a/source/net/filebot/cli/ArgumentProcessor.java b/source/net/filebot/cli/ArgumentProcessor.java index 09e765ab..c57b9d33 100644 --- a/source/net/filebot/cli/ArgumentProcessor.java +++ b/source/net/filebot/cli/ArgumentProcessor.java @@ -46,8 +46,8 @@ public class ArgumentProcessor { // print media info if (args.mediaInfo) { - for (File file : args.getFiles(true)) { - System.out.println(cli.getMediaInfo(file, args.format)); + for (String line : cli.getMediaInfo(args.getFiles(true), args.format, args.filter)) { + System.out.println(line); } return 0; } diff --git a/source/net/filebot/cli/CmdlineInterface.java b/source/net/filebot/cli/CmdlineInterface.java index 003ab2af..6c2aaa20 100644 --- a/source/net/filebot/cli/CmdlineInterface.java +++ b/source/net/filebot/cli/CmdlineInterface.java @@ -24,7 +24,7 @@ public interface CmdlineInterface { List fetchEpisodeList(String query, String format, String db, String sortOrder, String filter, String lang) throws Exception; - String getMediaInfo(File file, String format) throws Exception; + List getMediaInfo(Collection files, String format, String filter) throws Exception; List extract(Collection files, String output, String conflict, FileFilter filter, boolean forceExtractAll) throws Exception; diff --git a/source/net/filebot/cli/CmdlineOperations.java b/source/net/filebot/cli/CmdlineOperations.java index 80b97715..2ffe9393 100644 --- a/source/net/filebot/cli/CmdlineOperations.java +++ b/source/net/filebot/cli/CmdlineOperations.java @@ -43,6 +43,7 @@ import net.filebot.RenameAction; import net.filebot.StandardRenameAction; import net.filebot.archive.Archive; import net.filebot.archive.FileMapper; +import net.filebot.format.ExpressionFileFilter; import net.filebot.format.ExpressionFilter; import net.filebot.format.ExpressionFormat; import net.filebot.format.MediaBindingBean; @@ -1115,9 +1116,23 @@ public class CmdlineOperations implements CmdlineInterface { } @Override - public String getMediaInfo(File file, String expression) throws Exception { - ExpressionFormat format = new ExpressionFormat(expression != null ? expression : "{fn} [{resolution} {af} {vc} {ac}]"); - return format.format(new MediaBindingBean(readMetaInfo(file), file, null)); + public List getMediaInfo(Collection files, String format, String filter) throws Exception { + if (filter != null && filter.length() > 0) { + ExpressionFileFilter includes = new ExpressionFileFilter(new ExpressionFilter(filter), false); + files = filter(files, includes); + + if (files.isEmpty()) { + throw new CmdlineException("No files: " + files); + } + } + + ExpressionFormat formatter = new ExpressionFormat(format != null && format.length() > 0 ? format : "{fn} [{resolution} {af} {vc} {ac}]"); + List output = new ArrayList(); + for (File file : files) { + String line = formatter.format(new MediaBindingBean(readMetaInfo(file), file, null)); + output.add(line); + } + return output; } @Override diff --git a/source/net/filebot/cli/ScriptShellBaseClass.java b/source/net/filebot/cli/ScriptShellBaseClass.java index 9581d461..e26fb77d 100644 --- a/source/net/filebot/cli/ScriptShellBaseClass.java +++ b/source/net/filebot/cli/ScriptShellBaseClass.java @@ -420,10 +420,15 @@ public abstract class ScriptShellBaseClass extends Script { public String getMediaInfo(Map parameters) throws Exception { List input = getInputFileList(parameters); + if (input == null || input.isEmpty()) { + return null; + } + Map option = getDefaultOptions(parameters); synchronized (cli) { try { - return cli.getMediaInfo(input.get(0), asString(option.get(Option.format))); + List lines = cli.getMediaInfo(singleton(input.get(0)), asString(option.get(Option.format)), asString(option.get(Option.filter))); + return lines.get(0); } catch (Exception e) { printException(e, false); return null; diff --git a/source/net/filebot/ui/rename/ExpressionFileFilter.java b/source/net/filebot/format/ExpressionFileFilter.java similarity index 85% rename from source/net/filebot/ui/rename/ExpressionFileFilter.java rename to source/net/filebot/format/ExpressionFileFilter.java index 0e1b447b..04ce7b8f 100644 --- a/source/net/filebot/ui/rename/ExpressionFileFilter.java +++ b/source/net/filebot/format/ExpressionFileFilter.java @@ -1,13 +1,10 @@ -package net.filebot.ui.rename; +package net.filebot.format; import java.io.File; import java.io.FileFilter; import java.util.logging.Level; import java.util.logging.Logger; -import net.filebot.format.ExpressionFilter; -import net.filebot.format.MediaBindingBean; - public class ExpressionFileFilter implements FileFilter { private final ExpressionFilter filter; diff --git a/source/net/filebot/ui/rename/Preset.java b/source/net/filebot/ui/rename/Preset.java index 0f060b5d..d6e8aab4 100644 --- a/source/net/filebot/ui/rename/Preset.java +++ b/source/net/filebot/ui/rename/Preset.java @@ -12,6 +12,7 @@ import net.filebot.Language; import net.filebot.Settings; import net.filebot.StandardRenameAction; import net.filebot.WebServices; +import net.filebot.format.ExpressionFileFilter; import net.filebot.format.ExpressionFilter; import net.filebot.format.ExpressionFormat; import net.filebot.mac.MacAppUtilities; diff --git a/website/data/add-series-alias.txt b/website/data/add-series-alias.txt index 7da2ed6f..b331d20e 100644 --- a/website/data/add-series-alias.txt +++ b/website/data/add-series-alias.txt @@ -16,10 +16,10 @@ NCIS: New Orleans NCIS NO Proof (2015) Proof (US) Resurrection Resurrection (US) Revolution Revolution (2012) +Scream Scream The TV Series The Big Bang Theory TBBT The Bridge (2013) The Bridge (US) The Code (2014) The Code (AU) The Late Late Show with Craig Ferguson Craig Ferguson The Walking Dead TWD -World Series of Poker WSOP -Scream Scream The TV Series +World Series of Poker WSOP \ No newline at end of file