Subsonic API: added genres/moods tags for songs
This commit is contained in:
@@ -90,7 +90,7 @@ namespace API::Subsonic
|
||||
_childrenArrays[std::string{ key }].emplace_back(std::move(node));
|
||||
}
|
||||
|
||||
void Response::Node::createEmptyArrayValue(const std::string& key)
|
||||
void Response::Node::createEmptyArrayValue(std::string_view key)
|
||||
{
|
||||
if (_value)
|
||||
throw LmsException{ "Node already has a value" };
|
||||
@@ -98,12 +98,12 @@ namespace API::Subsonic
|
||||
_childrenValues.emplace(key, std::vector<std::string>{});
|
||||
}
|
||||
|
||||
void Response::Node::addArrayValue(const std::string& key, std::string_view value)
|
||||
void Response::Node::addArrayValue(std::string_view key, std::string_view value)
|
||||
{
|
||||
if (_value)
|
||||
throw LmsException{ "Node already has a value" };
|
||||
|
||||
_childrenValues[key].push_back(std::string{ value });
|
||||
_childrenValues[std::string{ key }].push_back(std::string{ value });
|
||||
}
|
||||
|
||||
Response::Node& Response::Node::createChild(const std::string& key)
|
||||
|
||||
@@ -211,8 +211,8 @@ namespace API::Subsonic
|
||||
void addChild(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);
|
||||
void createEmptyArrayValue(std::string_view key);
|
||||
void addArrayValue(std::string_view key, std::string_view value);
|
||||
|
||||
private:
|
||||
void setVersionAttribute(ProtocolVersion version);
|
||||
|
||||
@@ -147,17 +147,17 @@ namespace API::Subsonic
|
||||
trackResponse.setAttribute("starred", StringUtils::toISO8601String(dateTime));
|
||||
|
||||
// Report the first GENRE for this track
|
||||
ClusterType::pointer clusterType{ ClusterType::find(dbSession, "GENRE") };
|
||||
if (clusterType)
|
||||
ClusterType::pointer genreClusterType{ ClusterType::find(dbSession, "GENRE") };
|
||||
if (genreClusterType)
|
||||
{
|
||||
auto clusters{ track->getClusterGroups({clusterType}, 1) };
|
||||
auto clusters{ track->getClusterGroups({genreClusterType}, 1) };
|
||||
if (!clusters.empty() && !clusters.front().empty())
|
||||
trackResponse.setAttribute("genre", clusters.front().front()->getName());
|
||||
}
|
||||
|
||||
// OpenSubsonic specific fields (must always be set)
|
||||
{
|
||||
std::optional<UUID> mbid {track->getRecordingMBID()};
|
||||
std::optional<UUID> mbid{ track->getRecordingMBID() };
|
||||
trackResponse.setAttribute("musicBrainzId", mbid ? mbid->getAsString() : "");
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ namespace API::Subsonic
|
||||
// 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)
|
||||
@@ -194,6 +194,29 @@ namespace API::Subsonic
|
||||
addArtistLinks("artists", TrackArtistLinkType::Artist);
|
||||
addArtistLinks("albumartists", TrackArtistLinkType::ReleaseArtist);
|
||||
|
||||
auto addClusters{ [&](std::string_view field, std::string_view clusterTypeName)
|
||||
{
|
||||
trackResponse.createEmptyArrayValue(field);
|
||||
|
||||
ClusterType::pointer clusterType{ ClusterType::find(dbSession, clusterTypeName) };
|
||||
if (clusterType)
|
||||
{
|
||||
Cluster::FindParameters params;
|
||||
params.setTrack(track->getId());
|
||||
params.setClusterType(clusterType->getId());
|
||||
|
||||
for (const ClusterId clusterId : Cluster::find(dbSession, params).results)
|
||||
{
|
||||
Cluster::pointer cluster {Cluster::find(dbSession, clusterId)};
|
||||
if (cluster)
|
||||
trackResponse.addArrayValue(field, cluster->getName());
|
||||
}
|
||||
}
|
||||
} };
|
||||
|
||||
addClusters("genres", "GENRE");
|
||||
addClusters("moods", "MOOD");
|
||||
|
||||
return trackResponse;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user