command/queue: add position parameter to "load"
Another one from https://github.com/MusicPlayerDaemon/MPD/issues/888
This commit is contained in:
@@ -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 },
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user