db/simple: add option to hide CUE target songs
This reduces duplicates in the music database by hiding the original song file when it is referenced by a CUE sheet. Closes https://github.com/MusicPlayerDaemon/MPD/issues/1275
This commit is contained in:
@@ -109,21 +109,21 @@ Directory::FindChild(std::string_view name) const noexcept
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool
|
||||
Directory::TargetExists(std::string_view _target) const noexcept
|
||||
Song *
|
||||
Directory::LookupTargetSong(std::string_view _target) noexcept
|
||||
{
|
||||
StringView target{_target};
|
||||
|
||||
if (target.SkipPrefix("../")) {
|
||||
if (parent == nullptr)
|
||||
return false;
|
||||
return nullptr;
|
||||
|
||||
return parent->TargetExists(target);
|
||||
return parent->LookupTargetSong(target);
|
||||
}
|
||||
|
||||
/* sorry for the const_cast ... */
|
||||
const auto lr = const_cast<Directory *>(this)->LookupDirectory(target);
|
||||
return lr.directory->FindSong(lr.rest) != nullptr;
|
||||
const auto lr = LookupDirectory(target);
|
||||
return lr.directory->FindSong(lr.rest);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -229,6 +229,7 @@ Directory::Sort() noexcept
|
||||
|
||||
void
|
||||
Directory::Walk(bool recursive, const SongFilter *filter,
|
||||
bool hide_playlist_targets,
|
||||
const VisitDirectory& visit_directory, const VisitSong& visit_song,
|
||||
const VisitPlaylist& visit_playlist) const
|
||||
{
|
||||
@@ -247,7 +248,10 @@ Directory::Walk(bool recursive, const SongFilter *filter,
|
||||
}
|
||||
|
||||
if (visit_song) {
|
||||
for (auto &song : songs){
|
||||
for (auto &song : songs) {
|
||||
if (hide_playlist_targets && song.in_playlist)
|
||||
continue;
|
||||
|
||||
const auto song2 = song.Export();
|
||||
if (filter == nullptr || filter->Match(song2))
|
||||
visit_song(song2);
|
||||
@@ -265,6 +269,7 @@ Directory::Walk(bool recursive, const SongFilter *filter,
|
||||
|
||||
if (recursive)
|
||||
child.Walk(recursive, filter,
|
||||
hide_playlist_targets,
|
||||
visit_directory, visit_song,
|
||||
visit_playlist);
|
||||
}
|
||||
|
@@ -214,7 +214,7 @@ public:
|
||||
LookupResult LookupDirectory(std::string_view uri) noexcept;
|
||||
|
||||
[[gnu::pure]]
|
||||
bool TargetExists(std::string_view target) const noexcept;
|
||||
Song *LookupTargetSong(std::string_view target) noexcept;
|
||||
|
||||
[[gnu::pure]]
|
||||
bool IsEmpty() const noexcept {
|
||||
@@ -303,6 +303,7 @@ public:
|
||||
* Caller must lock #db_mutex.
|
||||
*/
|
||||
void Walk(bool recursive, const SongFilter *match,
|
||||
bool hide_playlist_targets,
|
||||
const VisitDirectory& visit_directory, const VisitSong& visit_song,
|
||||
const VisitPlaylist& visit_playlist) const;
|
||||
|
||||
|
@@ -60,6 +60,7 @@ inline SimpleDatabase::SimpleDatabase(const ConfigBlock &block)
|
||||
#ifdef ENABLE_ZLIB
|
||||
compress(block.GetBlockValue("compress", true)),
|
||||
#endif
|
||||
hide_playlist_targets(block.GetBlockValue("hide_playlist_targets", true)),
|
||||
cache_path(block.GetPath("cache_directory"))
|
||||
{
|
||||
if (path.IsNull())
|
||||
@@ -306,6 +307,7 @@ SimpleDatabase::Visit(const DatabaseSelection &selection,
|
||||
visit_directory(r.directory->Export());
|
||||
|
||||
r.directory->Walk(selection.recursive, selection.filter,
|
||||
hide_playlist_targets,
|
||||
visit_directory, visit_song,
|
||||
visit_playlist);
|
||||
helper.Commit();
|
||||
|
@@ -44,6 +44,8 @@ class SimpleDatabase : public Database {
|
||||
bool compress;
|
||||
#endif
|
||||
|
||||
bool hide_playlist_targets;
|
||||
|
||||
/**
|
||||
* The path where cache files for Mount() are located.
|
||||
*/
|
||||
|
@@ -101,6 +101,12 @@ struct Song {
|
||||
*/
|
||||
AudioFormat audio_format = AudioFormat::Undefined();
|
||||
|
||||
/**
|
||||
* Is this song referenced by at least one playlist file that
|
||||
* is part of the database?
|
||||
*/
|
||||
bool in_playlist = false;
|
||||
|
||||
template<typename F>
|
||||
Song(F &&_filename, Directory &_parent) noexcept
|
||||
:parent(_parent), filename(std::forward<F>(_filename)) {}
|
||||
|
Reference in New Issue
Block a user