From 4b7078297d9579bf5bf804a94e4f09a5c31167d4 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Mon, 19 Nov 2018 20:08:10 +0100
Subject: [PATCH] db/upnp: use the generic ::CollectUniqueTags() function

This function implements the "group" feature on top of the
Database::Visit() method.
---
 NEWS                                       |  2 ++
 src/db/plugins/upnp/UpnpDatabasePlugin.cxx | 23 ++--------------------
 2 files changed, 4 insertions(+), 21 deletions(-)

diff --git a/NEWS b/NEWS
index 9d2c98dc7..f1f16c4da 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,6 @@
 ver 0.21.4 (not yet released)
+* database
+  - upnp: implement "list ... group"
 
 ver 0.21.3 (2018/11/16)
 * output
diff --git a/src/db/plugins/upnp/UpnpDatabasePlugin.cxx b/src/db/plugins/upnp/UpnpDatabasePlugin.cxx
index 89c5c7a02..6db9da940 100644
--- a/src/db/plugins/upnp/UpnpDatabasePlugin.cxx
+++ b/src/db/plugins/upnp/UpnpDatabasePlugin.cxx
@@ -27,6 +27,7 @@
 #include "db/DatabasePlugin.hxx"
 #include "db/Selection.hxx"
 #include "db/VHelper.hxx"
+#include "db/UniqueTags.hxx"
 #include "db/DatabaseError.hxx"
 #include "db/LightDirectory.hxx"
 #include "song/LightSong.hxx"
@@ -627,27 +628,7 @@ std::map<std::string, std::set<std::string>>
 UpnpDatabase::CollectUniqueTags(const DatabaseSelection &selection,
 				TagType tag, TagType group) const
 {
-	(void)group; // TODO: use group
-
-	std::map<std::string, std::set<std::string>> result;
-	auto &values = result[std::string()];
-
-	for (auto& server : discovery->GetDirectories()) {
-		const auto dirbuf = SearchSongs(server, rootid, selection);
-
-		for (const auto &dirent : dirbuf.objects) {
-			if (dirent.type != UPnPDirObject::Type::ITEM ||
-			    dirent.item_class != UPnPDirObject::ItemClass::MUSIC)
-				continue;
-
-			const char *value = dirent.tag.GetValue(tag);
-			if (value != nullptr) {
-				values.emplace(value);
-			}
-		}
-	}
-
-	return result;
+	return ::CollectUniqueTags(*this, selection, tag, group);
 }
 
 DatabaseStats