Page 1 of 1

Environment variables in exec

Posted: 19 Apr 2018, 08:08
by devster
Unfortunately I was unable to discern it from the code, but is it possible to pass variables to exec scripts via the Environment instead of arguments?
Main reason is that it seems substantially less error-prone to use them, for example in bash, compared to positional arguments.

Code: Select all

$ filebot -exec "SERIES_ID={id} myscript.sh ...
and

Code: Select all

#!/bin/bash -u

seriesid="x${SERIES_ID:-notset}"

if [ $seriesid == "xnotset" ]; then exit 1; fi
or something like that.

Re: Environment variables in exec

Posted: 19 Apr 2018, 08:32
by rednoah
Nope, it's designed to kinda work like find -exec.


You can have your own glue logic script that does that though:

Code: Select all

filebot ... -exec env.sh {id}
env.sh

Code: Select all

#!/bin/sh
export SERIES_ID="$1"

myscript.sh

Re: Environment variables in exec

Posted: 19 Apr 2018, 09:15
by devster
Thank you.

I would propose this as a possible enhancement (definitely lowest of priorities), I believe it to be much easier in both bash and many other languages for exec scripts.
Thinking on Python for example:

Code: Select all

import os

series_id = os.getenv('id') # defaults to None if empty
instead of using argparse.
The idea comes from Sonarr actually, which allows the execution of custom post-processing scripts by passing several variables as environment variables (here for reference).
Variables (expression bindings) in FileBot are a huge amount, but then again there's apparently no limit to their numbers in either unix or Windows (there is a limit to env variable length in windows though).

Re: Environment variables in exec

Posted: 19 Apr 2018, 11:49
by rednoah
Sorry, not a good idea, since format expressions can do absolutely anything. There's dozens of top level bindings, and lots of dynamic bindings such as {video} that give you dynamic access to even more MediaInfo properties, some dynamic properties might even require network access such as {director} where extended Movie information is requested on demand when the binding is used.

The current system is straight forward and extremely powerful. Using environment variables would be neither. You're welcome to come up with a default glue logic script though that passes all the most common info fields and then sets up the environment appropriately for your custom call. Users that prefer your approach could then just use it.

Re: Environment variables in exec

Posted: 19 Apr 2018, 14:38
by devster
I didn't realize some were dynamic. Case closed.
Will try to stitch something together with a script.