[DOCS] Split code into external *.groovy script files

All about user-defined episode / movie format expressions
Locked
User avatar
rednoah
The Source
Posts: 21345
Joined: 16 Nov 2011, 08:59

[DOCS] Split code into external *.groovy script files

Post by rednoah »

1.
Use @format.groovy syntax to include external format expression code at compile time:

Code: Select all

@/path/to/TargetFolder.groovy
@/path/to/MovieNaming.groovy
@/path/to/MediaInfoTags.groovy

Image


:!: Note that the @file syntax for reading command-line arguments from external text files is a distinct concept and takes precedence on the command-line, so literal argument values cannot start with an @ character, so we start with a \n character (New Line) instead:

Code: Select all

filebot … --format "
@/path/to/TargetFolder.groovy
@/path/to/MovieNaming.groovy
@/path/to/MediaInfoTags.groovy
"

:idea: The --format option also accepts *.groovy files as input and will read the text content of the given file as option value:

Code: Select all

--format "/path/to/MyFormat.groovy"

:idea: You can thus have multiple levels of indirection, i.e. (CLI only) argument level, (CLI only) option level, (both GUI and CLI) format level:

Code: Select all

$ cat /path/to/MyCommand.args
-rename
-r
--db
TheMovieDB
--format
/path/to/MyFormat.groovy

Code: Select all

$ cat /path/to/MyFormat.groovy
@/path/to/TargetFolder.groovy
@/path/to/MovieNaming.groovy
@/path/to/MediaInfoTags.groovy

Code: Select all

$ cat /path/to/MovieNaming.groovy
{ plex.id }


2.
Dynamically evaluate external Groovy scripts at runtime:

Code: Select all

{ include '/path/to/TargetFolder.groovy' }
{ include '/path/to/MovieNaming.groovy' }
{ include '/path/to/MediaInfoTags.groovy' }

Code: Select all

{ include "/path/to/MovieFormat.${y > 1980 ? 'Recent' : 'Classic'}.groovy" }


3.
Dynamically evaluate Groovy code at runtime:

Code: Select all

{ evaluate('plex.name') }


:arrow: groovy.lang.Script
:arrow: net.filebot.format.ExpressionFormatFunctions
:idea: Please read the FAQ and How to Request Help.
Locked