command/database: add optional position parameter to "searchaddpl"
Closes https://github.com/MusicPlayerDaemon/MPD/issues/1328
This commit is contained in:
parent
651f57bced
commit
3464497880
2
NEWS
2
NEWS
|
@ -1,4 +1,6 @@
|
|||
ver 0.23.4 (not yet released)
|
||||
* protocol
|
||||
- add optional position parameter to "searchaddpl"
|
||||
* decoder
|
||||
- ffmpeg: support libavcodec 59
|
||||
* output
|
||||
|
|
|
@ -1225,7 +1225,7 @@ The music database
|
|||
|
||||
.. _command_searchaddpl:
|
||||
|
||||
:command:`searchaddpl {NAME} {FILTER} [sort {TYPE}] [window {START:END}]`
|
||||
:command:`searchaddpl {NAME} {FILTER} [sort {TYPE}] [window {START:END}] [position POS]`
|
||||
Search the database for songs matching
|
||||
``FILTER`` (see :ref:`Filters <filter_syntax>`) and add them to
|
||||
the playlist named ``NAME``.
|
||||
|
@ -1234,6 +1234,9 @@ The music database
|
|||
|
||||
Parameters have the same meaning as for :ref:`search <command_search>`.
|
||||
|
||||
The ``position`` parameter specifies where the songs will be
|
||||
inserted. [#since_0_23_4]_
|
||||
|
||||
.. _command_update:
|
||||
|
||||
:command:`update [URI]`
|
||||
|
@ -1655,3 +1658,4 @@ client-to-client messages are local to the current partition.
|
|||
.. [#since_0_23] Since :program:`MPD` 0.23
|
||||
.. [#since_0_23_1] Since :program:`MPD` 0.23.1
|
||||
.. [#since_0_23_3] Since :program:`MPD` 0.23.3
|
||||
.. [#since_0_23_4] Since :program:`MPD` 0.23.4
|
||||
|
|
|
@ -44,7 +44,7 @@ version_conf = configuration_data()
|
|||
version_conf.set_quoted('PACKAGE', meson.project_name())
|
||||
version_conf.set_quoted('PACKAGE_NAME', meson.project_name())
|
||||
version_conf.set_quoted('VERSION', meson.project_version())
|
||||
version_conf.set_quoted('PROTOCOL_VERSION', '0.23.3')
|
||||
version_conf.set_quoted('PROTOCOL_VERSION', '0.23.4')
|
||||
configure_file(output: 'Version.h', configuration: version_conf)
|
||||
|
||||
conf = configuration_data()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue