filebot icon

watcher.fatty.groovy

filebot | PRO | 11/01/13 07:23:59 PM UTC | 0 ⭐ | 1025 👁️ | Never ⏰ | []
Groovy |

1.44 KB

|

None

|

0 👍

/

0 👎

def root = 'D:/workspace/testdata/AMC-TEST'
 
def configs = [
    [inputDir: "$root/TV Shows", outputFormat: '''D:/TV Shows/{n}/Season {s}/{fn}''', db:'TheTVDB'],
    [inputDir: "$root/Movies", outputFormat: '''D:/Movies/{n}/{fn}''', db:'TheMovieDB'],
    [inputDir: "$root/Anime", outputFormat: '''D:/Anime/{primaryTitle}/{fn}''', db:'AniDB']
]
 
configs.each{ config ->
    def watchman = new File(config.inputDir).watch { changes ->
        // extract all
        changes += extract(file:changes.findAll{ it.isArchive() }, output:'.')
 
        // rename all
                def renamedFiles = rename(file:changes, db:config.db, format:config.format)
 
                def message = renamedFiles.name.join('\n')
                execute("sendemail.exe", "-f", "[email protected]", "-t", "[email protected]", "-s", "smtp.server.com:port", "-u", "Changes", "-m", message)
    }
 
    watchman.commitDelay = 5 * 1000         // default = 5s
    watchman.commitPerFolder = true         // default = true
}
 
 
println "Waiting for events"
if (console) { console.readLine() } else { sleep(Long.MAX_VALUE) } // keep running and watch for changes

Comments