mirror of
https://github.com/mpv-player/mpv
synced 2025-02-19 14:26:57 +00:00
input: do property expansion for all input command string arguments
Also add a "raw" prefix for commands, which prevents property expansion. The idea is that if the commands are generated by a program, it doesn't have to know whether the command expands properties or not.
This commit is contained in:
parent
3e6ec6dfa5
commit
58cc0f637f
@ -289,10 +289,14 @@ osd-msg
|
|||||||
value as text.
|
value as text.
|
||||||
osd-msg-bar
|
osd-msg-bar
|
||||||
Combine osd-bar and osd-msg.
|
Combine osd-bar and osd-msg.
|
||||||
|
raw
|
||||||
|
Don't expand properties in string arguments. (Like ``"${property-name}"``.)
|
||||||
|
expand-properties (default)
|
||||||
|
All string arguments are expanded like in ``--playing-msg``.
|
||||||
|
|
||||||
|
|
||||||
|
All of the osd prefixes are still overridden by the global ``--osd-level``
|
||||||
All of these are still overridden by the global ``--osd-level`` settings.
|
settings.
|
||||||
|
|
||||||
Undocumented prefixes: pausing, pausing_keep, pausing_toggle,
|
Undocumented prefixes: pausing, pausing_keep, pausing_toggle,
|
||||||
pausing_keep_force. (Should these be made official?)
|
pausing_keep_force. (Should these be made official?)
|
||||||
|
@ -1821,6 +1821,19 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
|
|||||||
bool msg_osd = auto_osd || (cmd->on_osd & MP_ON_OSD_MSG);
|
bool msg_osd = auto_osd || (cmd->on_osd & MP_ON_OSD_MSG);
|
||||||
bool bar_osd = auto_osd || (cmd->on_osd & MP_ON_OSD_BAR);
|
bool bar_osd = auto_osd || (cmd->on_osd & MP_ON_OSD_BAR);
|
||||||
int osdl = msg_osd ? 1 : OSD_LEVEL_INVISIBLE;
|
int osdl = msg_osd ? 1 : OSD_LEVEL_INVISIBLE;
|
||||||
|
|
||||||
|
if (!cmd->raw_args) {
|
||||||
|
for (int n = 0; n < cmd->nargs; n++) {
|
||||||
|
if (cmd->args[n].type.type == CONF_TYPE_STRING) {
|
||||||
|
cmd->args[n].v.s =
|
||||||
|
mp_property_expand_string(mpctx, cmd->args[n].v.s);
|
||||||
|
if (!cmd->args[n].v.s)
|
||||||
|
return;
|
||||||
|
talloc_steal(cmd, cmd->args[n].v.s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (cmd->id) {
|
switch (cmd->id) {
|
||||||
case MP_CMD_SEEK: {
|
case MP_CMD_SEEK: {
|
||||||
double v = cmd->args[0].v.d;
|
double v = cmd->args[0].v.d;
|
||||||
@ -1985,23 +1998,15 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
case MP_CMD_PRINT_TEXT: {
|
case MP_CMD_PRINT_TEXT: {
|
||||||
char *txt = mp_property_expand_string(mpctx, cmd->args[0].v.s);
|
mp_msg(MSGT_GLOBAL, MSGL_INFO, "%s\n", cmd->args[0].v.s);
|
||||||
if (txt) {
|
|
||||||
mp_msg(MSGT_GLOBAL, MSGL_INFO, "%s\n", txt);
|
|
||||||
talloc_free(txt);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case MP_CMD_SHOW_TEXT: {
|
case MP_CMD_SHOW_TEXT: {
|
||||||
char *txt = mp_property_expand_string(mpctx, cmd->args[0].v.s);
|
|
||||||
if (txt) {
|
|
||||||
// if no argument supplied use default osd_duration, else <arg> ms.
|
// if no argument supplied use default osd_duration, else <arg> ms.
|
||||||
set_osd_msg(mpctx, OSD_MSG_TEXT, cmd->args[2].v.i,
|
set_osd_msg(mpctx, OSD_MSG_TEXT, cmd->args[2].v.i,
|
||||||
(cmd->args[1].v.i < 0 ? osd_duration : cmd->args[1].v.i),
|
(cmd->args[1].v.i < 0 ? osd_duration : cmd->args[1].v.i),
|
||||||
"%s", txt);
|
"%s", cmd->args[0].v.s);
|
||||||
talloc_free(txt);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2284,11 +2289,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
|
|||||||
case MP_CMD_RUN:
|
case MP_CMD_RUN:
|
||||||
#ifndef __MINGW32__
|
#ifndef __MINGW32__
|
||||||
if (!fork()) {
|
if (!fork()) {
|
||||||
char *s = mp_property_expand_string(mpctx, cmd->args[0].v.s);
|
execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
|
||||||
if (s) {
|
|
||||||
execl("/bin/sh", "sh", "-c", s, NULL);
|
|
||||||
talloc_free(s);
|
|
||||||
}
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -790,6 +790,7 @@ mp_cmd_t *mp_input_parse_cmd(bstr str, const char *loc)
|
|||||||
{
|
{
|
||||||
int pausing = 0;
|
int pausing = 0;
|
||||||
int on_osd = MP_ON_OSD_AUTO;
|
int on_osd = MP_ON_OSD_AUTO;
|
||||||
|
bool raw_args = false;
|
||||||
struct mp_cmd *cmd = NULL;
|
struct mp_cmd *cmd = NULL;
|
||||||
bstr start = str;
|
bstr start = str;
|
||||||
void *tmp = talloc_new(NULL);
|
void *tmp = talloc_new(NULL);
|
||||||
@ -829,6 +830,10 @@ mp_cmd_t *mp_input_parse_cmd(bstr str, const char *loc)
|
|||||||
on_osd = MP_ON_OSD_MSG | MP_ON_OSD_BAR;
|
on_osd = MP_ON_OSD_MSG | MP_ON_OSD_BAR;
|
||||||
} else if (eat_token(&str, "osd-auto")) {
|
} else if (eat_token(&str, "osd-auto")) {
|
||||||
// default
|
// default
|
||||||
|
} else if (eat_token(&str, "raw")) {
|
||||||
|
raw_args = true;
|
||||||
|
} else if (eat_token(&str, "expand-properties")) {
|
||||||
|
// default
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -851,6 +856,7 @@ mp_cmd_t *mp_input_parse_cmd(bstr str, const char *loc)
|
|||||||
*cmd = mp_cmds[cmd_idx];
|
*cmd = mp_cmds[cmd_idx];
|
||||||
cmd->pausing = pausing;
|
cmd->pausing = pausing;
|
||||||
cmd->on_osd = on_osd;
|
cmd->on_osd = on_osd;
|
||||||
|
cmd->raw_args = raw_args;
|
||||||
|
|
||||||
for (int i = 0; i < MP_CMD_MAX_ARGS; i++) {
|
for (int i = 0; i < MP_CMD_MAX_ARGS; i++) {
|
||||||
struct mp_cmd_arg *cmdarg = &cmd->args[i];
|
struct mp_cmd_arg *cmdarg = &cmd->args[i];
|
||||||
|
@ -137,6 +137,7 @@ typedef struct mp_cmd {
|
|||||||
struct mp_cmd_arg args[MP_CMD_MAX_ARGS];
|
struct mp_cmd_arg args[MP_CMD_MAX_ARGS];
|
||||||
int nargs;
|
int nargs;
|
||||||
int pausing;
|
int pausing;
|
||||||
|
bool raw_args;
|
||||||
enum mp_on_osd on_osd;
|
enum mp_on_osd on_osd;
|
||||||
bstr original;
|
bstr original;
|
||||||
struct mp_cmd *queue_next;
|
struct mp_cmd *queue_next;
|
||||||
|
@ -206,7 +206,7 @@ static pthread_t playback_thread_id;
|
|||||||
[self.files enumerateObjectsUsingBlock:^(id obj, NSUInteger i, BOOL *_){
|
[self.files enumerateObjectsUsingBlock:^(id obj, NSUInteger i, BOOL *_){
|
||||||
const char *file = [escape_loadfile_name(obj) UTF8String];
|
const char *file = [escape_loadfile_name(obj) UTF8String];
|
||||||
const char *append = (i == 0) ? "" : " append";
|
const char *append = (i == 0) ? "" : " append";
|
||||||
char *cmd = talloc_asprintf(ctx, "loadfile \"%s\"%s", file, append);
|
char *cmd = talloc_asprintf(ctx, "raw loadfile \"%s\"%s", file, append);
|
||||||
mp_cmd_t *cmdt = mp_input_parse_cmd(bstr0(cmd), "");
|
mp_cmd_t *cmdt = mp_input_parse_cmd(bstr0(cmd), "");
|
||||||
mp_input_queue_cmd(self.inputContext, cmdt);
|
mp_input_queue_cmd(self.inputContext, cmdt);
|
||||||
}];
|
}];
|
||||||
|
Loading…
Reference in New Issue
Block a user