From afbd657bb8e955accf8022c96e867973c1fb0a41 Mon Sep 17 00:00:00 2001 From: "Avi Halachmi (:avih)" Date: Sun, 26 Mar 2017 20:29:10 +0300 Subject: command: add expand-text command to property-expand a string --- DOCS/man/input.rst | 5 +++++ input/cmd_list.c | 1 + input/cmd_list.h | 1 + player/command.c | 10 ++++++++++ 4 files changed, 17 insertions(+) diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index 984b8db7d6..7dded1cca1 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -357,6 +357,11 @@ List of Input Commands The minimum OSD level to show the text at (see ``--osd-level``). +``expand-text ""`` + Property-expand the argument and return the expanded string. This can be + used only through the client API or from a script using + ``mp.command_native``. (see `Property Expansion`_). + ``show-progress`` Show the progress bar, the elapsed time and the total duration of the file on the OSD. diff --git a/input/cmd_list.c b/input/cmd_list.c index 53cc375b3a..33cf40f233 100644 --- a/input/cmd_list.c +++ b/input/cmd_list.c @@ -97,6 +97,7 @@ const struct mp_cmd_def mp_cmds[] = { { MP_CMD_PRINT_TEXT, "print-text", { ARG_STRING }, .allow_auto_repeat = true }, { MP_CMD_SHOW_TEXT, "show-text", { ARG_STRING, OARG_INT(-1), OARG_INT(0) }, .allow_auto_repeat = true}, + { MP_CMD_EXPAND_TEXT, "expand-text", { ARG_STRING } }, { MP_CMD_SHOW_PROGRESS, "show-progress", .allow_auto_repeat = true}, { MP_CMD_SUB_ADD, "sub-add", { ARG_STRING, OARG_CHOICE(0, ({"select", 0}, {"auto", 1}, {"cached", 2})), diff --git a/input/cmd_list.h b/input/cmd_list.h index 1c2330b589..404df462f4 100644 --- a/input/cmd_list.h +++ b/input/cmd_list.h @@ -67,6 +67,7 @@ enum mp_command_type { MP_CMD_SET, MP_CMD_PRINT_TEXT, MP_CMD_SHOW_TEXT, + MP_CMD_EXPAND_TEXT, MP_CMD_SHOW_PROGRESS, MP_CMD_ADD, MP_CMD_CYCLE, diff --git a/player/command.c b/player/command.c index 28d331c97e..1732b7b3cd 100644 --- a/player/command.c +++ b/player/command.c @@ -5136,6 +5136,16 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re break; } + case MP_CMD_EXPAND_TEXT: { + if (!res) + return -1; + *res = (mpv_node){ + .format = MPV_FORMAT_STRING, + .u.string = mp_property_expand_string(mpctx, cmd->args[0].v.s) + }; + break; + } + case MP_CMD_LOADFILE: { char *filename = cmd->args[0].v.s; int append = cmd->args[1].v.i; -- cgit v1.2.3