command: extend sub_add command

This commit is contained in:
wm4
2014-10-20 23:55:29 +02:00
parent b79f291f4b
commit 131633b4e5
3 changed files with 30 additions and 4 deletions

View File

@@ -260,10 +260,26 @@ List of Input Commands
will seek to the previous position on start. The (optional) argument is will seek to the previous position on start. The (optional) argument is
exactly as in the ``quit`` command. exactly as in the ``quit`` command.
``sub_add "<file>"`` ``sub_add "<file>" [<flags> [<title> [<lang>]]]``
Load the given subtitle file. It is selected as current subtitle after Load the given subtitle file. It is selected as current subtitle after
loading. loading.
The ``flags`` args is one of the following values:
<select>
Select the subtitle immediately.
<auto>
Don't select the subtitle. (Or in some special situations, let the
default stream selection mechanism decide.)
The ``title`` argument sets the track title in the UI.
The ``lang`` argument sets the track language, and can also influence
stream selection with ``flags`` set to ``auto``.
``sub_remove [<id>]`` ``sub_remove [<id>]``
Remove the given subtitle track. If the ``id`` argument is missing, remove Remove the given subtitle track. If the ``id`` argument is missing, remove
the current track. (Works on external subtitle files only.) the current track. (Works on external subtitle files only.)

View File

@@ -89,7 +89,9 @@ const struct mp_cmd_def mp_cmds[] = {
{ MP_CMD_SHOW_TEXT, "show_text", { ARG_STRING, OARG_INT(-1), OARG_INT(0) }, { MP_CMD_SHOW_TEXT, "show_text", { ARG_STRING, OARG_INT(-1), OARG_INT(0) },
.allow_auto_repeat = true}, .allow_auto_repeat = true},
{ MP_CMD_SHOW_PROGRESS, "show_progress", .allow_auto_repeat = true}, { MP_CMD_SHOW_PROGRESS, "show_progress", .allow_auto_repeat = true},
{ MP_CMD_SUB_ADD, "sub_add", { ARG_STRING } }, { MP_CMD_SUB_ADD, "sub_add", { ARG_STRING,
OARG_CHOICE(0, ({"select", 0}, {"auto", 1})),
ARG_STRING, ARG_STRING } },
{ MP_CMD_SUB_REMOVE, "sub_remove", { OARG_INT(-1) } }, { MP_CMD_SUB_REMOVE, "sub_remove", { OARG_INT(-1) } },
{ MP_CMD_SUB_RELOAD, "sub_reload", { OARG_INT(-1) } }, { MP_CMD_SUB_RELOAD, "sub_reload", { OARG_INT(-1) } },

View File

@@ -4019,8 +4019,16 @@ int run_command(MPContext *mpctx, mp_cmd_t *cmd)
struct track *sub = mp_add_subtitles(mpctx, cmd->args[0].v.s); struct track *sub = mp_add_subtitles(mpctx, cmd->args[0].v.s);
if (!sub) if (!sub)
return -1; return -1;
mp_switch_track(mpctx, sub->type, sub); if (cmd->args[1].v.i == 0) {
mp_mark_user_track_selection(mpctx, 0, sub->type); mp_switch_track(mpctx, sub->type, sub);
mp_mark_user_track_selection(mpctx, 0, sub->type);
}
char *title = cmd->args[2].v.s;
if (title && title[0])
sub->title = talloc_strdup(sub, title);
char *lang = cmd->args[3].v.s;
if (lang && lang[0])
sub->lang = talloc_strdup(sub, lang);
break; break;
} }