Subsonic API: added artists and albumartists tags for songs
This commit is contained in:
@@ -73,7 +73,7 @@ namespace API::Subsonic
|
|||||||
_children[key].emplace_back(std::move(node));
|
_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)
|
if (_value)
|
||||||
throw LmsException{ "Node already has a 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)
|
if (_value)
|
||||||
throw LmsException{ "Node already has a 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)
|
void Response::Node::createEmptyArrayValue(const std::string& key)
|
||||||
|
|||||||
@@ -209,8 +209,8 @@ namespace API::Subsonic
|
|||||||
Node& createArrayChild(const std::string& key);
|
Node& createArrayChild(const std::string& key);
|
||||||
|
|
||||||
void addChild(const std::string& key, Node node);
|
void addChild(const std::string& key, Node node);
|
||||||
void createEmptyArrayChild(const std::string& key);
|
void createEmptyArrayChild(std::string_view key);
|
||||||
void addArrayChild(const std::string& key, Node node);
|
void addArrayChild(std::string_view key, Node node);
|
||||||
void createEmptyArrayValue(const std::string& key);
|
void createEmptyArrayValue(const std::string& key);
|
||||||
void addArrayValue(const std::string& key, std::string_view value);
|
void addArrayValue(const std::string& key, std::string_view value);
|
||||||
|
|
||||||
|
|||||||
@@ -162,13 +162,37 @@ namespace API::Subsonic
|
|||||||
}
|
}
|
||||||
|
|
||||||
trackResponse.createEmptyArrayChild("contributors");
|
trackResponse.createEmptyArrayChild("contributors");
|
||||||
for (const TrackArtistLinkId linkId : TrackArtistLink::find(dbSession, TrackArtistLink::FindParameters{}.setTrack(track->getId())).results)
|
|
||||||
{
|
{
|
||||||
TrackArtistLink::pointer link{ TrackArtistLink::find(dbSession, linkId) };
|
TrackArtistLink::FindParameters params;
|
||||||
// Don't report artists nor release artists as they are set in dedicated fields
|
params.setTrack(track->getId());
|
||||||
if (link && link->getType() != TrackArtistLinkType::Artist && link->getType() != TrackArtistLinkType::ReleaseArtist)
|
|
||||||
trackResponse.addArrayChild("contributors", createContributorNode(link));
|
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;
|
return trackResponse;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user