Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DOCS/interface-changes/env-property.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add `env` property that can be used to retrieve environment variables
6 changes: 6 additions & 0 deletions DOCS/man/input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2230,6 +2230,10 @@ Property list
.. note:: This is only an estimate. (It's computed from two unreliable
quantities: fps and possibly rounded timestamps.)

``env``
Read-only table of all the environment variables. A specific variable can be
accessed as a sub-property, e.g. ``${env/HOME}`` returns ``$HOME`` if set.

``pid``
Process-id of mpv.

Expand Down Expand Up @@ -3643,6 +3647,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.

Expand Down
33 changes: 33 additions & 0 deletions player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,38 @@ 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)
{
switch (action) {
case M_PROPERTY_GET_TYPE:
*(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_NODE};
return M_PROPERTY_OK;
case M_PROPERTY_GET:
case M_PROPERTY_GET_NODE: {
struct mpv_node node;
node_init(&node, MPV_FORMAT_NODE_MAP, NULL);
for (char **env = environ; env && *env; env++) {
char *sep = strchr(*env, '=');
if (!sep)
continue;
bstr key = { .start = *env, .len = sep - *env };
struct mpv_node *np = node_map_badd(&node, key, MPV_FORMAT_NONE);
np->format = MPV_FORMAT_STRING;
np->u.string = talloc_strdup(node.u.list, sep + 1);
}
*(struct mpv_node *)arg = node;
return M_PROPERTY_OK;
}
case 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)
{
Expand Down Expand Up @@ -4387,6 +4419,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},
Expand Down
Loading