Subsonic API: added discTitles field in Albums
This commit is contained in:
@@ -35,8 +35,7 @@
|
||||
namespace Database
|
||||
{
|
||||
|
||||
Wt::Dbo::Query<ReleaseId>
|
||||
createQuery(Session& session, const Release::FindParameters& params)
|
||||
Wt::Dbo::Query<ReleaseId> createQuery(Session& session, const Release::FindParameters& params)
|
||||
{
|
||||
auto query{ session.getDboSession().query<ReleaseId>("SELECT DISTINCT r.id from release r") };
|
||||
|
||||
@@ -184,14 +183,12 @@ _MBID {MBID ? MBID->getAsString() : ""}
|
||||
{
|
||||
}
|
||||
|
||||
Release::pointer
|
||||
Release::create(Session& session, const std::string& name, const std::optional<UUID>& MBID)
|
||||
Release::pointer Release::create(Session& session, const std::string& name, const std::optional<UUID>& MBID)
|
||||
{
|
||||
return session.getDboSession().add(std::unique_ptr<Release> {new Release{ name, MBID }});
|
||||
}
|
||||
|
||||
std::vector<Release::pointer>
|
||||
Release::find(Session& session, const std::string& name)
|
||||
std::vector<Release::pointer> Release::find(Session& session, const std::string& name)
|
||||
{
|
||||
session.checkUniqueLocked();
|
||||
|
||||
@@ -203,8 +200,7 @@ Release::find(Session& session, const std::string& name)
|
||||
return std::vector<Release::pointer>(res.begin(), res.end());
|
||||
}
|
||||
|
||||
Release::pointer
|
||||
Release::find(Session& session, const UUID& mbid)
|
||||
Release::pointer Release::find(Session& session, const UUID& mbid)
|
||||
{
|
||||
session.checkSharedLocked();
|
||||
|
||||
@@ -214,8 +210,7 @@ Release::find(Session& session, const UUID& mbid)
|
||||
.resultValue();;
|
||||
}
|
||||
|
||||
Release::pointer
|
||||
Release::find(Session& session, ReleaseId id)
|
||||
Release::pointer Release::find(Session& session, ReleaseId id)
|
||||
{
|
||||
session.checkSharedLocked();
|
||||
|
||||
@@ -225,23 +220,20 @@ Release::find(Session& session, ReleaseId id)
|
||||
.resultValue();
|
||||
}
|
||||
|
||||
bool
|
||||
Release::exists(Session& session, ReleaseId id)
|
||||
bool Release::exists(Session& session, ReleaseId id)
|
||||
{
|
||||
session.checkSharedLocked();
|
||||
return session.getDboSession().query<int>("SELECT 1 FROM release").where("id = ?").bind(id).resultValue() == 1;
|
||||
}
|
||||
|
||||
std::size_t
|
||||
Release::getCount(Session& session)
|
||||
std::size_t Release::getCount(Session& session)
|
||||
{
|
||||
session.checkSharedLocked();
|
||||
|
||||
return session.getDboSession().query<int>("SELECT COUNT(*) FROM release");
|
||||
}
|
||||
|
||||
RangeResults<ReleaseId>
|
||||
Release::findOrderedByArtist(Session& session, Range range)
|
||||
RangeResults<ReleaseId> Release::findOrderedByArtist(Session& session, Range range)
|
||||
{
|
||||
session.checkSharedLocked();
|
||||
|
||||
@@ -256,8 +248,7 @@ Release::findOrderedByArtist(Session& session, Range range)
|
||||
return Utils::execQuery(query, range);
|
||||
}
|
||||
|
||||
RangeResults<ReleaseId>
|
||||
Release::findOrphans(Session& session, Range range)
|
||||
RangeResults<ReleaseId> Release::findOrphans(Session& session, Range range)
|
||||
{
|
||||
session.checkSharedLocked();
|
||||
|
||||
@@ -265,8 +256,7 @@ Release::findOrphans(Session& session, Range range)
|
||||
return Utils::execQuery(query, range);
|
||||
}
|
||||
|
||||
RangeResults<ReleaseId>
|
||||
Release::find(Session& session, const FindParameters& params)
|
||||
RangeResults<ReleaseId> Release::find(Session& session, const FindParameters& params)
|
||||
{
|
||||
session.checkSharedLocked();
|
||||
|
||||
@@ -275,8 +265,7 @@ Release::find(Session& session, const FindParameters& params)
|
||||
return Utils::execQuery(query, params.range);
|
||||
}
|
||||
|
||||
std::size_t
|
||||
Release::getDiscCount() const
|
||||
std::size_t Release::getDiscCount() const
|
||||
{
|
||||
assert(session());
|
||||
int res{ session()->query<int>("SELECT COUNT(DISTINCT disc_number) FROM track t")
|
||||
@@ -287,20 +276,35 @@ Release::getDiscCount() const
|
||||
return res;
|
||||
}
|
||||
|
||||
Wt::WDate
|
||||
Release::getReleaseDate() const
|
||||
std::vector<DiscInfo> Release::getDiscs() const
|
||||
{
|
||||
assert(session());
|
||||
using ResultType = std::tuple<int, std::string>;
|
||||
auto results{ session()->query<ResultType>("SELECT DISTINCT disc_number, disc_subtitle FROM track t")
|
||||
.join("release r ON r.id = t.release_id")
|
||||
.where("r.id = ?")
|
||||
.orderBy("disc_number")
|
||||
.bind(getId())
|
||||
.resultList() };
|
||||
|
||||
std::vector<DiscInfo> discs;
|
||||
for (const auto& res : results)
|
||||
discs.emplace_back(DiscInfo{ static_cast<std::size_t>(std::get<int>(res)), std::get<std::string>(res) });
|
||||
|
||||
return discs;
|
||||
}
|
||||
|
||||
Wt::WDate Release::getReleaseDate() const
|
||||
{
|
||||
return getReleaseDate(false);
|
||||
}
|
||||
|
||||
Wt::WDate
|
||||
Release::getOriginalReleaseDate() const
|
||||
Wt::WDate Release::getOriginalReleaseDate() const
|
||||
{
|
||||
return getReleaseDate(true);
|
||||
}
|
||||
|
||||
Wt::WDate
|
||||
Release::getReleaseDate(bool original) const
|
||||
Wt::WDate Release::getReleaseDate(bool original) const
|
||||
{
|
||||
assert(session());
|
||||
|
||||
@@ -320,8 +324,7 @@ Release::getReleaseDate(bool original) const
|
||||
return dates.front();
|
||||
}
|
||||
|
||||
std::optional<std::string>
|
||||
Release::getCopyright() const
|
||||
std::optional<std::string> Release::getCopyright() const
|
||||
{
|
||||
assert(session());
|
||||
|
||||
@@ -340,8 +343,7 @@ Release::getCopyright() const
|
||||
return values.front();
|
||||
}
|
||||
|
||||
std::optional<std::string>
|
||||
Release::getCopyrightURL() const
|
||||
std::optional<std::string> Release::getCopyrightURL() const
|
||||
{
|
||||
assert(session());
|
||||
|
||||
@@ -360,8 +362,7 @@ Release::getCopyrightURL() const
|
||||
return values.front();
|
||||
}
|
||||
|
||||
std::vector<Artist::pointer>
|
||||
Release::getArtists(TrackArtistLinkType linkType) const
|
||||
std::vector<Artist::pointer> Release::getArtists(TrackArtistLinkType linkType) const
|
||||
{
|
||||
assert(session());
|
||||
|
||||
@@ -377,8 +378,7 @@ Release::getArtists(TrackArtistLinkType linkType) const
|
||||
return std::vector<Artist::pointer>(res.begin(), res.end());
|
||||
}
|
||||
|
||||
std::vector<Release::pointer>
|
||||
Release::getSimilarReleases(std::optional<std::size_t> offset, std::optional<std::size_t> count) const
|
||||
std::vector<Release::pointer> Release::getSimilarReleases(std::optional<std::size_t> offset, std::optional<std::size_t> count) const
|
||||
{
|
||||
assert(session());
|
||||
|
||||
@@ -401,21 +401,18 @@ Release::getSimilarReleases(std::optional<std::size_t> offset, std::optional<std
|
||||
return std::vector<pointer>(res.begin(), res.end());
|
||||
}
|
||||
|
||||
bool
|
||||
Release::hasVariousArtists() const
|
||||
bool Release::hasVariousArtists() const
|
||||
{
|
||||
// TODO optimize
|
||||
return getArtists().size() > 1;
|
||||
}
|
||||
|
||||
std::size_t
|
||||
Release::getTracksCount() const
|
||||
std::size_t Release::getTracksCount() const
|
||||
{
|
||||
return _tracks.size();
|
||||
}
|
||||
|
||||
std::chrono::milliseconds
|
||||
Release::getDuration() const
|
||||
std::chrono::milliseconds Release::getDuration() const
|
||||
{
|
||||
assert(session());
|
||||
|
||||
@@ -427,8 +424,7 @@ Release::getDuration() const
|
||||
return query.resultValue();
|
||||
}
|
||||
|
||||
Wt::WDateTime
|
||||
Release::getLastWritten() const
|
||||
Wt::WDateTime Release::getLastWritten() const
|
||||
{
|
||||
assert(session());
|
||||
|
||||
@@ -438,8 +434,7 @@ Release::getLastWritten() const
|
||||
return query.resultValue();
|
||||
}
|
||||
|
||||
std::vector<std::vector<Cluster::pointer>>
|
||||
Release::getClusterGroups(const std::vector<ClusterType::pointer>& clusterTypes, std::size_t size) const
|
||||
std::vector<std::vector<Cluster::pointer>> Release::getClusterGroups(const std::vector<ClusterType::pointer>& clusterTypes, std::size_t size) const
|
||||
{
|
||||
assert(session());
|
||||
|
||||
|
||||
@@ -92,8 +92,6 @@ class Release final : public Object<Release, ReleaseId>
|
||||
static RangeResults<ReleaseId> findOrphans(Session& session, Range range); // no track related
|
||||
static RangeResults<ReleaseId> findOrderedByArtist(Session& session, Range range);
|
||||
|
||||
std::size_t getTracksCount() const;
|
||||
|
||||
// Get the cluster of the tracks that belong to this release
|
||||
// Each clusters are grouped by cluster type, sorted by the number of occurence (max to min)
|
||||
// size is the max number of cluster per cluster type
|
||||
@@ -110,10 +108,12 @@ class Release final : public Object<Release, ReleaseId>
|
||||
std::optional<UUID> getMBID() const { return UUID::fromString(_MBID); }
|
||||
std::optional<std::size_t> getTotalDisc() const { return _totalDisc; }
|
||||
std::size_t getDiscCount() const; // may not be total disc (if incomplete for example)
|
||||
std::vector<DiscInfo> getDiscs() const;
|
||||
std::chrono::milliseconds getDuration() const;
|
||||
Wt::WDateTime getLastWritten() const;
|
||||
std::optional<ReleaseTypePrimary> getPrimaryType() const { return _primaryType; }
|
||||
EnumSet<ReleaseTypeSecondary> getSecondaryTypes() const { return _secondaryTypes; }
|
||||
std::size_t getTracksCount() const;
|
||||
|
||||
// Setters
|
||||
void setName(std::string_view name) { _name = name; }
|
||||
|
||||
@@ -83,6 +83,12 @@ namespace Database
|
||||
static DateRange fromYearRange(int from, int to);
|
||||
};
|
||||
|
||||
struct DiscInfo
|
||||
{
|
||||
std::size_t position;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
enum class ArtistSortMethod
|
||||
{
|
||||
None,
|
||||
|
||||
@@ -13,6 +13,7 @@ add_library(lmssubsonic SHARED
|
||||
impl/responses/Artist.cpp
|
||||
impl/responses/Bookmark.cpp
|
||||
impl/responses/Contributor.cpp
|
||||
impl/responses/DiscTitle.cpp
|
||||
impl/responses/Genre.cpp
|
||||
impl/responses/Playlist.cpp
|
||||
impl/responses/Song.cpp
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "utils/String.hpp"
|
||||
|
||||
#include "responses/Artist.hpp"
|
||||
#include "responses/DiscTitle.hpp"
|
||||
#include "SubsonicId.hpp"
|
||||
|
||||
namespace API::Subsonic
|
||||
@@ -175,6 +176,11 @@ namespace API::Subsonic
|
||||
for (const ReleaseTypeSecondary releaseType : release->getSecondaryTypes())
|
||||
albumNode.addArrayValue("releaseTypes", toString(releaseType));
|
||||
|
||||
// disc titles
|
||||
albumNode.createEmptyArrayChild("discTitles");
|
||||
for (const DiscInfo& discInfo : release->getDiscs())
|
||||
albumNode.addArrayChild("discTitles", createDiscTitle(discInfo));
|
||||
|
||||
return albumNode;
|
||||
}
|
||||
}
|
||||
@@ -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/>.
|
||||
*/
|
||||
|
||||
#include "responses/DiscTitle.hpp"
|
||||
|
||||
namespace API::Subsonic
|
||||
{
|
||||
Response::Node createDiscTitle(const Database::DiscInfo& discInfo)
|
||||
{
|
||||
Response::Node discTitleNode;
|
||||
|
||||
discTitleNode.setAttribute("disc", discInfo.position);
|
||||
discTitleNode.setAttribute("title", discInfo.name);
|
||||
|
||||
return discTitleNode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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/Types.hpp"
|
||||
#include "SubsonicResponse.hpp"
|
||||
|
||||
namespace API::Subsonic
|
||||
{
|
||||
Response::Node createDiscTitle(const Database::DiscInfo& discInfo);
|
||||
}
|
||||
Reference in New Issue
Block a user