From 7a355d676fae20a9c99846ab1d9fd28ae060e857 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Thu, 26 Apr 2012 11:25:58 +0000 Subject: [PATCH] * added a groovy sample post-processing script for utorrent --- .../filebot/cli/CmdlineOperations.java | 2 +- .../filebot/cli/ScriptShell.lib.groovy | 2 +- website/scripts/sorty.groovy | 8 ++- website/scripts/utorrent-postprocess.groovy | 55 +++++++++++++++++++ 4 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 website/scripts/utorrent-postprocess.groovy diff --git a/source/net/sourceforge/filebot/cli/CmdlineOperations.java b/source/net/sourceforge/filebot/cli/CmdlineOperations.java index ffdccf58..4b695a4f 100644 --- a/source/net/sourceforge/filebot/cli/CmdlineOperations.java +++ b/source/net/sourceforge/filebot/cli/CmdlineOperations.java @@ -479,8 +479,8 @@ public class CmdlineOperations implements CmdlineInterface { // rename file, throw exception on failure if (!destination.equals(source) && !destination.exists()) { + CLILogger.info(format("[%s] Rename [%s] to [%s]", renameAction, it.getKey(), it.getValue())); destination = renameAction.rename(source, destination); - CLILogger.info(format("[%s] Renamed [%s] to [%s]", renameAction, it.getKey(), it.getValue())); } else { CLILogger.info(format("Skipped [%s] because [%s] already exists", source, destination)); } diff --git a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy index d1841747..6a0215b0 100644 --- a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy +++ b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy @@ -15,7 +15,7 @@ File.metaClass.getDir = { getParentFile() } File.metaClass.hasFile = { c -> isDirectory() && listFiles().find(c) } String.metaClass.getFiles = { c -> new File(delegate).getFiles(c) } -File.metaClass.getFiles = { c -> def files = []; traverse(type:FILES) { files += it }; return c ? files.findAll(c).sort() : files.sort() } +File.metaClass.getFiles = { c -> if (delegate.isFile()) return [delegate]; def files = []; traverse(type:FILES, visitRoot:true) { files += it }; return c ? files.findAll(c).sort() : files.sort() } List.metaClass.getFiles = { c -> findResults{ it.getFiles(c) }.flatten().unique() } String.metaClass.getFolders = { c -> new File(delegate).getFolders(c) } diff --git a/website/scripts/sorty.groovy b/website/scripts/sorty.groovy index c8ab8869..390279d8 100644 --- a/website/scripts/sorty.groovy +++ b/website/scripts/sorty.groovy @@ -54,6 +54,12 @@ movieDir.getFolders{ !it.hasFile{ incomplete(it) } && it.hasFile{ it.isVideo() } // make XBMC scan for new content xbmc.each { host -> telnet(host, 9090) { writer, reader -> - writer.println('{"jsonrpc": "2.0", "method": "VideoLibrary.ScanForContent", "id": 1}') + // API call for latest XBMC release + def msg = '{"id":1,"method":"VideoLibrary.Scan","params":[],"jsonrpc":"2.0"}' + + // API call for XBMC Dharma-Release or older + // def msg = '{"id":1,"method":"VideoLibrary.ScanForContent","params":[],"jsonrpc":"2.0"}' + + writer.println(msg) } } diff --git a/website/scripts/utorrent-postprocess.groovy b/website/scripts/utorrent-postprocess.groovy new file mode 100644 index 00000000..c80388e5 --- /dev/null +++ b/website/scripts/utorrent-postprocess.groovy @@ -0,0 +1,55 @@ +// filebot -script "http://filebot.sf.net/scripts/utorrent-postprocess.groovy" "%D\%N" --output "X:/media" --action copy --conflict override -non-strict -trust-script -Xxbmc=localhost +println "Input: $args" +println "Parameters: $_args.parameters" + +def input = args.getFiles() + +// extract archives if necessary +input += extract(file:input) + +// process only media files +input = input.findAll{ it.isVideo() || it.isSubtitle() } + + +// group episodes/movies and rename according to XBMC standards +def groups = input.groupBy { + def tvs = detectSeriesName(it) + def mov = detectMovie(it, false) + println "$it.name [series: $tvs, movie: $mov]" + + // DECIDE EPISODE VS MOVIE (IF NOT CLEAR) + if (tvs && mov) { + if (it.name =~ "(?i:$tvs - .+)" || parseEpisodeNumber(it.name) || parseDate(it.name)) { + println "Exclude Movie: $mov" + mov = null + } else if (detectMovie(it, true)) { + println "Exclude Series: $tvs" + tvs = null + } + } + return [tvs:tvs, mov:mov] +} + +groups.each{ group, files -> + // EPISODE MODE + if (group.tvs && !group.mov) { + return rename(file:files, format:'TV Shows/{n}/{episode.special ? "Special" : "Season "+s}/{n} - {episode.special ? "S00E"+special.pad(2) : s00e00} - {t}', db:'TheTVDB') + } + + // MOVIE MODE + if (group.mov && !group.tvs) { + return rename(file:files, format:'Movies/{n} ({y}){" CD$pi"}{".$lang"}', db:'TheMovieDB') + } +} + + + +// make XBMC scan for new content +try { + telnet(xbmc, 9090) { writer, reader -> + def msg = '{"id":1,"method":"VideoLibrary.Scan","params":[],"jsonrpc":"2.0"}' + writer.println(msg) + } +} catch(e) { + println "${e.class.simpleName}: ${e.message}" +}