From 608896571c32ea0cee69d44788a4d447c8bfe037 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 14 Oct 2021 15:11:04 +0200 Subject: [PATCH] command/queue: add position parameter to "load" Another one from https://github.com/MusicPlayerDaemon/MPD/issues/888 --- NEWS | 1 + doc/protocol.rst | 7 ++++++- src/command/AllCommands.cxx | 2 +- src/command/PlaylistCommands.cxx | 17 ++++++++++++++++- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index f9a4a47c1..f074b47fa 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,7 @@ ver 0.23 (not yet released) - support relative positions in "addid" - fix relative positions in "move" and "moveid" - add "position" parameter to "findadd" and "searchadd" + - add position parameter to "load" * database - proxy: require MPD 0.20 or later - proxy: require libmpdclient 2.11 or later diff --git a/doc/protocol.rst b/doc/protocol.rst index 79c2ed9bd..df11350a7 100644 --- a/doc/protocol.rst +++ b/doc/protocol.rst @@ -917,11 +917,16 @@ remote playlists (absolute URI with a supported scheme). .. _command_load: -:command:`load {NAME} [START:END]` +:command:`load {NAME} [START:END] [POSITION]` Loads the playlist into the current queue. Playlist plugins are supported. A range may be specified to load only a part of the playlist. + The ``POSITION`` parameter specifies where the songs will be + inserted into the queue. (This requires specifying the range as + well; the special value `0:` can be used if the whole playlist + shall be loaded at a certain queue position.) + .. _command_playlistadd: :command:`playlistadd {NAME} {URI}` diff --git a/src/command/AllCommands.cxx b/src/command/AllCommands.cxx index f90f696d0..2a4a2208d 100644 --- a/src/command/AllCommands.cxx +++ b/src/command/AllCommands.cxx @@ -135,7 +135,7 @@ static constexpr struct command commands[] = { { "listplaylist", PERMISSION_READ, 1, 1, handle_listplaylist }, { "listplaylistinfo", PERMISSION_READ, 1, 1, handle_listplaylistinfo }, { "listplaylists", PERMISSION_READ, 0, 0, handle_listplaylists }, - { "load", PERMISSION_ADD, 1, 2, handle_load }, + { "load", PERMISSION_ADD, 1, 3, handle_load }, { "lsinfo", PERMISSION_READ, 0, 1, handle_lsinfo }, { "mixrampdb", PERMISSION_PLAYER, 1, 1, handle_mixrampdb }, { "mixrampdelay", PERMISSION_PLAYER, 1, 1, handle_mixrampdelay }, diff --git a/src/command/PlaylistCommands.cxx b/src/command/PlaylistCommands.cxx index 97ed475dc..cd3579aa6 100644 --- a/src/command/PlaylistCommands.cxx +++ b/src/command/PlaylistCommands.cxx @@ -79,11 +79,16 @@ handle_load(Client &client, Request args, [[maybe_unused]] Response &r) ); RangeArg range = args.ParseOptional(1, RangeArg::All()); - const ScopeBulkEdit bulk_edit(client.GetPartition()); + auto &partition = client.GetPartition(); + const ScopeBulkEdit bulk_edit(partition); auto &playlist = client.GetPlaylist(); const unsigned old_size = playlist.GetLength(); + const unsigned position = args.size > 2 + ? args.ParseUnsigned(2, old_size) + : old_size; + const SongLoader loader(client); playlist_open_into_queue(uri, range.start, range.end, @@ -96,6 +101,16 @@ handle_load(Client &client, Request args, [[maybe_unused]] Response &r) for (unsigned i = old_size; i < new_size; ++i) instance.LookupRemoteTag(playlist.queue.Get(i).GetRealURI()); + if (position < old_size) { + const RangeArg move_range{old_size, new_size}; + + try { + partition.MoveRange(move_range, position); + } catch (...) { + /* ignore - shall we handle it? */ + } + } + return CommandResult::OK; }