From 7e27663b7bdd92125dd221bf3dbb8f760681c9d7 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 23 Oct 2014 13:11:41 +0200 Subject: command: add a "cached" mode to sub_add This avoids reloading a subtitle if it was already added. In all cases, the subtitle is selected. --- player/command.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'player') diff --git a/player/command.c b/player/command.c index 77645d3755..8887338a6e 100644 --- a/player/command.c +++ b/player/command.c @@ -3682,6 +3682,18 @@ static int mp_property_multiply(char *property, double f, struct MPContext *mpct return r; } +static struct track *find_track_with_url(struct MPContext *mpctx, int type, + const char *url) +{ + for (int n = 0; n < mpctx->num_tracks; n++) { + struct track *track = mpctx->tracks[n]; + if (track && track->type == type && track->is_external && + strcmp(track->external_filename, url) == 0) + return track; + } + return NULL; +} + // Whether this property should react to key events generated by auto-repeat. static bool check_property_autorepeat(char *property, struct MPContext *mpctx) { @@ -4090,10 +4102,19 @@ int run_command(MPContext *mpctx, mp_cmd_t *cmd) case MP_CMD_SUB_ADD: { if (!mpctx->playing) return -1; + if (cmd->args[1].v.i == 2) { + struct track *sub = find_track_with_url(mpctx, STREAM_SUB, + cmd->args[0].v.s); + if (sub) { + mp_switch_track(mpctx, sub->type, sub); + mp_mark_user_track_selection(mpctx, 0, sub->type); + return 0; + } + } struct track *sub = mp_add_subtitles(mpctx, cmd->args[0].v.s); if (!sub) return -1; - if (cmd->args[1].v.i == 0) { + if (cmd->args[1].v.i != 1) { mp_switch_track(mpctx, sub->type, sub); mp_mark_user_track_selection(mpctx, 0, sub->type); } -- cgit v1.2.3