@kim -
Thanks for the SO link, I'll poke at that a bit and search for some other groovy alternatives to the native import statement.
Your idea is good and mirrors what I have found out when using filebot --script to run groovy scripts, however that seems to only work for variables you declare in the script directly executed by filebot. If defined in a script that is included in the main script using the filebot include() method, these doesn't work for anything outside that script (so you can't use them in main or another included script)
There is also the @Field groovy transformation which can be used with defined variables to make then "global" as an FYI -
https://groovy-lang.org/structure.html#_variables
@rednoah
I wouldn't say it's entirely a groovy thing, as the import statement behaves different between a groovy script run directly by the groovy interpreter and a groovy script run by filebot -script
For example, this works with a script called directly by the groovy interpreter (groovy test_mainscript.groovy)
test_mainscript.groovy
Code: Select all
import lib.Constants
// Adding it as a Static variable to a class and calling it directly works
println("Main Sript")
println("Main Script referencing lib variable airDateOrderMatcherRegexStatic:[${Constants.airDateOrderMatcherRegexStatic}]")
// Adding it as a public variable to a class and instantiating it works
Constants myConstants = new Constants()
println("Main Script referencing lib myConstants.property airDateOrderMatcherRegexPublic:[${myConstants.airDateOrderMatcherRegexPublic}]")
lib/Constants.groovy
Code: Select all
package lib
class Constants {
static String airDateOrderMatcherRegexStatic = /(?i)\b(?<![\.\[(])((S\d{1,2}|\d{1,2})(?>\.|\s)?([ExS]\d{1,4})[_]?(?>v\d{1,2})?)\b(?![\.\])=])/
public String airDateOrderMatcherRegexPublic = /(?i)\b(?<![\.\[(])((S\d{1,2}|\d{1,2})(?>\.|\s)?([ExS]\d{1,4})[_]?(?>v\d{1,2})?)\b(?![\.\])=])/
def airDateOrderMatcherRegexDef = /(?i)\b(?<![\.\[(])((S\d{1,2}|\d{1,2})(?>\.|\s)?([ExS]\d{1,4})[_]?(?>v\d{1,2})?)\b(?![\.\])=])/
}
However trying to run it using filebot -script produces an error when it tries to import the local groovy class (I just assumed it wasn't possible to import local files, which is why there is the include() method)
Code: Select all
startup failed:
Script1.groovy: 2: unable to resolve class lib.Constants
@ line 2, column 1.
import lib.Constants
^
1 error
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 2: unable to resolve class lib.Constants
@ line 2, column 1.
import lib.Constants
^
1 error
at net.filebot.cli.ScriptShell.evaluate(Unknown Source)
at net.filebot.cli.ScriptShell.runScript(Unknown Source)
at net.filebot.cli.ArgumentProcessor.runScript(Unknown Source)
at net.filebot.cli.ArgumentProcessor.run(Unknown Source)
at net.filebot.Main.main(Unknown Source)
Error (o_O)
Switching to using the include(), however I can't seem to instantiate the Constants class, nor access any of it's variables/constants, with a groovy script like this ..
filebot -script test_filebot_mainscript.groovy
Code: Select all
include('lib/Constants')
// Produces error
// No such property: airDateOrderMatcherRegexStatic for class: Script1
println("Main Script referencing lib variable airDateOrderMatcherRegexStatic:[${airDateOrderMatcherRegexStatic}]")
// Produces Error
// No such property: Constants for class: Script1
println("Main Sript")
println("Main Script referencing lib variable airDateOrderMatcherRegexStatic:[${Constants.airDateOrderMatcherRegexStatic}]")
// Produces Error
// unable to resolve class Constants
Constants myConstants = new Constants()
println("Main Script referencing lib myConstants.property airDateOrderMatcherRegexPublic:[${myConstants.airDateOrderMatcherRegexPublic}]")
// Produces Error
// No such property: airDateOrderMatcherRegexDef for class: Script1
println("Main Script referencing lib variable airDateOrderMatcherRegexDef:[${airDateOrderMatcherRegexDef}]")
and run using
Code: Select all
filebot -script test_filebot_mainscript.groovy
I will poke at this a bit more and post if I can find any workarounds. Thanks for the suggestions.