diff --git a/src/libs/subsonic/impl/SubsonicResponse.cpp b/src/libs/subsonic/impl/SubsonicResponse.cpp index 4b2dda49..b59898a0 100644 --- a/src/libs/subsonic/impl/SubsonicResponse.cpp +++ b/src/libs/subsonic/impl/SubsonicResponse.cpp @@ -73,7 +73,7 @@ namespace API::Subsonic _children[key].emplace_back(std::move(node)); } - void Response::Node::createEmptyArrayChild(const std::string& key) + void Response::Node::createEmptyArrayChild(std::string_view key) { if (_value) throw LmsException{ "Node already has a value" }; @@ -82,12 +82,12 @@ namespace API::Subsonic } - void Response::Node::addArrayChild(const std::string& key, Node node) + void Response::Node::addArrayChild(std::string_view key, Node node) { if (_value) throw LmsException{ "Node already has a value" }; - _childrenArrays[key].emplace_back(std::move(node)); + _childrenArrays[std::string{ key }].emplace_back(std::move(node)); } void Response::Node::createEmptyArrayValue(const std::string& key) diff --git a/src/libs/subsonic/impl/SubsonicResponse.hpp b/src/libs/subsonic/impl/SubsonicResponse.hpp index 4c72b9ce..b532688d 100644 --- a/src/libs/subsonic/impl/SubsonicResponse.hpp +++ b/src/libs/subsonic/impl/SubsonicResponse.hpp @@ -209,8 +209,8 @@ namespace API::Subsonic Node& createArrayChild(const std::string& key); void addChild(const std::string& key, Node node); - void createEmptyArrayChild(const std::string& key); - void addArrayChild(const std::string& key, Node node); + void createEmptyArrayChild(std::string_view key); + void addArrayChild(std::string_view key, Node node); void createEmptyArrayValue(const std::string& key); void addArrayValue(const std::string& key, std::string_view value); diff --git a/src/libs/subsonic/impl/responses/Song.cpp b/src/libs/subsonic/impl/responses/Song.cpp index af8b742d..434fab66 100644 --- a/src/libs/subsonic/impl/responses/Song.cpp +++ b/src/libs/subsonic/impl/responses/Song.cpp @@ -162,13 +162,37 @@ namespace API::Subsonic } trackResponse.createEmptyArrayChild("contributors"); - for (const TrackArtistLinkId linkId : TrackArtistLink::find(dbSession, TrackArtistLink::FindParameters{}.setTrack(track->getId())).results) { - TrackArtistLink::pointer link{ TrackArtistLink::find(dbSession, linkId) }; - // Don't report artists nor release artists as they are set in dedicated fields - if (link && link->getType() != TrackArtistLinkType::Artist && link->getType() != TrackArtistLinkType::ReleaseArtist) - trackResponse.addArrayChild("contributors", createContributorNode(link)); + TrackArtistLink::FindParameters params; + params.setTrack(track->getId()); + + for (const TrackArtistLinkId linkId : TrackArtistLink::find(dbSession, params).results) + { + TrackArtistLink::pointer link{ TrackArtistLink::find(dbSession, linkId) }; + // Don't report artists nor release artists as they are set in dedicated fields + if (link && link->getType() != TrackArtistLinkType::Artist && link->getType() != TrackArtistLinkType::ReleaseArtist) + trackResponse.addArrayChild("contributors", createContributorNode(link)); } + } + + auto addArtistLinks{ [&](std::string_view nodeName, TrackArtistLinkType type) + { + trackResponse.createEmptyArrayChild(nodeName); + + TrackArtistLink::FindParameters params; + params.setTrack(track->getId()); + params.setLinkType(type); + + for (const TrackArtistLinkId linkId : TrackArtistLink::find(dbSession, params).results) + { + TrackArtistLink::pointer link{ TrackArtistLink::find(dbSession, linkId) }; + if (link) + trackResponse.addArrayChild(nodeName, createArtistNode(link->getArtist())); + } + } }; + + addArtistLinks("artists", TrackArtistLinkType::Artist); + addArtistLinks("albumartists", TrackArtistLinkType::ReleaseArtist); return trackResponse; }