From 432256e5d2ccee8806023f03aea076f46d9cc9ea Mon Sep 17 00:00:00 2001 From: David Vaughan Date: Sat, 3 Feb 2024 16:01:06 -0800 Subject: player: add loadlist insert-next commands Analogous changes to the previous commit ("add loadfile insert-next commands"), but for the `loadlist` command. This allows us to insert a new playlist next in the current playlist, rather than just appending it to the end. --- player/command.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'player') diff --git a/player/command.c b/player/command.c index 3e040bc256..cbb5d787fe 100644 --- a/player/command.c +++ b/player/command.c @@ -5567,24 +5567,32 @@ static void cmd_loadlist(void *p) struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx; char *filename = cmd->args[0].v.s; - int append = cmd->args[1].v.i; + int flag = cmd->args[1].v.i; + + bool replace = (flag == 0); + bool insert_next = (flag == 3 || flag == 4); + bool play = (flag == 2 || flag == 4); struct playlist *pl = playlist_parse_file(filename, cmd->abort->cancel, mpctx->global); if (pl) { prepare_playlist(mpctx, pl); struct playlist_entry *new = pl->current; - if (!append) + if (replace) playlist_clear(mpctx->playlist); struct playlist_entry *first = playlist_entry_from_index(pl, 0); int num_entries = pl->num_entries; - playlist_append_entries(mpctx->playlist, pl); + if (insert_next) { + playlist_transfer_entries(mpctx->playlist, pl); + } else { + playlist_append_entries(mpctx->playlist, pl); + } talloc_free(pl); if (!new) new = playlist_get_first(mpctx->playlist); - if ((!append || (append == 2 && !mpctx->playlist->current)) && new) + if ((replace || (play && !mpctx->playlist->current)) && new) mp_set_playlist_entry(mpctx, new); struct mpv_node *res = &cmd->result; @@ -6703,7 +6711,9 @@ const struct mp_cmd_def mp_cmds[] = { {"flags", OPT_CHOICE(v.i, {"replace", 0}, {"append", 1}, - {"append-play", 2}), + {"append-play", 2}, + {"insert-next", 3}, + {"insert-next-play", 4}), .flags = MP_CMD_OPT_ARG}, }, .spawn_thread = true, -- cgit v1.2.3