From 6b6839579e13db08fd26f5efb08dbb19370f2c8d Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 23 Jul 2012 04:54:50 +0000 Subject: [PATCH] * support all -rename -get-subtitles -extract functionality out of the box in housekeeping and watcher scripts --- .../filebot/cli/ScriptShell.lib.groovy | 10 ++++++---- website/scripts/housekeeping.groovy | 17 +++++++++++++++-- website/scripts/watcher.groovy | 17 +++++++++++++++-- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy index 36132fd5..07f52a98 100644 --- a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy +++ b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy @@ -138,8 +138,8 @@ def createWatchService(Closure callback, List folders, boolean watchTree) { } } - // collect updates for 5 minutes and then batch process - watchService.setCommitDelay(5 * 60 * 1000) + // collect updates for 500 ms and then batch process + watchService.setCommitDelay(500) watchService.setCommitPerFolder(watchTree) // start watching given files @@ -275,13 +275,15 @@ def _files(args) { (args.folder as File).traverse(type:FILES, maxDepth:0) { files += it } } if (args.file) { - if (args.file instanceof Iterable || args.file instanceof File[]) { + if (args.file instanceof Iterable || args.file instanceof Object[]) { files += args.file as List } else { files += args.file as File } } - return files + + // ignore invalid input + return files.flatten().findResults{ it as File } } diff --git a/website/scripts/housekeeping.groovy b/website/scripts/housekeeping.groovy index 407da0e7..dfc8611a 100644 --- a/website/scripts/housekeeping.groovy +++ b/website/scripts/housekeeping.groovy @@ -10,8 +10,21 @@ def updateFrequency = 5 * 60 * 1000 // spawn daemon thread Thread.startDaemon { while (sleep(updateFrequency) || true) { - args.eachMediaFolder { - rename(folder:it) + // extract all + if (_args.extract) { + extract(file:args.getFiles{ it.isArchive() }, output:'.') + } + + // subtitles for all + if (_args.getSubtitles) { + getMissingSubtitles(file:args.getFiles{ it.isVideo() }, output:'srt') + } + + // rename all + if (_args.rename) { + args.eachMediaFolder { + rename(folder:it) + } } } } diff --git a/website/scripts/watcher.groovy b/website/scripts/watcher.groovy index fb297129..b162a538 100644 --- a/website/scripts/watcher.groovy +++ b/website/scripts/watcher.groovy @@ -1,9 +1,22 @@ // filebot -script fn:watcher /path/to/folder/ --output /output/folder/ --format // watch folders and print files that were added/modified -args.watch { changes -> - rename(file:changes) +def watchman = args.watch { changes -> + // extract all + if (_args.extract) + changes += extract(file:changes.findAll{ it.isArchive() }, output:'.') + + // subtitles for all + if (_args.getSubtitles) + changes += getMissingSubtitles(file:changes.findAll{ it.isVideo() }, output:'srt') + + // rename all + if (_args.rename) + rename(file:changes) } +watchman.commitDelay = 5 * 1000 // default = 5s +watchman.commitPerFolder = true // default = true + println "Waiting for events" console.readLine() // keep running and watch for changes