* support all -rename -get-subtitles -extract functionality out of the box in housekeeping and watcher scripts

This commit is contained in:
Reinhard Pointner 2012-07-23 04:54:50 +00:00
parent f9d2e9dbf8
commit 6b6839579e
3 changed files with 36 additions and 8 deletions

View File

@ -138,8 +138,8 @@ def createWatchService(Closure callback, List folders, boolean watchTree) {
} }
} }
// collect updates for 5 minutes and then batch process // collect updates for 500 ms and then batch process
watchService.setCommitDelay(5 * 60 * 1000) watchService.setCommitDelay(500)
watchService.setCommitPerFolder(watchTree) watchService.setCommitPerFolder(watchTree)
// start watching given files // start watching given files
@ -275,13 +275,15 @@ def _files(args) {
(args.folder as File).traverse(type:FILES, maxDepth:0) { files += it } (args.folder as File).traverse(type:FILES, maxDepth:0) { files += it }
} }
if (args.file) { 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 files += args.file as List
} else { } else {
files += args.file as File files += args.file as File
} }
} }
return files
// ignore invalid input
return files.flatten().findResults{ it as File }
} }

View File

@ -10,10 +10,23 @@ def updateFrequency = 5 * 60 * 1000
// spawn daemon thread // spawn daemon thread
Thread.startDaemon { Thread.startDaemon {
while (sleep(updateFrequency) || true) { while (sleep(updateFrequency) || true) {
// 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 { args.eachMediaFolder {
rename(folder:it) rename(folder:it)
} }
} }
}
} }
println "Press ENTER to abort" println "Press ENTER to abort"

View File

@ -1,9 +1,22 @@
// filebot -script fn:watcher /path/to/folder/ --output /output/folder/ --format <expression> // filebot -script fn:watcher /path/to/folder/ --output /output/folder/ --format <expression>
// watch folders and print files that were added/modified // watch folders and print files that were added/modified
args.watch { 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) rename(file:changes)
} }
watchman.commitDelay = 5 * 1000 // default = 5s
watchman.commitPerFolder = true // default = true
println "Waiting for events" println "Waiting for events"
console.readLine() // keep running and watch for changes console.readLine() // keep running and watch for changes