New command searchplaylist
This commit is contained in:
+51
-3
@@ -8,7 +8,9 @@
|
||||
#include "PlaylistSong.hxx"
|
||||
#include "SongEnumerator.hxx"
|
||||
#include "SongPrint.hxx"
|
||||
#include "song/Filter.hxx"
|
||||
#include "song/DetachedSong.hxx"
|
||||
#include "song/LightSong.hxx"
|
||||
#include "input/Error.hxx"
|
||||
#include "fs/Traits.hxx"
|
||||
#include "thread/Mutex.hxx"
|
||||
@@ -50,13 +52,55 @@ playlist_provider_print(Response &r,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
playlist_provider_search_print(Response &r,
|
||||
const SongLoader &loader,
|
||||
const char *uri,
|
||||
SongEnumerator &e,
|
||||
unsigned start_index,
|
||||
unsigned end_index,
|
||||
SongFilter *filter) noexcept
|
||||
{
|
||||
const auto base_uri = uri != nullptr
|
||||
? PathTraitsUTF8::GetParent(uri)
|
||||
: ".";
|
||||
|
||||
std::unique_ptr<DetachedSong> song;
|
||||
|
||||
unsigned skip = start_index;
|
||||
unsigned n = end_index - start_index;
|
||||
|
||||
while ((song = e.NextSong()) != nullptr) {
|
||||
const bool detail = playlist_check_translate_song(*song, base_uri,
|
||||
loader);
|
||||
if (!filter->Match(static_cast<LightSong>(*song)))
|
||||
continue;
|
||||
|
||||
if (skip > 0) {
|
||||
--skip;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (detail)
|
||||
song_print_info(r, *song);
|
||||
else
|
||||
/* fallback if no detail was requested or no
|
||||
detail was available */
|
||||
song_print_uri(r, *song);
|
||||
|
||||
if (--n == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
playlist_file_print(Response &r, Partition &partition,
|
||||
const SongLoader &loader,
|
||||
const LocatedUri &uri,
|
||||
unsigned start_index,
|
||||
unsigned end_index,
|
||||
bool detail)
|
||||
bool detail,
|
||||
SongFilter *filter)
|
||||
try {
|
||||
Mutex mutex;
|
||||
|
||||
@@ -72,8 +116,12 @@ try {
|
||||
if (playlist == nullptr)
|
||||
throw PlaylistError::NoSuchList();
|
||||
|
||||
playlist_provider_print(r, loader, uri.canonical_uri, *playlist,
|
||||
start_index, end_index, detail);
|
||||
if (filter == nullptr)
|
||||
playlist_provider_print(r, loader, uri.canonical_uri, *playlist,
|
||||
start_index, end_index, detail);
|
||||
else
|
||||
playlist_provider_search_print(r, loader, uri.canonical_uri, *playlist,
|
||||
start_index, end_index, filter);
|
||||
} catch (...) {
|
||||
if (IsFileNotFound(std::current_exception()))
|
||||
throw PlaylistError::NoSuchList();
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
class Response;
|
||||
class SongLoader;
|
||||
class SongFilter;
|
||||
struct Partition;
|
||||
|
||||
/**
|
||||
@@ -20,4 +21,6 @@ playlist_file_print(Response &r, Partition &partition,
|
||||
const SongLoader &loader,
|
||||
const LocatedUri &uri,
|
||||
unsigned start_index, unsigned end_index,
|
||||
bool detail);
|
||||
bool detail,
|
||||
SongFilter *filter);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user