Skip to content

Commit 7c71d9a

Browse files
committed
player/command: refactor loadfile and loadlist commands to use flags
We should have done this ages ago. These commands essentially consist of a combination of a load action and whether or not playback should be started. The old `-play` aliases are kept for backwards compatibility.
1 parent 74b47cf commit 7c71d9a

File tree

4 files changed

+83
-53
lines changed

4 files changed

+83
-53
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
the `loadfile` and `loadlist` commands can now take multiple flags (i.e. `append+play`)

DOCS/man/input.rst

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -553,29 +553,44 @@ Playlist Manipulation
553553
Stop playback of the current file, and play the new file immediately.
554554
<append>
555555
Append the file to the playlist.
556+
<insert-next>
557+
Insert the file into the playlist, directly after the current entry.
558+
<insert-at>
559+
Insert the file into the playlist, at the index given in the third
560+
argument.
561+
<play>
562+
If nothing is currently playing, start playback. (Always starts with the
563+
added file, even if the playlist was not empty before running this
564+
command).
565+
566+
Multiple flags can be combined, e.g.: ``append+play``.
567+
568+
By default, ``append``, ``insert-next``, and ``insert-at`` will not
569+
immediately start playback even if the playlist was previously empty. Adding
570+
the ``play`` flag to them forces playback to start.
571+
572+
The following values are considered deprecated and were the old way
573+
(before mpv 0.41) of forcing playback to start before the ``play`` flag was
574+
added.
575+
556576
<append-play>
557577
Append the file, and if nothing is currently playing, start playback.
558578
(Always starts with the added file, even if the playlist was not empty
559579
before running this command.)
560-
<insert-next>
561-
Insert the file into the playlist, directly after the current entry.
562580
<insert-next-play>
563581
Insert the file next, and if nothing is currently playing, start playback.
564582
(Always starts with the added file, even if the playlist was not empty
565583
before running this command.)
566-
<insert-at>
567-
Insert the file into the playlist, at the index given in the third
568-
argument.
569584
<insert-at-play>
570585
Insert the file at the index given in the third argument, and if nothing
571586
is currently playing, start playback. (Always starts with the added
572587
file, even if the playlist was not empty before running this command.)
573588

574-
The third argument is an insertion index, used only by the ``insert-at`` and
575-
``insert-at-play`` actions. When used with those actions, the new item will
576-
be inserted at the index position in the playlist, or appended to the end if
577-
index is less than 0 or greater than the size of the playlist. This argument
578-
will be ignored for all other actions. This argument is added in mpv 0.38.0.
589+
The third argument is an insertion index, used only by the ``insert-at``
590+
action. When used with those actions, the new item will be inserted at the
591+
index position in the playlist, or appended to the end if index is less than
592+
0 or greater than the size of the playlist. This argument will be ignored for
593+
all other actions. This argument was added in mpv 0.38.0.
579594

580595
The fourth argument is a list of options and values which should be set
581596
while the file is playing. It is of the form ``opt1=value1,opt2=value2,..``.
@@ -601,30 +616,45 @@ Playlist Manipulation
601616
Stop playback and replace the internal playlist with the new one.
602617
<append>
603618
Append the new playlist at the end of the current internal playlist.
619+
<insert-next>
620+
Insert the new playlist into the current internal playlist, directly
621+
after the current entry.
622+
<insert-at>
623+
Insert the new playlist at the index given in the third argument.
624+
<play>
625+
If nothing is currently playing, start playback. (Always starts with the
626+
added playlist, even if the internal playlist was not empty before running
627+
this command).
628+
629+
Multiple flags can be combined, e.g.: ``append+play``.
630+
631+
By default, ``append``, ``insert-next``, and ``insert-at`` will not
632+
immediately start playback even if the playlist was previously empty. Adding
633+
the ``play`` flag to them forces playback to start.
634+
635+
The following values are considered deprecated and were the old way
636+
(before mpv 0.41) of forcing playback to start before the ``play`` flag was
637+
added.
638+
604639
<append-play>
605640
Append the new playlist, and if nothing is currently playing, start
606641
playback. (Always starts with the new playlist, even if the internal
607642
playlist was not empty before running this command.)
608-
<insert-next>
609-
Insert the new playlist into the current internal playlist, directly
610-
after the current entry.
611643
<insert-next-play>
612644
Insert the new playlist, and if nothing is currently playing, start
613645
playback. (Always starts with the new playlist, even if the internal
614646
playlist was not empty before running this command.)
615-
<insert-at>
616-
Insert the new playlist at the index given in the third argument.
617647
<insert-at-play>
618648
Insert the new playlist at the index given in the third argument, and if
619649
nothing is currently playing, start playback. (Always starts with the
620650
new playlist, even if the internal playlist was not empty before running
621651
this command.)
622652

623-
The third argument is an insertion index, used only by the ``insert-at`` and
624-
``insert-at-play`` actions. When used with those actions, the new playlist
625-
will be inserted at the index position in the internal playlist, or appended
626-
to the end if index is less than 0 or greater than the size of the internal
627-
playlist. This argument will be ignored for all other actions.
653+
The third argument is an insertion index, used only by the ``insert-at`` action.
654+
When used with those actions, the new playlist will be inserted at the index
655+
position in the internal playlist, or appended to the end if index is less
656+
than 0 or greater than the size of the internal playlist. This argument will be
657+
ignored for all other actions. This argument was added in mpv 0.38.0.
628658

