* make watcher/housekeeping more general

This commit is contained in:
Reinhard Pointner 2012-07-21 20:35:13 +00:00
parent 47cd4a8a2d
commit 1335105a58
3 changed files with 8 additions and 21 deletions

View File

@ -205,7 +205,7 @@ List.metaClass.sortBySimilarity = { prime, Closure toStringFunction = { obj -> o
// call scripts
def include(String input, Map parameters = [:], Object... args) {
// initialize default parameter
parameters.args = (args as List).findResults{ it as File }
parameters.args = (args as List).flatten().findResults{ it as File }
// run given script and catch exceptions
_guarded { _shell.runScript(input, new javax.script.SimpleBindings(parameters)) }

View File

@ -1,21 +1,17 @@
// filebot -script "http://filebot.sf.net/scripts/housekeeping.groovy" <folder>
// filebot -script fn:housekeeping /path/to/folder/ --output /output/folder/ --format <expression>
/*
* Watch folder for new tv shows and automatically
* move/rename new episodes into a predefined folder structure
* Watch folder for new tv shows and automatically move/rename new episodes
*/
// check for new media files once every 5 minutes
def updateFrequency = 5 * 60 * 1000
// V:/TV Shows/Stargate/Season 1/Stargate.S01E01.Pilot
def episodeFormat = "{com.sun.jna.Platform.isWindows() ? file[0] : home}/TV Shows/{n}{'/Season '+s}/{n.space('.')}.{s00e00}.{t.space('.')}"
// spawn daemon thread
Thread.startDaemon {
while (sleep(updateFrequency) || true) {
args.eachMediaFolder {
rename(folder:it, db: "thetvdb", format:episodeFormat)
rename(folder:it)
}
}
}

View File

@ -1,18 +1,9 @@
// filebot -script "http://filebot.sf.net/scripts/watcher.groovy" --format <expression> <folder>
// filebot -script fn:watcher /path/to/folder/ --output /output/folder/ --format <expression>
// SANITY CHECK
if (_prop['java.runtime.version'] < '1.7') throw new Exception('Java 7 required')
if (!(new File(_args.format ?: '').absolute)) throw new Exception('Absolute target path format required')
// watch folders and print files that were added/modified (requires Java 7)
def watchman = args.watch { changes ->
println "Processing $changes"
rename(file:changes)
// watch folders and print files that were added/modified
args.watch { changes ->
rename(file:changes)
}
// process after 5 minutes without any changes to the folder
watchman.setCommitDelay(5 * 60 * 1000)
println "Waiting for events"
console.readLine() // keep running and watch for changes