Combine Watch Script And AMC?

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
SpencerC77
Posts: 10
Joined: 11 Oct 2013, 14:02

Combine Watch Script And AMC?

Post 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!
User avatar
rednoah
The Source
Posts: 23006
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Combine Watch Script And AMC?

Post 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.
:idea: Please read the FAQ and How to Request Help.
SpencerC77
Posts: 10
Joined: 11 Oct 2013, 14:02

Re: Combine Watch Script And AMC?

Post 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 (?_?)
User avatar
rednoah
The Source
Posts: 23006
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Combine Watch Script And AMC?

Post 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.
:idea: Please read the FAQ and How to Request Help.
User avatar
rednoah
The Source
Posts: 23006
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Combine Watch Script And AMC?

Post 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.
:idea: Please read the FAQ and How to Request Help.
strategiry
Donor
Posts: 4
Joined: 18 Sep 2014, 05:59

Re: Combine Watch Script And AMC?

Post 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 (°_°)
User avatar
rednoah
The Source
Posts: 23006
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Combine Watch Script And AMC?

Post by rednoah »

This might help:
http://pastebin.com/6v4V5Bk7

Make sure you're using the latest revision.
:idea: Please read the FAQ and How to Request Help.
strategiry
Donor
Posts: 4
Joined: 18 Sep 2014, 05:59

Re: Combine Watch Script And AMC?

Post 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!
User avatar
rednoah
The Source
Posts: 23006
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Combine Watch Script And AMC?

Post 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.
:idea: Please read the FAQ and How to Request Help.
strategiry
Donor
Posts: 4
Joined: 18 Sep 2014, 05:59

Re: Combine Watch Script And AMC?

Post 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
Post Reply