// filebot sync-amc.groovy --output "X:/output" -non-strict --action move --conflict skip
// SCP config
def config = [
server: 'example.org',
username: 'monkey',
password: 'tiger',
remoteFolder: '/home/monkey/complete/',
localFolder: 'X:/sync/'
]
// AMC config
def amc = [
minFileSize: 0,
minLengthMS: 0,
excludeList: new File(config.localFolder, 'local.excludes')
]
def excludeList = new File(config.localFolder, 'remote.excludes')
def excludes = (excludeList.exists() ? excludeList.readLines() : []) as HashSet
// *********** SYNC *********** //
include('fn:lib/ant')
def remoteFilesList = sshexec(command: """find "${config.remoteFolder}" -type f""", host: config.server, username: config.username, password: config.password)
def newRemoteFiles = remoteFilesList.readLines().findAll{ !excludes.contains(it) }
println "[FIND] ${newRemoteFiles.size()} new files"
if (newRemoteFiles.isEmpty())
return;
newRemoteFiles.each{ remotePath ->
def localPath = new File(config.localFolder, remotePath)
println "[SYNC] Copy [${remotePath}] to [${localPath}]"
scp(host: config.server, username: config.username, password: config.password, file: remotePath, localDir: localPath.parentFile)
excludeList.append(remotePath + '\n') // add remote path to local exclude list
}
// *********** AMC *********** //
new File(config.localFolder).listFiles().findAll{ it.isDirectory() }.each{ root ->
println "[AMC] Execute AMC on ${root}"
executeScript('fn:amc', amc, root)
executeScript('fn:cleaner', [root:true], root)
}