Scripts and Automation Scripting interface usage manual

See Examples

About

FileBot makes scripting and automation as easy as it gets. Write modern Groovy code instead of bothering with cumbersome *.cmd or *.sh scripts. It's much more powerful and works the same on all operating systems.

The built-in functions are the same as in the CLI and parameter usage is also exactly the same.

Examples

Running Scripts

filebot -script "/path/to/script.groovy" ... Execute a given Groovy script. Parameters passed on the command-line when starting a script will serve as default parameters for function calls within the script.

Script Repository

Find scripts for common tasks here. You can just use these scripts straight away or as a reference for building your own more advanced scripts. If you wrote a really useful script please share it with us.

Example Scripts

args.eachMediaFolder{
def files = rename(folder:it)
compute(file:files.findAll{ it.video })
}
Rename media files folder by folder and compute checksums for the renamed video files.
['E:/TV Shows' as File].eachMediaFolder{ rename(folder:it, db:'TheTVDB') }
['E:/Anime' as File].eachMediaFolder{ rename(folder:it, db:'AniDB') }
['E:/Movies' as File].eachMediaFolder{ rename(folder:it, db:'TheMovieDB') }
Run rename on each media folder in each folder structure using different databases.
args.getFiles{ it.video }
    .sort{ it.name }
    .each{ println getMediaInfo(it, '{fn} [{vf} {vc} {af}]') }
Print media info for all video files in alphabetical order using the given format pattern.

Function Reference

Rename media files

File[] rename(folder | file | list | map, db, order, format, action, ...)

Rename the given files.

Variants:
rename(folder | file) ... match files with episode / movie information and then rename
rename(list) ... match files with episode information in linear order and then rename
rename(map) ... rename files according to the given Map
Parameters:
db ... series / movie database
order ... episode sort order
format ... format expression
action ... standard file operation or custom Closure
conflict ... conflict behavior
filter ... filter expression
mapper ... mapper expression
query ... force series / movie lookup
lang ... preferred language
strict ... use opportunistic matching or strict matching
output ... output folder
apply ... standard post-processing action or custom Closure
exec ... exec expression

Fetch subtitles for media files

File[] getMissingSubtitles(folder | file, lang, output, encoding, ...)

Fetch missing subtitles for the given files.

Parameters:
folder ... process media files in this folder
file ... process these media files
query ... force series / movie lookup
lang ... subtitle language
output ... force subtitle output format (e.g. srt)
encoding ... force output character encoding (e.g. UTF-8)
format ... subtitle file naming format (e.g. Match Video)
strict ... use lookup-by-hash or search-by-name

File verification

boolean check(folder | file)

Verify file integrity based on the given verification file.

Parameters:
folder ... check all the verification files in this folder
file ... check these verification files

File compute(folder | file, output, format, encoding)

Compute checksums and hashes for the given files and write them to a verification file.

Parameters:
folder ... compute checksums for all the files in this folder
file ... compute checksums for these files
output ... output file
format ... output format (e.g. SFV)
encoding ... force output character encoding (e.g. UTF-8)

Utilities

File[] extract(folder | file, output)

Extract the given archives.

Parameters:
folder ... extract all the archives in this folder
file ... extract this archive file
output ... output folder

String[] getMediaInfo(folder | file, filter, format, apply, exec)

Print media information.

Parameters:
folder ... process media files in this folder
file ... process these media files
filter ... file filter expression
format ... output format expression
apply ... standard post-processing action or custom Closure
exec ... exec expression

String getMediaInfo(file, format)

Apply custom format on the given media file and return the result.

Positional Parameters:
file ... input media file
format ... output format expression

ScriptShellMethods defines additional helper functions. Please refer to the Script Repository for example code.

Need help getting started? Join the Forum or Discord.