summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-07-02 13:17:50 +0200
committerwm4 <wm4@nowhere>2013-07-02 13:23:26 +0200
commit451f6788cea2f7a90badcf2fb7e1e3679fa513cb (patch)
tree3ed3098c30316d5d8c174da64359e4f873d8a0cf
parent0b77649c0b6afb103e0390163bd14f1cf9d20f06 (diff)
downloadmpv-451f6788cea2f7a90badcf2fb7e1e3679fa513cb.tar.bz2
mpv-451f6788cea2f7a90badcf2fb7e1e3679fa513cb.tar.xz
command: add some playlist manipulation commands
playlist_remove and playlist_move.
-rw-r--r--DOCS/man/en/input.rst11
-rw-r--r--core/command.c23
-rw-r--r--core/input/input.c2
-rw-r--r--core/input/input.h2
-rw-r--r--core/playlist.c14
-rw-r--r--core/playlist.h3
6 files changed, 55 insertions, 0 deletions
diff --git a/DOCS/man/en/input.rst b/DOCS/man/en/input.rst
index d57d686184..e7c53b2d3b 100644
--- a/DOCS/man/en/input.rst
+++ b/DOCS/man/en/input.rst
@@ -164,6 +164,17 @@ loadlist "<playlist>" [replace|append]
playlist_clear
Clear the playlist, except the currently played file.
+playlist_remove <index>
+ Remove the playlist entry at the given index. Index values start counting
+ with 0. You can't remove the entry for the currently played file.
+
+playlist_move <index1> <index2>
+ Move the playlist entry at index1, so that it takes the place of the
+ entry index2. (Paradoxically, the moved playlist entry will not have
+ the index value index2 after moving if index1 was lower than index2,
+ because index2 refers to the target entry, not the index the entry
+ will have after moving.)
+
run "<command>"
Run the given command with ``/bin/sh -c``. The string is expanded like in
property_expansion_.
diff --git a/core/command.c b/core/command.c
index 453ddbe974..dec3ae9c9f 100644
--- a/core/command.c
+++ b/core/command.c
@@ -2180,6 +2180,29 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
break;
}
+ case MP_CMD_PLAYLIST_REMOVE: {
+ struct playlist_entry *e = playlist_entry_from_index(mpctx->playlist,
+ cmd->args[0].v.i);
+ if (e) {
+ // Can't play a removed entry
+ if (mpctx->playlist->current == e)
+ mpctx->stop_play = PT_CURRENT_ENTRY;
+ playlist_remove(mpctx->playlist, e);
+ }
+ break;
+ }
+
+ case MP_CMD_PLAYLIST_MOVE: {
+ struct playlist_entry *e1 = playlist_entry_from_index(mpctx->playlist,
+ cmd->args[0].v.i);
+ struct playlist_entry *e2 = playlist_entry_from_index(mpctx->playlist,
+ cmd->args[1].v.i);
+ if (e1) {
+ playlist_move(mpctx->playlist, e1, e2);
+ }
+ break;
+ }
+
case MP_CMD_STOP:
// Go back to the starting point.
mpctx->stop_play = PT_STOP;
diff --git a/core/input/input.c b/core/input/input.c
index d7aaf54dec..9f63114530 100644
--- a/core/input/input.c
+++ b/core/input/input.c
@@ -183,6 +183,8 @@ static const mp_cmd_t mp_cmds[] = {
{"append", 1}, {"1", 1})),
}},
{ MP_CMD_PLAYLIST_CLEAR, "playlist_clear", },
+ { MP_CMD_PLAYLIST_REMOVE, "playlist_remove", { ARG_INT } },
+ { MP_CMD_PLAYLIST_MOVE, "playlist_move", { ARG_INT, ARG_INT } },
{ MP_CMD_RUN, "run", { ARG_STRING } },
{ MP_CMD_KEYDOWN_EVENTS, "key_down_event", { ARG_INT } },
diff --git a/core/input/input.h b/core/input/input.h
index 071efe5def..5b6170c7ae 100644
--- a/core/input/input.h
+++ b/core/input/input.h
@@ -39,6 +39,8 @@ enum mp_command_type {
MP_CMD_LOADFILE,
MP_CMD_LOADLIST,
MP_CMD_PLAYLIST_CLEAR,
+ MP_CMD_PLAYLIST_REMOVE,
+ MP_CMD_PLAYLIST_MOVE,
MP_CMD_SUB_STEP,
MP_CMD_TV_SET_CHANNEL,
MP_CMD_TV_LAST_CHANNEL,
diff --git a/core/playlist.c b/core/playlist.c
index 4132ebec10..0d96ee5d0b 100644
--- a/core/playlist.c
+++ b/core/playlist.c
@@ -114,6 +114,20 @@ void playlist_clear(struct playlist *pl)
pl->current_was_replaced = false;
}
+// Moves entry such that entry->prev = at (even if at is NULL)
+void playlist_move(struct playlist *pl, struct playlist_entry *entry,
+ struct playlist_entry *at)
+{
+ struct playlist_entry *save_current = pl->current;
+ bool save_replaced = pl->current_was_replaced;
+
+ playlist_unlink(pl, entry);
+ playlist_insert(pl, at ? at->prev : pl->last, entry);
+
+ pl->current = save_current;
+ pl->current_was_replaced = save_replaced;
+}
+
void playlist_add_file(struct playlist *pl, const char *filename)
{
playlist_add(pl, playlist_entry_new(filename));
diff --git a/core/playlist.h b/core/playlist.h
index 3e34390707..f01d4b8ddd 100644
--- a/core/playlist.h
+++ b/core/playlist.h
@@ -58,6 +58,9 @@ void playlist_add(struct playlist *pl, struct playlist_entry *add);
void playlist_remove(struct playlist *pl, struct playlist_entry *entry);
void playlist_clear(struct playlist *pl);
+void playlist_move(struct playlist *pl, struct playlist_entry *entry,
+ struct playlist_entry *at);
+
void playlist_add_file(struct playlist *pl, const char *filename);
void playlist_shuffle(struct playlist *pl);
struct playlist_entry *playlist_get_next(struct playlist *pl, int direction);