filebot

watcher.fatty.groovy

Nov 1st, 2013
515
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 1.44 KB | None | 0 0
  1. def root = 'D:/workspace/testdata/AMC-TEST'
  2.  
  3. def configs = [
  4.     [inputDir: "$root/TV Shows", outputFormat: '''D:/TV Shows/{n}/Season {s}/{fn}''', db:'TheTVDB'],
  5.     [inputDir: "$root/Movies", outputFormat: '''D:/Movies/{n}/{fn}''', db:'TheMovieDB'],
  6.     [inputDir: "$root/Anime", outputFormat: '''D:/Anime/{primaryTitle}/{fn}''', db:'AniDB']
  7. ]
  8.  
  9. configs.each{ config ->
  10.     def watchman = new File(config.inputDir).watch { changes ->
  11.         // extract all
  12.         changes += extract(file:changes.findAll{ it.isArchive() }, output:'.')
  13.  
  14.         // rename all
  15.                 def renamedFiles = rename(file:changes, db:config.db, format:config.format)
  16.  
  17.                 def message = renamedFiles.name.join('\n')
  18.                 execute("sendemail.exe", "-f", "sender@mail.com", "-t", "recipient@mail.com", "-s", "smtp.server.com:port", "-u", "Changes", "-m", message)
  19.     }
  20.  
  21.     watchman.commitDelay = 5 * 1000         // default = 5s
  22.     watchman.commitPerFolder = true         // default = true
  23. }
  24.  
  25.  
  26. println "Waiting for events"
  27. if (console) { console.readLine() } else { sleep(Long.MAX_VALUE) } // keep running and watch for changes
Add Comment
Please, Sign In to add comment