summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorGuido Cella <guido@guidocella.xyz>2023-10-07 16:53:52 +0200
committerDudemanguy <random342@airmail.cc>2023-10-09 15:09:35 +0000
commit81dea9031dec05559624b6d2a8ea9bf89667f755 (patch)
treeba78bb2183bccf8e73fff01932e0029057888c82 /player
parentbcb9ed56fae7da59b495c5bddd7576821627dffb (diff)
downloadmpv-81dea9031dec05559624b6d2a8ea9bf89667f755.tar.bz2
mpv-81dea9031dec05559624b6d2a8ea9bf89667f755.tar.xz
command: add playlist-next-playlist and playlist-prev-playlist
playlist-prev-playlist goes to the beginning of the previous playlist because this seems more useful and symmetrical to playlist-next-playlist. It does not go to the beginning when the current playlist-path starts with the previous playlist-path, e.g. with mpv --loop-playlist foo/, which expands to foo/{1..9}.zip, the current playlist path foo/1.zip beings with the playlist-path foo/ of {2..9}.zip and thus playlist-prev-playlist goes to 9.zip rather than to 2.zip. Closes #12495.
Diffstat (limited to 'player')
-rw-r--r--player/command.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/player/command.c b/player/command.c
index cf4971a4b3..8d7bc39c11 100644
--- a/player/command.c
+++ b/player/command.c
@@ -5321,6 +5321,45 @@ static void cmd_playlist_next_prev(void *p)
mpctx->add_osd_seek_info |= OSD_SEEK_INFO_CURRENT_FILE;
}
+static void cmd_playlist_next_prev_playlist(void *p)
+{
+ struct mp_cmd_ctx *cmd = p;
+ struct MPContext *mpctx = cmd->mpctx;
+ int direction = *(int *)cmd->priv;
+
+ struct playlist_entry *entry =
+ playlist_get_first_in_next_playlist(mpctx->playlist, direction);
+
+ if (!entry && mpctx->opts->loop_times != 1 && mpctx->playlist->current) {
+ entry = direction > 0 ? playlist_get_first(mpctx->playlist)
+ : playlist_get_last(mpctx->playlist);
+
+ if (entry && entry->playlist_path &&
+ strcmp(entry->playlist_path,
+ mpctx->playlist->current->playlist_path) == 0)
+ entry = NULL;
+
+ if (direction > 0 && entry && mpctx->opts->loop_times > 1) {
+ mpctx->opts->loop_times--;
+ m_config_notify_change_opt_ptr(mpctx->mconfig,
+ &mpctx->opts->loop_times);
+ }
+
+ if (direction < 0)
+ entry = playlist_get_first_in_same_playlist(
+ entry, mpctx->playlist->current->playlist_path);
+ }
+
+ if (!entry) {
+ cmd->success = false;
+ return;
+ }
+
+ mp_set_playlist_entry(mpctx, entry);
+ if (cmd->on_osd & MP_ON_OSD_MSG)
+ mpctx->add_osd_seek_info |= OSD_SEEK_INFO_CURRENT_FILE;
+}
+
static void cmd_playlist_play_index(void *p)
{
struct mp_cmd_ctx *cmd = p;
@@ -6373,6 +6412,10 @@ const struct mp_cmd_def mp_cmds[] = {
},
.priv = &(const int){-1},
},
+ { "playlist-next-playlist", cmd_playlist_next_prev_playlist,
+ .priv = &(const int){1} },
+ { "playlist-prev-playlist", cmd_playlist_next_prev_playlist,
+ .priv = &(const int){-1} },
{ "playlist-play-index", cmd_playlist_play_index,
{
{"index", OPT_CHOICE(v.i, {"current", -2}, {"none", -1}),