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..693b9563d5d11 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -2230,6 +2230,13 @@ 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. + + Note that this property cannot be used directly, a sub-property is required. + ``pid`` Process-id of mpv. @@ -3643,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. 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},