Combine amc and watcher scripts

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
Amishman
Donor
Posts: 56
Joined: 29 Dec 2013, 15:54

Combine amc and watcher scripts

Post by Amishman »

I was wondering if there is an easy way to combine amc and the watcher script together? What I'm looking for is all the features and options of amc but the input is a folder it is watching. So, anything put into the watched folder is run through amc.

My guess is that it should be easy to just swap out the input source but i'm not sure. I looked at both groovy scripts but I dont know enough about programming to see the part of code that would need to be removed for it to work.
Amishman
Donor
Posts: 56
Joined: 29 Dec 2013, 15:54

Re: Combine amc and watcher scripts

Post by Amishman »

I just found this forum post:
http://www.filebot.net/forums/viewtopic.php?f=4&t=1004

This is what I want to do but I am receiving an error when I try to run it.

C:\Rm_Finished_Torrents>filebot -script C:\Users\Amishman\Desktop\watcher_test.g
roovy
Jan 17, 2014 5:28:45 PM java.util.prefs.WindowsPreferences <init>
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0
x80000002. Windows RegCreateKeyEx(...) returned error code 5.
MultipleCompilationErrorsException: startup failed:
Script3.groovy: 1: expecting EOF, found 'watchman' @ line 1, column 6.
?def watchman = args.watch { changes ->
^

1 error

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script3.groovy: 1: expecting EOF, found 'watchman' @ line 1, column 6.
?def watchman = args.watch { changes ->
^

1 error

at net.sourceforge.filebot.cli.ScriptShell.evaluate(ScriptShell.java:102
)
at net.sourceforge.filebot.cli.ScriptShell.runScript(ScriptShell.java:95
)
at net.sourceforge.filebot.cli.ArgumentProcessor.process(ArgumentProcess
or.java:125)
at net.sourceforge.filebot.Main.main(Main.java:190)
Failure (░_░)
Launch4j: Failed to run the given command.
I'm sure I am doing something wrong. Here is my script.

Code: Select all

def watchman = args.watch { changes ->
   execute('filebot', '-script', 'fn:amc', '-non-strict', '--output G:/', 'G:/Watched', '--log-file amc.log', '--action move', '--conflict override', --

def "seriesFormat=TV/{n}/{'Season '+s.pad (1)}/{s00e00} {t}/{n} {s00e00} {t}" "movieFormat=New Movies/{n} ({y}) {\"[$vf]\"}/{n} ({y})" --def clean=y --

def plex=localhost)
}

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

println "Waiting for events"
if (console) { console.readLine() } else { sleep(Long.MAX_VALUE) } // keep running and watch for changes
Any ideas?
User avatar
rednoah
The Source
Posts: 22994
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Combine amc and watcher scripts

Post by rednoah »

You're code has syntax errors. Your String literals are wrong.

If you pass in arguments just use '''...''' to avoid any escape issue that you may have with " or '
:idea: Please read the FAQ and How to Request Help.
Amishman
Donor
Posts: 56
Joined: 29 Dec 2013, 15:54

Re: Combine amc and watcher scripts

Post by Amishman »

I think I am getting closer. This is my new error.
MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.?def() is applicable for argument types: (Script2$1) values: [Script2$1@1961e2a]
Possible solutions: grep(), get(java.lang.String), grep(java.lang.Object), use([Ljava.lang.Object;), wait(), find()
groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.?def() is applicable for argument types: (Script2$1) values: [Script2$1@1961e2a]
Possible solutions: grep(), get(java.lang.String), grep(java.lang.Object), use([Ljava.lang.Object;), wait(), find()
at Script3.run(Script3.groovy:1)
at net.sourceforge.filebot.cli.ScriptShell.evaluate(ScriptShell.java:102
)
at net.sourceforge.filebot.cli.ScriptShell.runScript(ScriptShell.java:95
)
at net.sourceforge.filebot.cli.ArgumentProcessor.process(ArgumentProcess
or.java:125)
at net.sourceforge.filebot.Main.main(Main.java:190)
Failure (░_░)
Launch4j: Failed to run the given command.
Here is my code:

Code: Select all

def watchman = args.watch { changes ->
   execute('''filebot -script fn:amc -non-strict --output "G:/" "G:/Watched" --log-file amc.log --action move --conflict override --def "seriesFormat=TV/{n}/{'Season '+s.pad (1)}/{s00e00} {t}/{n} {s00e00} {t}" "movieFormat=New Movies/{n} ({y}) {\"[$vf]\"}/{n} ({y})" --def clean=y --def plex=localhost''')
}
User avatar
rednoah
The Source
Posts: 22994
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Combine amc and watcher scripts

Post by rednoah »

I tested with the latest revision. Your code seems to work.

You probably have issues in the rest of the script.
:idea: Please read the FAQ and How to Request Help.
Amishman
Donor
Posts: 56
Joined: 29 Dec 2013, 15:54

Re: Combine amc and watcher scripts

Post by Amishman »

This is the whole script.

Code: Select all

def watchman = args.watch { changes ->
   execute('''filebot -script fn:amc -non-strict --output "G:/" "G:/Watched" --log-file amc.log --action move --conflict override --def "seriesFormat=TV/{n}/{'Season '+s.pad (1)}/{s00e00} {t}/{n} {s00e00} {t}" "movieFormat=New Movies/{n} ({y}) {\"[$vf]\"}/{n} ({y})" --def clean=y --def plex=localhost''')
}

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

println "Waiting for events"
if (console) { console.readLine() } else { sleep(Long.MAX_VALUE) } // keep running and watch for changes
I just put that in a batch file and run it. Should I be doing it another way?
User avatar
rednoah
The Source
Posts: 22994
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Combine amc and watcher scripts

Post by rednoah »

batch file as in .bat file? Not sure what you mean, that doesn't make sense.

groovy script should be .groovy files and you should use filebot to execute the script with filebot -script script.groovy

When I say "latest version" I don't mean version 3.8 but the absolutely latest revision.
:idea: Please read the FAQ and How to Request Help.
Amishman
Donor
Posts: 56
Joined: 29 Dec 2013, 15:54

Re: Combine amc and watcher scripts

Post by Amishman »

I created .bat file to execute the script. This is the script in the .bat file

Code: Select all

filebot -script C:\Users\Amishman\Desktop\watcher_test.groovy
I just updated to the latest revision FileBot.jar 2014-01-17. It had 161 downloads this week.

I tried running it from the CLI.

Code: Select all

C:\Users\Amishman\Desktop>filebot -script watcher_test.groovy
I still received the same error.
MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.?def() is applicable for argument types: (Script2$1) values: [Script2$1@1e7cb19]
Possible solutions: grep(), get(java.lang.String), use([Ljava.lang.Object;), grep(java.lang.Object), wait(), find()
groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.
jsr223.GroovyScriptEngineImpl.?def() is applicable for argument types: (Script2$1) values: [Script2$1@1e7cb19]
Possible solutions: grep(), get(java.lang.String), use([Ljava.lang.Object;), grep(java.lang.Object), wait(), find()
at Script3.run(Script3.groovy:1)
at net.sourceforge.filebot.cli.ScriptShell.evaluate(ScriptShell.java:91)
at net.sourceforge.filebot.cli.ScriptShell.runScript(ScriptShell.java:85)
at net.sourceforge.filebot.cli.ArgumentProcessor.process(ArgumentProcessor.java:123)
at net.sourceforge.filebot.Main.main(Main.java:194)
Failure (░_░)
Launch4j: Failed to run the given command.
User avatar
rednoah
The Source
Posts: 22994
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Combine amc and watcher scripts

Post by rednoah »

It all works fine.

I guess you're using a crappy windows editor that adds a byte marker to the beginning of the file, which makes it illegal groovy code. Use a good editor like notepad2 or notepad++ and NEVER EVER using anything made by microsoft like editor, wordpad or word.
:idea: Please read the FAQ and How to Request Help.
Amishman
Donor
Posts: 56
Joined: 29 Dec 2013, 15:54

Re: Combine amc and watcher scripts

Post by Amishman »

ok, I used notepad++ to make the groovy script. When I run the script, it now says "waiting for event". I take it to mean that it is watching the G:/Watched folder. I put a tv show into the folder and nothing happens that I can tell. The TV show has not been moved or renamed and it has been about 15 minutes. I thought the time was set for 5 seconds?
User avatar
rednoah
The Source
Posts: 22994
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Combine amc and watcher scripts

Post by rednoah »

I've tried the same script and it starts working after 5 seconds when a file is added.

Is this what you're calling?

Code: Select all

filebot -script watcher_test.groovy
How would it know which folder to watch?

Code: Select all

filebot -script watcher_test.groovy /path/to/folder/to/watch
:idea: Please read the FAQ and How to Request Help.
Amishman
Donor
Posts: 56
Joined: 29 Dec 2013, 15:54

Re: Combine amc and watcher scripts

Post by Amishman »

I thought I was telling it what folder to watch in the script but now that you mention it. I was telling the amc script not the watcher script. It is working great now.

I just made donation to Thank you so much for all your help.
Amishman
Donor
Posts: 56
Joined: 29 Dec 2013, 15:54

Re: Combine amc and watcher scripts

Post by Amishman »

I was doing some testing and almost everything is working perfectly. The only thing that I can tell so far that is not working properly is the movie rename part. It does not add the 720p or 1080p to the folder name.

Code: Select all

"movieFormat=New Movies/{n} ({y}) {\"[$vf]\"}/{n} ({y})"
The code works properly when uTorrent downloads the file but it doesn't worl in the watched folder. I'm guessing it has to do with the quotes but I cant seem to find the right code.
User avatar
bonelifer
Power User
Posts: 81
Joined: 23 Mar 2013, 18:27

Re: Combine amc and watcher scripts

Post by bonelifer »

The Escape tool gave me this, difference is it escaped the "$" sign:

Code: Select all

"movieFormat=New Movies/{n} ({y}) {\"[\$vf]\"}/{n} ({y})"
Escape tool:
filename -script fn:escape
Amishman
Donor
Posts: 56
Joined: 29 Dec 2013, 15:54

Re: Combine amc and watcher scripts

Post by Amishman »

Thanks bonelifer but that doesn't work. It just gives the name and year of the movie - Caddyshack (1980) in the folder name but not resolution - Caddyshack (1980) [1080p].

For it to work in uTorrent I had to remove the \ before the $. The script above works perfect in uTorrent for my naming scheme.
G:\New Movies\Caddyshack (1980) [1080p]\Caddyshack (1980).mp4
User avatar
rednoah
The Source
Posts: 22994
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Combine amc and watcher scripts

Post by rednoah »

Yeah, but now you have the cmdline String in the Groovy code so it needs to be Groovy String escaped, not Windows CMD escaped, or possibly both.

Check the amc output and see what amc thinks you have passed in, you should see the issue right away which part doesn't get passed along as you had thought.
:idea: Please read the FAQ and How to Request Help.
Amishman
Donor
Posts: 56
Joined: 29 Dec 2013, 15:54

Re: Combine amc and watcher scripts

Post by Amishman »

This is what is in my amc.log.
Jan 20, 2014 3:47:18 PM java.util.prefs.WindowsPreferences <init>
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
Parameter: seriesFormat = TV/{n}/{'Season '+s.pad (1)}/{s00e00} {t}/{n} {s00e00} {t}
Parameter: movieFormat = New Movies/{n} ({y}) {[$vf]}/{n} ({y})
Parameter: clean = y
Parameter: plex = localhost
Argument: G:\Watched
Done ヾ(@⌒ー⌒@)ノ
It doesn't tell me that it has renamed anything but the file is being renamed.
User avatar
rednoah
The Source
Posts: 22994
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Combine amc and watcher scripts

Post by rednoah »

Then you're confusing something, running multiple watchers or something, I donno, I can only tell you that in this run you show me here nothing has been renamed.


EDIT: This is not valid format code:

NO

Code: Select all

{[$vf]}
YES (String expression)

Code: Select all

{"[$vf]"}
YES (Array expression)

Code: Select all

{[vf]}
:idea: Please read the FAQ and How to Request Help.
Amishman
Donor
Posts: 56
Joined: 29 Dec 2013, 15:54

Re: Combine amc and watcher scripts

Post by Amishman »

It's working now.

Code: Select all

{[vf]}
got it working.

It's possible I had multiple watching scripts running but I'm not sure.

Thanks for all your help.
Post Reply