command/queue: add position parameter to "load"

Another one from https://github.com/MusicPlayerDaemon/MPD/issues/888
This commit is contained in:
Max Kellermann 2021-10-14 15:11:04 +02:00
parent 2e5ca1cbd2
commit 608896571c
4 changed files with 24 additions and 3 deletions

1
NEWS
View File

@ -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

View File

@ -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}`

View File

@ -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 },

View File

@ -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;
}