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