Merge branch 'searchplaylist_pos' of https://github.com/jcorporation/MPD

This commit is contained in:
Max Kellermann 2024-10-26 08:14:31 +02:00
commit 98bc63251e
2 changed files with 17 additions and 7 deletions

1
NEWS
View File

@ -17,6 +17,7 @@ ver 0.24 (not yet released)
- consume only idle flags that were subscribed to - consume only idle flags that were subscribed to
- volume command is no longer deprecated - volume command is no longer deprecated
- new "available" subcommand for tagtypes - new "available" subcommand for tagtypes
- searching stored playlists respond now with song position
* database * database
- attribute "added" shows when each song was added to the database - attribute "added" shows when each song was added to the database
- fix integer overflows with 64-bit inode numbers - fix integer overflows with 64-bit inode numbers

View File

@ -17,6 +17,8 @@
#include "Partition.hxx" #include "Partition.hxx"
#include "Instance.hxx" #include "Instance.hxx"
#include "PlaylistError.hxx" #include "PlaylistError.hxx"
#include <fmt/format.h>
#include "client/Response.hxx"
static void static void
playlist_provider_print(Response &r, playlist_provider_print(Response &r,
@ -69,27 +71,34 @@ playlist_provider_search_print(Response &r,
unsigned skip = start_index; unsigned skip = start_index;
unsigned n = end_index - start_index; unsigned n = end_index - start_index;
unsigned position = 0;
while ((song = e.NextSong()) != nullptr) { while ((song = e.NextSong()) != nullptr) {
const bool detail = playlist_check_translate_song(*song, base_uri, const bool detail = playlist_check_translate_song(*song, base_uri,
loader); loader);
if (!filter->Match(static_cast<LightSong>(*song))) if (!filter->Match(static_cast<LightSong>(*song))) {
continue; ++position;
if (skip > 0) {
--skip;
continue; continue;
} }
if (detail) if (skip > 0) {
--skip;
++position;
continue;
}
if (detail) {
song_print_info(r, *song); song_print_info(r, *song);
else r.Fmt(FMT_STRING("Pos: {}\n"), position);
} else
/* fallback if no detail was requested or no /* fallback if no detail was requested or no
detail was available */ detail was available */
song_print_uri(r, *song); song_print_uri(r, *song);
if (--n == 0) if (--n == 0)
break; break;
++position;
} }
} }