summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-11-28 19:13:48 +0100
committerwm4 <wm4@nowhere>2013-11-28 19:13:48 +0100
commit0a18f3eb9a163b1cd656129dac6164d7914ecc41 (patch)
tree351b5a74c9a4885e8adc493a81451aa91c018510
parent5318a1bea1e477033cd355e19be366f0504222e9 (diff)
downloadmpv-0a18f3eb9a163b1cd656129dac6164d7914ecc41.tar.bz2
mpv-0a18f3eb9a163b1cd656129dac6164d7914ecc41.tar.xz
command: allow "current" as argument to playlist_remove command
Feature request from github issue #376.
-rw-r--r--DOCS/man/en/input.rst6
-rw-r--r--mpvcore/input/input.c5
-rw-r--r--mpvcore/player/command.c2
3 files changed, 10 insertions, 3 deletions
diff --git a/DOCS/man/en/input.rst b/DOCS/man/en/input.rst
index 53336344af..917584428f 100644
--- a/DOCS/man/en/input.rst
+++ b/DOCS/man/en/input.rst
@@ -185,9 +185,11 @@ List of Input Commands
``playlist_clear``
Clear the playlist, except the currently played file.
-``playlist_remove <index>``
+``playlist_remove current|<index>``
Remove the playlist entry at the given index. Index values start counting
- with 0. You cannot remove the entry for the currently played file.
+ with 0. The special value ``current`` removes the current entry. Note that
+ removing the current entry also stops playback and starts playing the next
+ entry.
``playlist_move <index1> <index2>``
Move the playlist entry at index1, so that it takes the place of the
diff --git a/mpvcore/input/input.c b/mpvcore/input/input.c
index c000835d58..d36fee3b94 100644
--- a/mpvcore/input/input.c
+++ b/mpvcore/input/input.c
@@ -112,6 +112,7 @@ struct key_name {
#define ARG_DOUBLE OPT_DOUBLE(ARG(d), 0)
#define ARG_STRING OPT_STRING(ARG(s), 0)
#define ARG_CHOICE(c) OPT_CHOICE(ARG(i), 0, c)
+#define ARG_CHOICE_OR_INT(...) OPT_CHOICE_OR_INT(ARG(i), 0, __VA_ARGS__)
#define ARG_TIME OPT_TIME(ARG(d), 0)
#define OARG_DOUBLE(def) OPT_DOUBLE(ARG(d), 0, OPTDEF_DOUBLE(def))
#define OARG_INT(def) OPT_INT(ARG(i), 0, OPTDEF_INT(def))
@@ -216,7 +217,9 @@ static const struct mp_cmd_def mp_cmds[] = {
{"append", 1}, {"1", 1})),
}},
{ MP_CMD_PLAYLIST_CLEAR, "playlist_clear", },
- { MP_CMD_PLAYLIST_REMOVE, "playlist_remove", { ARG_INT } },
+ { MP_CMD_PLAYLIST_REMOVE, "playlist_remove", {
+ ARG_CHOICE_OR_INT(0, INT_MAX, ({"current", -1})),
+ }},
{ MP_CMD_PLAYLIST_MOVE, "playlist_move", { ARG_INT, ARG_INT } },
{ MP_CMD_RUN, "run", { ARG_STRING } },
diff --git a/mpvcore/player/command.c b/mpvcore/player/command.c
index c2db56444e..f6aa429b99 100644
--- a/mpvcore/player/command.c
+++ b/mpvcore/player/command.c
@@ -2701,6 +2701,8 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
case MP_CMD_PLAYLIST_REMOVE: {
struct playlist_entry *e = playlist_entry_from_index(mpctx->playlist,
cmd->args[0].v.i);
+ if (cmd->args[0].v.i < 0)
+ e = mpctx->playlist->current;
if (e) {
// Can't play a removed entry
if (mpctx->playlist->current == e)