From 26dc1f9489539efba89127acab2c33782250f343 Mon Sep 17 00:00:00 2001 From: NRK Date: Fri, 27 Oct 2023 19:23:49 +0600 Subject: [PATCH 1/2] player/command: add env property mainly so that env vars can be accessed from within input.conf. --- DOCS/interface-changes/env-property.txt | 1 + DOCS/man/input.rst | 5 +++++ player/command.c | 12 ++++++++++++ 3 files changed, 18 insertions(+) create mode 100644 DOCS/interface-changes/env-property.txt diff --git a/DOCS/interface-changes/env-property.txt b/DOCS/interface-changes/env-property.txt new file mode 100644 index 0000000000000..1db4fef6ddb14 --- /dev/null +++ b/DOCS/interface-changes/env-property.txt @@ -0,0 +1 @@ +add env property that can be used to retrieve environment variables diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index 7eea15fbcba22..48deb6baa454d 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -2230,6 +2230,11 @@ Property list .. note:: This is only an estimate. (It's computed from two unreliable quantities: fps and possibly rounded timestamps.) +``env/...`` + Read-only property that can be used for retrieving environment variables. + The variable to retrieve should be set as the sub-property. E.g + ``${env/HOME}`` will return ``$HOME`` if set. + ``pid`` Process-id of mpv. diff --git a/player/command.c b/player/command.c index eaf392e6e710d..c361e513eda01 100644 --- a/player/command.c +++ b/player/command.c @@ -544,6 +544,17 @@ static int mp_property_filename(void *ctx, struct m_property *prop, return r; } +static int mp_property_env(void *ctx, struct m_property *prop, + int action, void *arg) +{ + if (action == M_PROPERTY_KEY_ACTION) { + struct m_property_action_arg *ka = arg; + char *val = getenv(ka->key); + return m_property_strdup_ro(ka->action, ka->arg, val); + } + return M_PROPERTY_NOT_IMPLEMENTED; +} + static int mp_property_stream_open_filename(void *ctx, struct m_property *prop, int action, void *arg) { @@ -4387,6 +4398,7 @@ static const struct m_property mp_properties_base[] = { {"video-speed-correction", mp_property_av_speed_correction, .priv = "v"}, {"display-sync-active", mp_property_display_sync_active}, {"filename", mp_property_filename}, + {"env", mp_property_env}, {"stream-open-filename", mp_property_stream_open_filename}, {"file-size", mp_property_file_size}, {"path", mp_property_path}, From 64e8fedb95fdcad24bc437f63ec4ff7b829df833 Mon Sep 17 00:00:00 2001 From: NRK Date: Sun, 15 Mar 2026 14:22:48 +0000 Subject: [PATCH 2/2] DOCS/man/input: document dummy properties these properties cannot be used directly and require a sub-property. document this explicitly. --- DOCS/man/input.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index 48deb6baa454d..693b9563d5d11 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -2235,6 +2235,8 @@ Property list The variable to retrieve should be set as the sub-property. E.g ``${env/HOME}`` will return ``$HOME`` if set. + Note that this property cannot be used directly, a sub-property is required. + ``pid`` Process-id of mpv. @@ -3648,6 +3650,8 @@ Property list If tracks of the requested type are selected via ``--lavfi-complex``, the first one is returned. + Note that this property cannot be used directly, a sub-property is required. + ``chapter-list`` (RW) List of chapters, current entry marked.