Skip to content

Commit 6bdb978

Browse files
committed
player/command: add env property
mainly so that env vars can be accessed from within input.conf.
1 parent afef912 commit 6bdb978

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

DOCS/man/input.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2230,6 +2230,11 @@ Property list
22302230
.. note:: This is only an estimate. (It's computed from two unreliable
22312231
quantities: fps and possibly rounded timestamps.)
22322232

2233+
``env/...``
2234+
Read-only property that can be used for retrieving environment variables.
2235+
The variable to retrieve should be set as the sub-property. E.g
2236+
``${env/HOME}`` will return ``$HOME`` if set.
2237+
22332238
``pid``
22342239
Process-id of mpv.
22352240

player/command.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,17 @@ static int mp_property_filename(void *ctx, struct m_property *prop,
544544
return r;
545545
}
546546

547+
static int mp_property_env(void *ctx, struct m_property *prop,
548+
int action, void *arg)
549+
{
550+
if (action == M_PROPERTY_KEY_ACTION) {
551+
struct m_property_action_arg *ka = arg;
552+
char *val = getenv(ka->key);
553+
return m_property_strdup_ro(ka->action, ka->arg, val);
554+
}
555+
return M_PROPERTY_NOT_IMPLEMENTED;
556+
}
557+
547558
static int mp_property_stream_open_filename(void *ctx, struct m_property *prop,
548559
int action, void *arg)
549560
{
@@ -4387,6 +4398,7 @@ static const struct m_property mp_properties_base[] = {
43874398
{"video-speed-correction", mp_property_av_speed_correction, .priv = "v"},
43884399
{"display-sync-active", mp_property_display_sync_active},
43894400
{"filename", mp_property_filename},
4401+
{"env", mp_property_env},
43904402
{"stream-open-filename", mp_property_stream_open_filename},
43914403
{"file-size", mp_property_file_size},
43924404
{"path", mp_property_path},

0 commit comments

Comments
 (0)