command/database: add optional position parameter to "searchaddpl"
Closes https://github.com/MusicPlayerDaemon/MPD/issues/1328
This commit is contained in:
@@ -199,13 +199,20 @@ handle_searchaddpl(Client &client, Request args, Response &)
|
||||
{
|
||||
const char *playlist = args.shift();
|
||||
|
||||
const unsigned position = ParseQueuePosition(args, UINT_MAX);
|
||||
|
||||
SongFilter filter;
|
||||
const auto selection = ParseDatabaseSelection(args, true, filter);
|
||||
|
||||
const Database &db = client.GetDatabaseOrThrow();
|
||||
|
||||
search_add_to_playlist(db, client.GetStorage(),
|
||||
playlist, selection);
|
||||
if (position == UINT_MAX)
|
||||
search_add_to_playlist(db, client.GetStorage(),
|
||||
playlist, selection);
|
||||
else
|
||||
SearchInsertIntoPlaylist(db, client.GetStorage(), selection,
|
||||
playlist, position);
|
||||
|
||||
return CommandResult::OK;
|
||||
}
|
||||
|
||||
|
@@ -22,6 +22,7 @@
|
||||
#include "PlaylistFile.hxx"
|
||||
#include "Interface.hxx"
|
||||
#include "song/DetachedSong.hxx"
|
||||
#include "protocol/Ack.hxx"
|
||||
|
||||
#include <functional>
|
||||
|
||||
@@ -61,3 +62,22 @@ SearchInsertIntoPlaylist(const Database &db, const Storage *storage,
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
void
|
||||
SearchInsertIntoPlaylist(const Database &db, const Storage *storage,
|
||||
const DatabaseSelection &selection,
|
||||
const char *playlist_name,
|
||||
unsigned position)
|
||||
{
|
||||
PlaylistFileEditor editor{
|
||||
playlist_name,
|
||||
PlaylistFileEditor::LoadMode::TRY,
|
||||
};
|
||||
|
||||
if (position > editor.size())
|
||||
throw ProtocolError{ACK_ERROR_ARG, "Bad position"};
|
||||
|
||||
if (SearchInsertIntoPlaylist(db, storage, selection,
|
||||
editor, position) > 0)
|
||||
editor.Save();
|
||||
}
|
||||
|
@@ -42,4 +42,10 @@ SearchInsertIntoPlaylist(const Database &db, const Storage *storage,
|
||||
PlaylistFileEditor &playlist,
|
||||
unsigned position);
|
||||
|
||||
void
|
||||
SearchInsertIntoPlaylist(const Database &db, const Storage *storage,
|
||||
const DatabaseSelection &selection,
|
||||
const char *playlist_name,
|
||||
unsigned position);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user