Subsonic API: added timestamps into coverart ids, Made use of image ids to save a lookup, ref #558

This commit is contained in:
emeric
2024-12-08 15:48:52 +01:00
parent 38efdfaf87
commit 4a8754a7fa
18 changed files with 253 additions and 179 deletions
+6 -3
View File
@@ -32,6 +32,7 @@
#include "services/feedback/IFeedbackService.hpp"
#include "services/scrobbling/IScrobblingService.hpp"
#include "CoverArtId.hpp"
#include "RequestContext.hpp"
#include "SubsonicId.hpp"
#include "responses/Artist.hpp"
@@ -84,9 +85,10 @@ namespace lms::api::subsonic
}
albumNode.setAttribute("created", core::stringUtils::toISO8601String(release->getLastWritten()));
if (release->getImage())
if (const auto image{ release->getImage() })
{
albumNode.setAttribute("coverArt", idToString(release->getId()));
const CoverArtId coverArtId{ image->getId(), image->getLastWriteTime().toTime_t() };
albumNode.setAttribute("coverArt", idToString(coverArtId));
}
else
{
@@ -96,7 +98,8 @@ namespace lms::api::subsonic
params.setRange(db::Range{ 0, 1 });
db::Track::find(context.dbSession, params, [&](const db::Track::pointer& track) {
albumNode.setAttribute("coverArt", idToString(track->getId()));
const CoverArtId coverArtId{ track->getId(), track->getLastWriteTime().toTime_t() };
albumNode.setAttribute("coverArt", idToString(coverArtId));
});
}
if (const auto year{ release->getYear() })
+6 -2
View File
@@ -29,6 +29,7 @@
#include "database/User.hpp"
#include "services/feedback/IFeedbackService.hpp"
#include "CoverArtId.hpp"
#include "RequestContext.hpp"
#include "SubsonicId.hpp"
@@ -94,8 +95,11 @@ namespace lms::api::subsonic
artistNode.setAttribute("id", idToString(artist->getId()));
artistNode.setAttribute("name", artist->getName());
if (artist->getImage())
artistNode.setAttribute("coverArt", idToString(artist->getId()));
if (const auto image{ artist->getImage() })
{
const CoverArtId coverArtId{ image->getId(), image->getLastWriteTime().toTime_t() };
artistNode.setAttribute("coverArt", idToString(coverArtId));
}
const std::size_t count{ Release::getCount(context.dbSession, Release::FindParameters{}.setArtist(artist->getId())) };
artistNode.setAttribute("albumCount", count);
@@ -23,6 +23,7 @@
#include "database/TrackList.hpp"
#include "database/User.hpp"
#include "CoverArtId.hpp"
#include "SubsonicId.hpp"
namespace lms::api::subsonic
@@ -50,7 +51,8 @@ namespace lms::api::subsonic
params.setSortMethod(TrackSortMethod::TrackList);
db::Track::find(session, params, [&](const db::Track::pointer& track) {
playlistNode.setAttribute("coverArt", idToString(track->getId()));
const CoverArtId coverArtId{ track->getId(), track->getLastWriteTime().toTime_t() };
playlistNode.setAttribute("coverArt", idToString(coverArtId));
});
return playlistNode;
+13 -3
View File
@@ -36,6 +36,7 @@
#include "services/feedback/IFeedbackService.hpp"
#include "services/scrobbling/IScrobblingService.hpp"
#include "CoverArtId.hpp"
#include "RequestContext.hpp"
#include "SubsonicId.hpp"
#include "responses/Artist.hpp"
@@ -109,9 +110,18 @@ namespace lms::api::subsonic
const Release::pointer release{ track->getRelease() };
if (track->hasCover())
trackResponse.setAttribute("coverArt", idToString(track->getId()));
else if (release && release->getImage())
trackResponse.setAttribute("coverArt", idToString(release->getId()));
{
const CoverArtId coverArtId{ track->getId(), track->getLastWriteTime().toTime_t() };
trackResponse.setAttribute("coverArt", idToString(coverArtId));
}
else if (release)
{
if (const db::Image::pointer image{ release->getImage() })
{
const CoverArtId coverArtId{ image->getId(), image->getLastWriteTime().toTime_t() };
trackResponse.setAttribute("coverArt", idToString(coverArtId));
}
}
const std::vector<Artist::pointer>& artists{ track->getArtists({ TrackArtistLinkType::Artist }) };
if (!artists.empty())