Subsonic API: fixed extensions + genres

This commit is contained in:
emeric
2023-10-10 23:30:40 +02:00
parent 042cd54171
commit 0e5249868c
9 changed files with 114 additions and 9 deletions
+2 -2
View File
@@ -18,9 +18,9 @@ The following extra fields are implemented:
* `moods`
* `originalReleaseDate`
* `isCompilation`
* `discTitles`
* `discTitles`: discs with no subtitle are omitted
* `Child` response:
* `musicBrainzId`: note this is actually the recording MBID
* `musicBrainzId`: note this is actually the recording MBID when this response refers to a song
* `genres`
* `artists`
* `albumArtists`
+1
View File
@@ -15,6 +15,7 @@ add_library(lmssubsonic SHARED
impl/responses/Bookmark.cpp
impl/responses/Contributor.cpp
impl/responses/DiscTitle.cpp
impl/responses/ItemGenre.cpp
impl/responses/Genre.cpp
impl/responses/Playlist.cpp
impl/responses/ReplayGain.cpp
@@ -176,7 +176,6 @@ namespace API::Subsonic
}
return response;
}
} // namespace
@@ -24,7 +24,7 @@ namespace API::Subsonic
Response response{ Response::createOkResponse(context.serverProtocolVersion) };
{
Response::Node& transcodeOffsetNode{ response.createNode("openSubsonicExtensions") };
Response::Node& transcodeOffsetNode{ response.createArrayNode("openSubsonicExtensions") };
transcodeOffsetNode.setAttribute("name", "transcodeOffset");
transcodeOffsetNode.addArrayValue("versions", 1);
}
+21 -1
View File
@@ -29,6 +29,7 @@
#include "responses/Artist.hpp"
#include "responses/DiscTitle.hpp"
#include "responses/ItemGenre.hpp"
#include "SubsonicId.hpp"
namespace API::Subsonic
@@ -160,9 +161,28 @@ namespace API::Subsonic
}
} };
addClusters("genres", "GENRE");
addClusters("moods", "MOOD");
// Genres
{
albumNode.createEmptyArrayChild("genres");
ClusterType::pointer clusterType{ ClusterType::find(dbSession, "GENRE") };
if (clusterType)
{
Cluster::FindParameters params;
params.setRelease(release->getId());
params.setClusterType(clusterType->getId());
for (const ClusterId clusterId : Cluster::find(dbSession, params).results)
{
Cluster::pointer cluster{ Cluster::find(dbSession, clusterId) };
if (cluster)
albumNode.addArrayChild("genres", createItemGenreNode(cluster));
}
}
}
albumNode.createEmptyArrayChild("artists");
for (const Artist::pointer& artist : release->getReleaseArtists())
albumNode.addArrayChild("artists", createArtistNode(artist));
@@ -19,8 +19,6 @@
#pragma once
#include "services/database/Cluster.hpp"
#include "services/database/Object.hpp"
#include "SubsonicResponse.hpp"
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2023 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include "responses/ItemGenre.hpp"
#include "services/database/Cluster.hpp"
namespace API::Subsonic
{
Response::Node createItemGenreNode(const Database::Cluster::pointer& cluster)
{
Response::Node genreNode;
genreNode.setAttribute("name", cluster->getName());
return genreNode;
}
}
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2023 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "services/database/Object.hpp"
#include "SubsonicResponse.hpp"
namespace Database
{
class Cluster;
}
namespace API::Subsonic
{
Response::Node createItemGenreNode(const Database::ObjectPtr<Database::Cluster>& cluster);
}
+22 -2
View File
@@ -32,6 +32,7 @@
#include "utils/String.hpp"
#include "responses/Artist.hpp"
#include "responses/Contributor.hpp"
#include "responses/ItemGenre.hpp"
#include "responses/ReplayGain.hpp"
#include "SubsonicId.hpp"
#include "Utils.hpp"
@@ -212,14 +213,33 @@ namespace API::Subsonic
{
Cluster::pointer cluster {Cluster::find(dbSession, clusterId)};
if (cluster)
trackResponse.addArrayValue(field, cluster->getName());
trackResponse.addArrayValue(field, cluster->getName());
}
}
} };
addClusters("genres", "GENRE");
addClusters("moods", "MOOD");
// Genres
{
trackResponse.createEmptyArrayChild("genres");
ClusterType::pointer clusterType{ ClusterType::find(dbSession, "GENRE") };
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.addArrayChild("genres", createItemGenreNode(cluster));
}
}
}
trackResponse.addChild("replayGain", createReplayGainNode(track));
return trackResponse;