Commit 48e8a268 authored by Max Kellermann's avatar Max Kellermann

command/playlist: allow range in playlistdelete

parent ade847bc
ver 0.23.3 (not yet released) ver 0.23.3 (not yet released)
* protocol * protocol
- add optional position parameter to "add" and "playlistadd" - add optional position parameter to "add" and "playlistadd"
- allow range in "playlistdelete"
* output * output
- alsa: add option "stop_dsd_silence" to work around DSD DAC noise - alsa: add option "stop_dsd_silence" to work around DSD DAC noise
* macOS: fix libfmt related build failure * macOS: fix libfmt related build failure
......
...@@ -929,7 +929,7 @@ remote playlists (absolute URI with a supported scheme). ...@@ -929,7 +929,7 @@ remote playlists (absolute URI with a supported scheme).
inserted into the queue; it can be relative as described in inserted into the queue; it can be relative as described in
:ref:`addid <command_addid>`. (This requires specifying the range :ref:`addid <command_addid>`. (This requires specifying the range
as well; the special value `0:` can be used if the whole playlist as well; the special value `0:` can be used if the whole playlist
shall be loaded at a certain queue position.) [#since_0_23_1] shall be loaded at a certain queue position.) [#since_0_23_1]_
.. _command_playlistadd: .. _command_playlistadd:
...@@ -953,6 +953,8 @@ remote playlists (absolute URI with a supported scheme). ...@@ -953,6 +953,8 @@ remote playlists (absolute URI with a supported scheme).
Deletes ``SONGPOS`` from the Deletes ``SONGPOS`` from the
playlist `NAME.m3u`. playlist `NAME.m3u`.
The second parameter can be a range. [#since_0_23_3]_
.. _command_playlistmove: .. _command_playlistmove:
:command:`playlistmove {NAME} {FROM} {TO}` :command:`playlistmove {NAME} {FROM} {TO}`
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "song/DetachedSong.hxx" #include "song/DetachedSong.hxx"
#include "SongLoader.hxx" #include "SongLoader.hxx"
#include "Mapper.hxx" #include "Mapper.hxx"
#include "protocol/RangeArg.hxx"
#include "fs/io/TextFile.hxx" #include "fs/io/TextFile.hxx"
#include "fs/io/FileOutputStream.hxx" #include "fs/io/FileOutputStream.hxx"
#include "fs/io/BufferedOutputStream.hxx" #include "fs/io/BufferedOutputStream.hxx"
...@@ -315,6 +316,16 @@ PlaylistFileEditor::RemoveIndex(unsigned i) ...@@ -315,6 +316,16 @@ PlaylistFileEditor::RemoveIndex(unsigned i)
} }
void void
PlaylistFileEditor::RemoveRange(RangeArg range)
{
if (!range.CheckClip(size()))
throw PlaylistError::BadRange();
contents.erase(std::next(contents.begin(), range.start),
std::next(contents.begin(), range.end));
}
void
PlaylistFileEditor::Save() PlaylistFileEditor::Save()
{ {
SavePlaylistFile(path, contents); SavePlaylistFile(path, contents);
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <string> #include <string>
struct ConfigData; struct ConfigData;
struct RangeArg;
class DetachedSong; class DetachedSong;
class SongLoader; class SongLoader;
class PlaylistVector; class PlaylistVector;
...@@ -60,6 +61,7 @@ public: ...@@ -60,6 +61,7 @@ public:
void MoveIndex(unsigned src, unsigned dest); void MoveIndex(unsigned src, unsigned dest);
void RemoveIndex(unsigned i); void RemoveIndex(unsigned i);
void RemoveRange(RangeArg range);
void Save(); void Save();
......
...@@ -175,10 +175,10 @@ handle_playlistdelete([[maybe_unused]] Client &client, ...@@ -175,10 +175,10 @@ handle_playlistdelete([[maybe_unused]] Client &client,
Request args, [[maybe_unused]] Response &r) Request args, [[maybe_unused]] Response &r)
{ {
const char *const name = args[0]; const char *const name = args[0];
unsigned from = args.ParseUnsigned(1); const auto range = args.ParseRange(1);
PlaylistFileEditor editor(name, PlaylistFileEditor::LoadMode::YES); PlaylistFileEditor editor(name, PlaylistFileEditor::LoadMode::YES);
editor.RemoveIndex(from); editor.RemoveRange(range);
editor.Save(); editor.Save();
return CommandResult::OK; return CommandResult::OK;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment