* added a groovy sample post-processing script for utorrent

This commit is contained in:
Reinhard Pointner 2012-04-26 11:25:58 +00:00
parent 820a5594ba
commit 7a355d676f
4 changed files with 64 additions and 3 deletions

View File

@ -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));
}

View File

@ -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) }

View File

@ -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)
}
}

View File

@ -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}"
}