How can I use a variable from one include() script in another include() script?
Posted: 03 Jul 2021, 15:23
I am using filebot's include() method to source several "libraries", which are groovy scripts (not classes) in a groovy script executed using filebot --script <script>.
I have several libraries, and multiple methods within those libraries.
in my main script I use include() to source the "library" scripts.
include('lib/detect')
I use alot of regex, some of which is duplicated within those libraries, and I would like to use a single variable in one library and reference that variable in both the main script and other libraries.
I have only been able to figure out how to declare a variable within a specific library for use with that specific library (but I can't figure out how to use it in other library files) using groovy.transform.field
for example
lib\detect.groovy
and I can use that in a method (within lib\detect.groovy) like so
Any ideas on how (if) this can be done?
I have been unsuccessful in using import within the main script or library script to import local groovy scripts/classes
I have tried creating a lib\constants.groovy class (which I can't figure out how to import) with the variable declared public, but can't figure out how to reference/use it in the lib\detect.groovy method (even using include()), I just get the "No such property" error ..
I have several libraries, and multiple methods within those libraries.
in my main script I use include() to source the "library" scripts.
include('lib/detect')
I use alot of regex, some of which is duplicated within those libraries, and I would like to use a single variable in one library and reference that variable in both the main script and other libraries.
I have only been able to figure out how to declare a variable within a specific library for use with that specific library (but I can't figure out how to use it in other library files) using groovy.transform.field
for example
lib\detect.groovy
Code: Select all
@Field String airDateOrderMatcherRegex = /(?i)\b(?<![\.\[(])((S\d{1,2}|\d{1,2})(?>\.|\s)?([ExS]\d{1,4})[_]?(?>v\d{1,2})?)\b(?![\.\])=])/
Code: Select all
return filename =~ /${airDateOrderMatcherRegex}/
I have been unsuccessful in using import within the main script or library script to import local groovy scripts/classes
I have tried creating a lib\constants.groovy class (which I can't figure out how to import) with the variable declared public, but can't figure out how to reference/use it in the lib\detect.groovy method (even using include()), I just get the "No such property" error ..
Code: Select all
No such property: airDateOrderMatcherRegex for class: lib.Script7