Page 1 of 1

Combine Watch Script And AMC?

Posted: 12 Oct 2013, 04:51
by SpencerC77
I have a remote server set up to automatically push files through SSH to my local machine. Would it be possible to use the watch script to watch the download directory and then run amc on the directory when all downloads are finished? I am very new at this and I having some trouble with it so I appreciate all the help I can get!

Re: Combine Watch Script And AMC?

Posted: 12 Oct 2013, 04:58
by rednoah
Here's the example that you can try and see if you get the right events after files have been uploaded:

Code: Select all

def watchman = args.watch { changes ->
   println changes
}

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

If that works you can try calling the amc script on the change set:

Code: Select all

def watchman = args.watch { changes ->
   executeScript('fn:amc', _def, changes)
}

watchman.commitDelay = 60 * 1000
watchman.commitPerFolder = true

println "Waiting for events"
if (console) { console.readLine() } else { sleep(Long.MAX_VALUE) } // keep running and watch for changes
The internal amc call will inherit all the options you pass when call the script.

Re: Combine Watch Script And AMC?

Posted: 13 Oct 2013, 00:58
by SpencerC77
I am getting this error when trying to run this as a groovy script:

Code: Select all

MultipleCompilationErrorsException: startup failed:
Script3.groovy: 1: unexpected char: '\' @ line 1, column 2.
   {\rtf1\ansi\ansicpg1252\cocoartf1187\cocoasubrtf400
    ^

1 error

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script3.groovy: 1: unexpected char: '\' @ line 1, column 2.
   {\rtf1\ansi\ansicpg1252\cocoartf1187\cocoasubrtf400
    ^

1 error

	at net.sourceforge.filebot.cli.ScriptShell.evaluate(Unknown Source)
	at net.sourceforge.filebot.cli.ScriptShell.runScript(Unknown Source)
	at net.sourceforge.filebot.cli.ArgumentProcessor.process(Unknown Source)
	at net.sourceforge.filebot.Main.main(Unknown Source)
Failure (?_?)

Re: Combine Watch Script And AMC?

Posted: 13 Oct 2013, 07:58
by rednoah
Looks like you're using the equivalent of MS Word to save your script file...

The groovy script has to be UTF-8 encoded plain-text file. Not some sort of RTF document.

Re: Combine Watch Script And AMC?

Posted: 13 Oct 2013, 10:30
by rednoah
Played with it and i think a sub-process might work best, but you'll have to specify the args in the script and not in the cmdline:

Code: Select all

def watchman = args.watch { changes ->
	execute('filebot', '-script', 'fn:amc', '-non-strict', '--output', '/path/to/files', changes)
}

watchman.commitDelay = 60 * 1000
watchman.commitPerFolder = false

println "Waiting for events"
if (console) { console.readLine() } else { sleep(Long.MAX_VALUE) } // keep running and watch for changes
You may need 3.8 RC for this one to work.

Re: Combine Watch Script And AMC?

Posted: 18 Sep 2014, 06:16
by strategiry
I'm trying to do something similar to OP, and am unable to get your supplied script (amc within watcher) working. Can you elaborate on how to specify the args in the script?

When I try to call the modified watcher with:

filebot -script "path\to\watcher.groovy" "pathto\stuff" --output "pathto\Export"

I get:
MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.def() is applicable for argument types: (net.filebot.cli.ScriptShellMethods$2) values: [net.filebot.cli.ScriptShellMethods$2@e5509d0]
Possible solutions: grep(), get(java.lang.String), grep(java.lang.Object), use([Ljava.lang.Object;), wait(), every()
groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.def() is applicable for argument types: (net.filebot.cli.ScriptShellMethods$2) values: [net.filebot.cli.ScriptShellMethods$2@e5509d0]
Possible solutions: grep(), get(java.lang.String), grep(java.lang.Object), use([Ljava.lang.Object;), wait(), every()
at Script1.run(Script1.groovy:1)
at net.filebot.cli.ScriptShell.evaluate(ScriptShell.java:60)
at net.filebot.cli.ScriptShell.runScript(ScriptShell.java:81)
at net.filebot.cli.ArgumentProcessor.process(ArgumentProcessor.java:108)
at net.filebot.Main.main(Main.java:191)
Failure (°_°)

Re: Combine Watch Script And AMC?

Posted: 18 Sep 2014, 09:34
by rednoah
This might help:
http://pastebin.com/6v4V5Bk7

Make sure you're using the latest revision.

Re: Combine Watch Script And AMC?

Posted: 19 Sep 2014, 07:10
by strategiry
Almost there, the watcher script works great when files are placed in the input folder. However, it does not trigger when folders are put in the input directory. How can I have the script do both?

Appreciate the support, thank you!

Re: Combine Watch Script And AMC?

Posted: 26 Sep 2014, 08:24
by rednoah
This should work:

Code: Select all

f.watchFolder(true, true, 5000)
See method definitions:

Code: Select all

FolderWatchService watchFolder(File self, Closure<?> callback)
FolderWatchService watchFolder(File self, boolean watchTree, boolean commitPerFolder, long commitDelay, final Closure<?> callback)
See net/filebot/cli/ScriptShellMethods.java for details.


But if you need to watch the entire tree you're probably doing something wrong already in your setup. I don't recommend watching more than one specific folder.

Re: Combine Watch Script And AMC?

Posted: 26 Sep 2014, 09:47
by strategiry
Yea it's not ideal, however I wanted to have a monitored folder where others could 'dump' their media files/folders into and then have filebot process/sort it into the correct folder structure that the rest of my own downloads/files already follow.

Edit: If I'm reading correctly, do you mean:

def output = '/Users/reinhard/Downloads/output/'
def input = '/Users/reinhard/Downloads/complete/'

(input as File).watchFolder(true, true, 5000) { files ->
executeScript('dev:amc', ['--action', 'duplicate', '-non-strict', '--output', output], [minFileSize:0], files)
}

sleep Integer.MAX_VALUE