summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorDavid Vaughan <david@davidv.xyz>2024-02-03 16:01:06 -0800
committerDudemanguy <random342@airmail.cc>2024-02-26 02:03:21 +0000
commit432256e5d2ccee8806023f03aea076f46d9cc9ea (patch)
treec5ea1913c6ee6d175e5f6c9bba2e16e295622646 /player
parent9e162d26046005ca0f58f22a057e1d8393900d50 (diff)
downloadmpv-432256e5d2ccee8806023f03aea076f46d9cc9ea.tar.bz2
mpv-432256e5d2ccee8806023f03aea076f46d9cc9ea.tar.xz
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.
Diffstat (limited to 'player')
-rw-r--r--player/command.c20
1 files changed, 15 insertions, 5 deletions
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,