Environment variables in exec

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
devster
Posts: 417
Joined: 06 Jun 2017, 22:56

Environment variables in exec

Post 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.
I only work in black and sometimes very, very dark grey. (Batman)
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Environment variables in exec

Post 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
:idea: Please read the FAQ and How to Request Help.
devster
Posts: 417
Joined: 06 Jun 2017, 22:56

Re: Environment variables in exec

Post 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).
I only work in black and sometimes very, very dark grey. (Batman)
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Environment variables in exec

Post 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.
:idea: Please read the FAQ and How to Request Help.
devster
Posts: 417
Joined: 06 Jun 2017, 22:56

Re: Environment variables in exec

Post by devster »

I didn't realize some were dynamic. Case closed.
Will try to stitch something together with a script.
I only work in black and sometimes very, very dark grey. (Batman)
Post Reply