Subsonic API: can now search albums and artists using mbid, fixes #826
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
#include "core/Random.hpp"
|
#include "core/Random.hpp"
|
||||||
|
#include "core/UUID.hpp"
|
||||||
#include "database/Session.hpp"
|
#include "database/Session.hpp"
|
||||||
#include "database/objects/Artist.hpp"
|
#include "database/objects/Artist.hpp"
|
||||||
#include "database/objects/Directory.hpp"
|
#include "database/objects/Directory.hpp"
|
||||||
@@ -172,37 +173,48 @@ namespace lms::api::subsonic
|
|||||||
|
|
||||||
if (!keywords.empty())
|
if (!keywords.empty())
|
||||||
{
|
{
|
||||||
|
if (keywords.size() == 1)
|
||||||
|
{
|
||||||
|
if (const auto mbid{ core::UUID::fromString(keywords.front()) })
|
||||||
|
{
|
||||||
|
if (const auto artist{ Artist::find(context.getDbSession(), *mbid) })
|
||||||
|
{
|
||||||
|
searchResultNode.addArrayChild("artist", createArtistNode(context, artist));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
findArtists();
|
findArtists();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScanTracker<ArtistId>::ScanInfo scanInfo{
|
||||||
|
.clientAddress = context.getClientIpAddr(),
|
||||||
|
.clientName = std::string{ context.getClientName() },
|
||||||
|
.user = context.getUser()->getId(),
|
||||||
|
.library = mediaLibrary,
|
||||||
|
.offset = artistOffset
|
||||||
|
};
|
||||||
|
|
||||||
|
if (ArtistId cachedLastRetrievedId{ currentScansInProgress.extractLastRetrievedObjectId(scanInfo) }; cachedLastRetrievedId.isValid())
|
||||||
|
{
|
||||||
|
Artist::find(
|
||||||
|
context.getDbSession(), cachedLastRetrievedId, artistCount, [&](const Artist::pointer& artist) {
|
||||||
|
searchResultNode.addArrayChild("artist", createArtistNode(context, artist));
|
||||||
|
},
|
||||||
|
mediaLibrary);
|
||||||
|
lastRetrievedId = cachedLastRetrievedId;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ScanTracker<ArtistId>::ScanInfo scanInfo{
|
findArtists();
|
||||||
.clientAddress = context.getClientIpAddr(),
|
}
|
||||||
.clientName = std::string{ context.getClientName() },
|
|
||||||
.user = context.getUser()->getId(),
|
|
||||||
.library = mediaLibrary,
|
|
||||||
.offset = artistOffset
|
|
||||||
};
|
|
||||||
|
|
||||||
if (ArtistId cachedLastRetrievedId{ currentScansInProgress.extractLastRetrievedObjectId(scanInfo) }; cachedLastRetrievedId.isValid())
|
if (lastRetrievedId.isValid())
|
||||||
{
|
{
|
||||||
Artist::find(
|
scanInfo.offset = artistOffset + artistCount;
|
||||||
context.getDbSession(), cachedLastRetrievedId, artistCount, [&](const Artist::pointer& artist) {
|
currentScansInProgress.setObjectId(scanInfo, lastRetrievedId);
|
||||||
searchResultNode.addArrayChild("artist", createArtistNode(context, artist));
|
|
||||||
},
|
|
||||||
mediaLibrary);
|
|
||||||
lastRetrievedId = cachedLastRetrievedId;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
findArtists();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastRetrievedId.isValid())
|
|
||||||
{
|
|
||||||
scanInfo.offset = artistOffset + artistCount;
|
|
||||||
currentScansInProgress.setObjectId(scanInfo, lastRetrievedId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,37 +248,48 @@ namespace lms::api::subsonic
|
|||||||
|
|
||||||
if (!keywords.empty())
|
if (!keywords.empty())
|
||||||
{
|
{
|
||||||
|
if (keywords.size() == 1)
|
||||||
|
{
|
||||||
|
if (const auto mbid{ core::UUID::fromString(keywords.front()) })
|
||||||
|
{
|
||||||
|
if (const auto release{ Release::find(context.getDbSession(), *mbid) })
|
||||||
|
{
|
||||||
|
searchResultNode.addArrayChild("album", createAlbumNode(context, release, id3));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
findReleases();
|
findReleases();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScanTracker<ReleaseId>::ScanInfo scanInfo{
|
||||||
|
.clientAddress = context.getClientIpAddr(),
|
||||||
|
.clientName = std::string{ context.getClientName() },
|
||||||
|
.user = context.getUser()->getId(),
|
||||||
|
.library = mediaLibrary,
|
||||||
|
.offset = albumOffset
|
||||||
|
};
|
||||||
|
|
||||||
|
if (ReleaseId cachedLastRetrievedId{ currentScansInProgress.extractLastRetrievedObjectId(scanInfo) }; cachedLastRetrievedId.isValid())
|
||||||
|
{
|
||||||
|
Release::find(
|
||||||
|
context.getDbSession(), cachedLastRetrievedId, albumCount, [&](const Release::pointer& release) {
|
||||||
|
searchResultNode.addArrayChild("album", createAlbumNode(context, release, id3));
|
||||||
|
},
|
||||||
|
mediaLibrary);
|
||||||
|
lastRetrievedId = cachedLastRetrievedId;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ScanTracker<ReleaseId>::ScanInfo scanInfo{
|
findReleases();
|
||||||
.clientAddress = context.getClientIpAddr(),
|
}
|
||||||
.clientName = std::string{ context.getClientName() },
|
|
||||||
.user = context.getUser()->getId(),
|
|
||||||
.library = mediaLibrary,
|
|
||||||
.offset = albumOffset
|
|
||||||
};
|
|
||||||
|
|
||||||
if (ReleaseId cachedLastRetrievedId{ currentScansInProgress.extractLastRetrievedObjectId(scanInfo) }; cachedLastRetrievedId.isValid())
|
if (lastRetrievedId.isValid())
|
||||||
{
|
{
|
||||||
Release::find(
|
scanInfo.offset = albumOffset + albumCount;
|
||||||
context.getDbSession(), cachedLastRetrievedId, albumCount, [&](const Release::pointer& release) {
|
currentScansInProgress.setObjectId(scanInfo, lastRetrievedId);
|
||||||
searchResultNode.addArrayChild("album", createAlbumNode(context, release, id3));
|
|
||||||
},
|
|
||||||
mediaLibrary);
|
|
||||||
lastRetrievedId = cachedLastRetrievedId;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
findReleases();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastRetrievedId.isValid())
|
|
||||||
{
|
|
||||||
scanInfo.offset = albumOffset + albumCount;
|
|
||||||
currentScansInProgress.setObjectId(scanInfo, lastRetrievedId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,36 +324,35 @@ namespace lms::api::subsonic
|
|||||||
if (!keywords.empty())
|
if (!keywords.empty())
|
||||||
{
|
{
|
||||||
findTracks();
|
findTracks();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScanTracker<TrackId>::ScanInfo scanInfo{
|
||||||
|
.clientAddress = context.getClientIpAddr(),
|
||||||
|
.clientName = std::string{ context.getClientName() },
|
||||||
|
.user = context.getUser()->getId(),
|
||||||
|
.library = mediaLibrary,
|
||||||
|
.offset = songOffset
|
||||||
|
};
|
||||||
|
|
||||||
|
if (TrackId cachedLastRetrievedId{ currentScansInProgress.extractLastRetrievedObjectId(scanInfo) }; cachedLastRetrievedId.isValid())
|
||||||
|
{
|
||||||
|
Track::find(
|
||||||
|
context.getDbSession(), cachedLastRetrievedId, songCount, [&](const Track::pointer& track) {
|
||||||
|
searchResultNode.addArrayChild("song", createSongNode(context, track, id3));
|
||||||
|
},
|
||||||
|
mediaLibrary);
|
||||||
|
lastRetrievedId = cachedLastRetrievedId;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ScanTracker<TrackId>::ScanInfo scanInfo{
|
findTracks();
|
||||||
.clientAddress = context.getClientIpAddr(),
|
}
|
||||||
.clientName = std::string{ context.getClientName() },
|
|
||||||
.user = context.getUser()->getId(),
|
|
||||||
.library = mediaLibrary,
|
|
||||||
.offset = songOffset
|
|
||||||
};
|
|
||||||
|
|
||||||
if (TrackId cachedLastRetrievedId{ currentScansInProgress.extractLastRetrievedObjectId(scanInfo) }; cachedLastRetrievedId.isValid())
|
if (lastRetrievedId.isValid())
|
||||||
{
|
{
|
||||||
Track::find(
|
scanInfo.offset = songOffset + songCount;
|
||||||
context.getDbSession(), cachedLastRetrievedId, songCount, [&](const Track::pointer& track) {
|
currentScansInProgress.setObjectId(scanInfo, lastRetrievedId);
|
||||||
searchResultNode.addArrayChild("song", createSongNode(context, track, id3));
|
|
||||||
},
|
|
||||||
mediaLibrary);
|
|
||||||
lastRetrievedId = cachedLastRetrievedId;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
findTracks();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastRetrievedId.isValid())
|
|
||||||
{
|
|
||||||
scanInfo.offset = songOffset + songCount;
|
|
||||||
currentScansInProgress.setObjectId(scanInfo, lastRetrievedId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user