Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow range in listplaylist and listplaylistinfo #1991

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ver 0.24 (not yet released)
- stickers on playlists and some tag types
- new command "stickernames"
- new "search"/"find" filter "added-since"
- allow range in listplaylist and listplaylistinfo
* database
- attribute "added" shows when each song was added to the database
- proxy: require MPD 0.21 or later
Expand Down
10 changes: 6 additions & 4 deletions doc/protocol.rst
Original file line number Diff line number Diff line change
Expand Up @@ -944,15 +944,17 @@ remote playlists (absolute URI with a supported scheme).

.. _command_listplaylist:

:command:`listplaylist {NAME}`
:command:`listplaylist {NAME} [{START:END}]`
Lists the songs in the playlist. Playlist plugins are
supported.
supported. A range may be specified to list
only a part of the playlist. [#since_0_24]_

.. _command_listplaylistinfo:

:command:`listplaylistinfo {NAME}`
:command:`listplaylistinfo {NAME} [{START:END}]`
Lists the songs with metadata in the playlist. Playlist
plugins are supported.
plugins are supported. A range may be specified to list
only a part of the playlist. [#since_0_24]_

.. _command_listplaylists:

Expand Down
4 changes: 2 additions & 2 deletions src/command/AllCommands.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ static constexpr struct command commands[] = {
{ "listneighbors", PERMISSION_READ, 0, 0, handle_listneighbors },
#endif
{ "listpartitions", PERMISSION_READ, 0, 0, handle_listpartitions },
{ "listplaylist", PERMISSION_READ, 1, 1, handle_listplaylist },
{ "listplaylistinfo", PERMISSION_READ, 1, 1, handle_listplaylistinfo },
{ "listplaylist", PERMISSION_READ, 1, 2, handle_listplaylist },
{ "listplaylistinfo", PERMISSION_READ, 1, 2, handle_listplaylistinfo },
{ "listplaylists", PERMISSION_READ, 0, 0, handle_listplaylists },
{ "load", PERMISSION_ADD, 1, 3, handle_load },
{ "lsinfo", PERMISSION_READ, 0, 1, handle_lsinfo },
Expand Down
8 changes: 6 additions & 2 deletions src/command/PlaylistCommands.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ handle_listplaylist(Client &client, Request args, Response &r)
#endif
);

RangeArg range = args.ParseOptional(1, RangeArg::All());

if (playlist_file_print(r, client.GetPartition(), SongLoader(client),
name, false))
name, range.start, range.end, false))
return CommandResult::OK;

throw PlaylistError::NoSuchList();
Expand All @@ -142,8 +144,10 @@ handle_listplaylistinfo(Client &client, Request args, Response &r)
#endif
);

RangeArg range = args.ParseOptional(1, RangeArg::All());

if (playlist_file_print(r, client.GetPartition(), SongLoader(client),
name, true))
name, range.start, range.end, true))
return CommandResult::OK;

throw PlaylistError::NoSuchList();
Expand Down
23 changes: 19 additions & 4 deletions src/playlist/Print.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,25 @@ static void
playlist_provider_print(Response &r,
const SongLoader &loader,
const char *uri,
SongEnumerator &e, bool detail) noexcept
SongEnumerator &e,
unsigned start_index,
unsigned end_index,
bool detail) noexcept
{
const auto base_uri = uri != nullptr
? PathTraitsUTF8::GetParent(uri)
: ".";

std::unique_ptr<DetachedSong> song;
while ((song = e.NextSong()) != nullptr) {

for (unsigned i = 0;
i < end_index && (song = e.NextSong()) != nullptr;
++i) {
if (i < start_index) {
/* skip songs before the start index */
continue;
}

if (playlist_check_translate_song(*song, base_uri,
loader) &&
detail)
Expand All @@ -40,7 +51,10 @@ playlist_provider_print(Response &r,
bool
playlist_file_print(Response &r, Partition &partition,
const SongLoader &loader,
const LocatedUri &uri, bool detail)
const LocatedUri &uri,
unsigned start_index,
unsigned end_index,
bool detail)
{
Mutex mutex;

Expand All @@ -56,6 +70,7 @@ playlist_file_print(Response &r, Partition &partition,
if (playlist == nullptr)
return false;

playlist_provider_print(r, loader, uri.canonical_uri, *playlist, detail);
playlist_provider_print(r, loader, uri.canonical_uri, *playlist,
start_index, end_index, detail);
return true;
}
4 changes: 3 additions & 1 deletion src/playlist/Print.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ struct Partition;
bool
playlist_file_print(Response &r, Partition &partition,
const SongLoader &loader,
const LocatedUri &uri, bool detail);
const LocatedUri &uri,
unsigned start_index, unsigned end_index,
bool detail);

#endif
Loading