629659
``playlist-clear``
630660
Clear the playlist, except the currently played file.

player/command.c

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6069,21 +6069,17 @@ static void cmd_escape_ass(void *p)
60696069

60706070
static struct load_action get_load_action(struct MPContext *mpctx, int action_flag)
60716071
{
6072-
switch (action_flag) {
6073-
case 0: // replace
6074-
return (struct load_action){LOAD_TYPE_REPLACE, .play = true};
6075-
case 1: // append
6076-
return (struct load_action){LOAD_TYPE_APPEND, .play = false};
6077-
case 2: // append-play
6078-
return (struct load_action){LOAD_TYPE_APPEND, .play = true};
6079-
case 3: // insert-next
6080-
return (struct load_action){LOAD_TYPE_INSERT_NEXT, .play = false};
6081-
case 4: // insert-next-play
6082-
return (struct load_action){LOAD_TYPE_INSERT_NEXT, .play = true};
6083-
case 5: // insert-at
6084-
return (struct load_action){LOAD_TYPE_INSERT_AT, .play = false};
6085-
case 6: // insert-at-play
6086-
return (struct load_action){LOAD_TYPE_INSERT_AT, .play = true};
6072+
int type = action_flag & 3;
6073+
bool play = (action_flag >> 3) & 1;
6074+
switch (type) {
6075+
case 0:
6076+
return (struct load_action){LOAD_TYPE_REPLACE, .play = play};
6077+
case 1:
6078+
return (struct load_action){LOAD_TYPE_APPEND, .play = play};
6079+
case 2:
6080+
return (struct load_action){LOAD_TYPE_INSERT_NEXT, .play = play};
6081+
case 3:
6082+
return (struct load_action){LOAD_TYPE_INSERT_AT, .play = play};
60876083
default: // default: replace
60886084
return (struct load_action){LOAD_TYPE_REPLACE, .play = true};
60896085
}
@@ -7389,14 +7385,16 @@ const struct mp_cmd_def mp_cmds[] = {
73897385
{ "loadfile", cmd_loadfile,
73907386
{
73917387
{"url", OPT_STRING(v.s)},
7392-
{"flags", OPT_CHOICE(v.i,
7393-
{"replace", 0},
7394-
{"append", 1},
7395-
{"append-play", 2},
7396-
{"insert-next", 3},
7397-
{"insert-next-play", 4},
7398-
{"insert-at", 5},
7399-
{"insert-at-play", 6}),
7388+
{"flags", OPT_FLAGS(v.i,
7389+
{"replace", 4|0},
7390+
{"append", 4|1},
7391+
{"insert-next", 4|2},
7392+
{"insert-at", 4|3},
7393+
{"play", 32|8},
7394+
// backwards compatibility
7395+
{"append-play", (4|1) + (16|8)},
7396+
{"insert-next-play", (4|2) + (16|8)},
7397+
{"insert-at-play", (4|3) + (16|8)}),
74007398
.flags = MP_CMD_OPT_ARG},
74017399
{"index", OPT_INT(v.i), OPTDEF_INT(-1)},
74027400
{"options", OPT_KEYVALUELIST(v.str_list), .flags = MP_CMD_OPT_ARG},
@@ -7405,14 +7403,16 @@ const struct mp_cmd_def mp_cmds[] = {
74057403
{ "loadlist", cmd_loadlist,
74067404
{
74077405
{"url", OPT_STRING(v.s)},
7408-
{"flags", OPT_CHOICE(v.i,
7409-
{"replace", 0},
7410-
{"append", 1},
7411-
{"append-play", 2},
7412-
{"insert-next", 3},
7413-
{"insert-next-play", 4},
7414-
{"insert-at", 5},
7415-
{"insert-at-play", 6}),
7406+
{"flags", OPT_FLAGS(v.i,
7407+
{"replace", 4|0},
7408+
{"append", 4|1},
7409+
{"insert-next", 4|2},
7410+
{"insert-at", 4|3},
7411+
{"play", 32|8},
7412+
// backwards compatibility
7413+
{"append-play", (4|1) + (16|8)},
7414+
{"insert-next-play", (4|2) + (16|8)},
7415+
{"insert-at-play", (4|3) + (16|8)}),
74167416
.flags = MP_CMD_OPT_ARG},
74177417
{"index", OPT_INT(v.i), OPTDEF_INT(-1)},
74187418
},

player/lua/commands.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,7 @@ local function command_flags_at_2nd_argument_list(command)
335335
local flags = {
336336
["apply-profile"] = {"apply", "restore"},
337337
["frame-step"] = {"play", "seek", "mute"},
338-
["loadfile"] = {"replace", "append", "append-play", "insert-next",
339-
"insert-next-play", "insert-at", "insert-at-play"},
338+
["loadfile"] = {"replace", "append", "insert-next", "insert-at", "play"},
340339
["screenshot-to-file"] = {"subtitles", "video", "window", "each-frame"},
341340
["screenshot-raw"] = {"bgr0", "bgra", "rgba", "rgba64"},
342341
["seek"] = {"relative", "absolute", "absolute-percent",

0 commit comments

Comments
 (0)