From d7bd3ca1959774daa119b31e1e2755ddba213ffe Mon Sep 17 00:00:00 2001 From: emeric Date: Mon, 2 Oct 2023 22:37:54 +0200 Subject: [PATCH] Subsonic API: added musicBrainzId extra field --- src/libs/subsonic/impl/responses/Album.cpp | 21 ++++++++++++--------- src/libs/subsonic/impl/responses/Artist.cpp | 6 ++++++ src/libs/subsonic/impl/responses/Song.cpp | 6 ++++++ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/libs/subsonic/impl/responses/Album.cpp b/src/libs/subsonic/impl/responses/Album.cpp index 1248c4b5..aec0cc24 100644 --- a/src/libs/subsonic/impl/responses/Album.cpp +++ b/src/libs/subsonic/impl/responses/Album.cpp @@ -81,21 +81,24 @@ namespace API::Subsonic } } - if (id3) + // Report the first GENRE for this track + ClusterType::pointer clusterType{ ClusterType::find(dbSession, "GENRE") }; + if (clusterType) { - // Report the first GENRE for this track - ClusterType::pointer clusterType{ ClusterType::find(dbSession, "GENRE") }; - if (clusterType) - { - auto clusters{ release->getClusterGroups({clusterType}, 1) }; - if (!clusters.empty() && !clusters.front().empty()) - albumNode.setAttribute("genre", clusters.front().front()->getName()); - } + auto clusters{ release->getClusterGroups({clusterType}, 1) }; + if (!clusters.empty() && !clusters.front().empty()) + albumNode.setAttribute("genre", clusters.front().front()->getName()); } if (const Wt::WDateTime dateTime{ Service::get()->getStarredDateTime(user->getId(), release->getId()) }; dateTime.isValid()) albumNode.setAttribute("starred", StringUtils::toISO8601String(dateTime)); // TODO report correct date/time + // OpenSubsonic specific field + { + std::optional mbid {release->getMBID()}; + albumNode.setAttribute("musicBrainzId", mbid ? mbid->getAsString() : ""); + } + return albumNode; } } \ No newline at end of file diff --git a/src/libs/subsonic/impl/responses/Artist.cpp b/src/libs/subsonic/impl/responses/Artist.cpp index 85ec6d40..a527a437 100644 --- a/src/libs/subsonic/impl/responses/Artist.cpp +++ b/src/libs/subsonic/impl/responses/Artist.cpp @@ -68,6 +68,12 @@ namespace API::Subsonic if (const Wt::WDateTime dateTime{ Service::get()->getStarredDateTime(user->getId(), artist->getId()) }; dateTime.isValid()) artistNode.setAttribute("starred", StringUtils::toISO8601String(dateTime)); + // OpenSubsonic specific field + { + std::optional mbid {artist->getMBID()}; + artistNode.setAttribute("musicBrainzId", mbid ? mbid->getAsString() : ""); + } + return artistNode; } } \ No newline at end of file diff --git a/src/libs/subsonic/impl/responses/Song.cpp b/src/libs/subsonic/impl/responses/Song.cpp index af319ff2..f737c49c 100644 --- a/src/libs/subsonic/impl/responses/Song.cpp +++ b/src/libs/subsonic/impl/responses/Song.cpp @@ -153,6 +153,12 @@ namespace API::Subsonic trackResponse.setAttribute("genre", clusters.front().front()->getName()); } + // OpenSubsonic specific field + { + std::optional mbid {track->getTrackMBID()}; + trackResponse.setAttribute("musicBrainzId", mbid ? mbid->getAsString() : ""); + } + return trackResponse; } } \ No newline at end of file