Advertisement
filebot

sync-amc.groovy

Jan 21st, 2014
600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 1.56 KB | None | 0 0
  1. // filebot sync-amc.groovy --output "X:/output" -non-strict --action move --conflict skip
  2.  
  3.  
  4. // SCP config
  5. def config = [
  6.     server: 'example.org',
  7.     username: 'monkey',
  8.     password: 'tiger',
  9.     remoteFolder: '/home/monkey/complete/',
  10.     localFolder: 'X:/sync/'
  11. ]
  12.  
  13.  
  14. // AMC config
  15. def amc = [
  16.     minFileSize: 0,
  17.     minLengthMS: 0,
  18.     excludeList: new File(config.localFolder, 'local.excludes')
  19. ]
  20.  
  21.  
  22. def excludeList = new File(config.localFolder, 'remote.excludes')
  23. def excludes = (excludeList.exists() ? excludeList.readLines() : []) as HashSet
  24.  
  25.  
  26. // ***********   SYNC   *********** //
  27.  
  28.  
  29. include('fn:lib/ant')
  30.  
  31. def remoteFilesList = sshexec(command: """find "${config.remoteFolder}" -type f""", host: config.server, username: config.username, password: config.password)
  32. def newRemoteFiles = remoteFilesList.readLines().findAll{ !excludes.contains(it) }
  33.  
  34. println "[FIND] ${newRemoteFiles.size()} new files"
  35. if (newRemoteFiles.isEmpty())
  36.     return;
  37.  
  38. newRemoteFiles.each{ remotePath ->
  39.     def localPath = new File(config.localFolder, remotePath)
  40.     println "[SYNC] Copy [${remotePath}] to [${localPath}]"
  41.     scp(host: config.server, username: config.username, password: config.password, file: remotePath, localDir: localPath.parentFile)
  42.  
  43.     excludeList.append(remotePath + '\n') // add remote path to local exclude list
  44. }
  45.  
  46.  
  47. // ***********   AMC   *********** //
  48.  
  49.  
  50. new File(config.localFolder).listFiles().findAll{ it.isDirectory() }.each{ root ->
  51.     println "[AMC] Execute AMC on ${root}"
  52.     executeScript('fn:amc', amc, root)
  53.     executeScript('fn:cleaner', [root:true], root)
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement