From 38d9903d0f8dd5eb1c23246cc0ee5d07beafee3f Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Wed, 2 Nov 2011 18:19:09 +0000 Subject: [PATCH] * added PrintMediaInfo command in CLI and scripting interface --- source/net/sourceforge/filebot/cli/ArgumentBean.java | 5 ++++- .../sourceforge/filebot/cli/ArgumentProcessor.java | 11 ++++++++++- .../net/sourceforge/filebot/cli/CmdlineInterface.java | 3 +++ .../sourceforge/filebot/cli/CmdlineOperations.java | 9 +++++++-- .../sourceforge/filebot/cli/ScriptShell.lib.groovy | 8 ++++++++ website/data/shell/mi.groovy | 9 +++++++++ 6 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 website/data/shell/mi.groovy diff --git a/source/net/sourceforge/filebot/cli/ArgumentBean.java b/source/net/sourceforge/filebot/cli/ArgumentBean.java index 42a6e7ad..74fb9970 100644 --- a/source/net/sourceforge/filebot/cli/ArgumentBean.java +++ b/source/net/sourceforge/filebot/cli/ArgumentBean.java @@ -28,6 +28,9 @@ public class ArgumentBean { @Option(name = "-list", usage = "Fetch episode list") public boolean list = false; + @Option(name = "-mediainfo", usage = "Get media info") + public boolean mediaInfo = false; + @Option(name = "--db", usage = "Episode/Movie database", metaVar = "[TVRage, AniDB, TheTVDB] or [OpenSubtitles, TheMovieDB]") public String db; @@ -78,7 +81,7 @@ public class ArgumentBean { public boolean runCLI() { - return rename || getSubtitles || check || list || script != null; + return rename || getSubtitles || check || list || mediaInfo || script != null; } diff --git a/source/net/sourceforge/filebot/cli/ArgumentProcessor.java b/source/net/sourceforge/filebot/cli/ArgumentProcessor.java index 196f9a49..a9d31586 100644 --- a/source/net/sourceforge/filebot/cli/ArgumentProcessor.java +++ b/source/net/sourceforge/filebot/cli/ArgumentProcessor.java @@ -41,7 +41,7 @@ public class ArgumentProcessor { CLILogger.setLevel(args.getLogLevel()); try { - // print operations + // print episode info if (args.list) { for (String eps : cli.fetchEpisodeList(args.query, args.format, args.db, args.lang)) { System.out.println(eps); @@ -49,6 +49,15 @@ public class ArgumentProcessor { return 0; } + // print media info + if (args.mediaInfo) { + for (File file : args.getFiles(true)) { + System.out.println(cli.getMediaInfo(file, args.format)); + } + return 0; + } + + // execute CLI operations if (args.script == null) { // file operations Set files = new LinkedHashSet(args.getFiles(true)); diff --git a/source/net/sourceforge/filebot/cli/CmdlineInterface.java b/source/net/sourceforge/filebot/cli/CmdlineInterface.java index 09c2a663..78874e29 100644 --- a/source/net/sourceforge/filebot/cli/CmdlineInterface.java +++ b/source/net/sourceforge/filebot/cli/CmdlineInterface.java @@ -24,4 +24,7 @@ public interface CmdlineInterface { List fetchEpisodeList(String query, String format, String db, String lang) throws Exception; + + String getMediaInfo(File file, String format) throws Exception; + } diff --git a/source/net/sourceforge/filebot/cli/CmdlineOperations.java b/source/net/sourceforge/filebot/cli/CmdlineOperations.java index 01e4ae4a..8791dd70 100644 --- a/source/net/sourceforge/filebot/cli/CmdlineOperations.java +++ b/source/net/sourceforge/filebot/cli/CmdlineOperations.java @@ -637,8 +637,6 @@ public class CmdlineOperations implements CmdlineInterface { Locale locale = getLanguage(languageName).toLocale(); SearchResult hit = selectSearchResult(query, service.search(query, locale), false); - - Analytics.trackEvent("CLI", "PrintEpisodeList", hit.getName()); List episodes = new ArrayList(); for (Episode it : service.getEpisodeList(hit, locale)) { @@ -650,6 +648,13 @@ 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(file, file)); + } + + private Language getLanguage(String lang) { // try to look up by language code Language language = Language.getLanguage(lang); diff --git a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy index f9ca1ddc..b1c720f3 100644 --- a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy +++ b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy @@ -3,6 +3,7 @@ import static groovy.io.FileType.* 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) } @@ -35,6 +36,13 @@ def compute(args) { args = _defaults(args) _guarded { _cli.compute(_files(args), args.output, args.encoding) } } +def fetchEpisodeList(args) { args = _defaults(args) + _guarded { _cli.fetchEpisodeList(args.query, args.format, args.db, args.lang) } +} + +def getMediaInfo(args) { args = _defaults(args) + _guarded { _cli.getMediaInfo(args.file, args.format) } +} /** diff --git a/website/data/shell/mi.groovy b/website/data/shell/mi.groovy new file mode 100644 index 00000000..142028ec --- /dev/null +++ b/website/data/shell/mi.groovy @@ -0,0 +1,9 @@ +// filebot -script "http://filebot.sourceforge.net/data/shell/mi.groovy" --format "{fn} [{resolution} {af} {vc} {ac}]" + +/* + * Print media info for all video files using given or default format pattern + */ +args.getFiles() +.findAll { it.isVideo() } +.sort { a, b -> a.name.compareTo(b.name) } +.each { println getMediaInfo(file:it) }