Fixed blob warning

This commit is contained in:
emeric
2026-06-21 16:33:03 +02:00
parent 75c3b302ce
commit d25233f7cc
9 changed files with 50 additions and 50 deletions
@@ -45,7 +45,7 @@ namespace lms::scrobbling::lastFm
const bool res{ track->getDuration() >= std::chrono::seconds{ 30 } && (playedDuration >= std::chrono::minutes{ 4 } || playedDuration >= track->getDuration() / 2) };
if (!res)
LOG(DEBUG, "Track cannot be scrobbled: played duration too short (" << playedDuration.count() << "s, total = " << std::chrono::duration_cast<std::chrono::seconds>(track->getDuration()).count() << "s)");
LMS_LOG_LASTFM(DEBUG, "Track cannot be scrobbled: played duration too short (" << playedDuration.count() << "s, total = " << std::chrono::duration_cast<std::chrono::seconds>(track->getDuration()).count() << "s)");
return res;
}
@@ -57,12 +57,12 @@ namespace lms::scrobbling::lastFm
, _client{ core::http::createClient(ioContext, core::Service<core::IConfig>::get()->getString("lastfm-api-base-url", "https://ws.audioscrobbler.com")) }
, _synchronizer{ ioContext, db, *_client }
{
LOG(INFO, "Starting Last.fm backend");
LMS_LOG_LASTFM(INFO, "Starting Last.fm backend");
}
LastFmBackend::~LastFmBackend()
{
LOG(INFO, "Stopped Last.fm backend");
LMS_LOG_LASTFM(INFO, "Stopped Last.fm backend");
}
void LastFmBackend::listenStarted(const Listen& listen)
@@ -106,7 +106,7 @@ namespace lms::scrobbling::lastFm
const std::string token{ utils::parseAuthToken(msg.body()) };
if (token.empty())
{
LOG(WARNING, "auth.getToken: failed to parse token");
LMS_LOG_LASTFM(WARNING, "auth.getToken: failed to parse token");
onFailure();
return;
}
@@ -120,7 +120,7 @@ namespace lms::scrobbling::lastFm
onSuccess(authUrl);
};
request.onFailureFunc = [onFailure = std::move(onFailure)] {
LOG(WARNING, "auth.getToken: HTTP request failed");
LMS_LOG_LASTFM(WARNING, "auth.getToken: HTTP request failed");
onFailure();
};
_client->sendGETRequest(std::move(request));
@@ -136,7 +136,7 @@ namespace lms::scrobbling::lastFm
auto it{ _pendingAuths.find(userId) };
if (it == _pendingAuths.end())
{
LOG(WARNING, "continueLastFmLink: no pending auth for user");
LMS_LOG_LASTFM(WARNING, "continueLastFmLink: no pending auth for user");
onFailure();
return;
}
@@ -157,7 +157,7 @@ namespace lms::scrobbling::lastFm
const std::string sessionKey{ utils::parseSessionKey(msg.body()) };
if (sessionKey.empty())
{
LOG(WARNING, "auth.getSession: failed to parse session key");
LMS_LOG_LASTFM(WARNING, "auth.getSession: failed to parse session key");
onFailure();
return;
}
@@ -178,11 +178,11 @@ namespace lms::scrobbling::lastFm
_pendingAuths.erase(userId);
}
LOG(INFO, "Last.fm account linked for user " << userId.toString());
LMS_LOG_LASTFM(INFO, "Last.fm account linked for user " << userId.toString());
onSuccess();
};
request.onFailureFunc = [onFailure = std::move(onFailure)] {
LOG(WARNING, "auth.getSession: HTTP request failed");
LMS_LOG_LASTFM(WARNING, "auth.getSession: HTTP request failed");
onFailure();
};
@@ -62,7 +62,7 @@ namespace lms::scrobbling::lastFm
const std::string artistName{ track->getArtistDisplayName() };
if (artistName.empty())
{
LOG(DEBUG, "Track '" << track->getAbsoluteFilePath() << "' cannot be scrobbled: no artist name");
LMS_LOG_LASTFM(DEBUG, "Track '" << track->getAbsoluteFilePath() << "' cannot be scrobbled: no artist name");
return std::nullopt;
}
@@ -118,7 +118,7 @@ namespace lms::scrobbling::lastFm
, _submitPeriod{ core::Service<core::IConfig>::get()->getULong("lastfm-submit-period-hours", 1) }
, _client{ client }
{
LOG(INFO, "Starting Last.fm scrobblings synchronizer, submit period = " << _submitPeriod.count() << " hours");
LMS_LOG_LASTFM(INFO, "Starting Last.fm scrobblings synchronizer, submit period = " << _submitPeriod.count() << " hours");
if (_submitPeriod.count() > 0)
scheduleSubmit(std::chrono::seconds{ 30 });
}
@@ -141,14 +141,14 @@ namespace lms::scrobbling::lastFm
const utils::LastFmCredentials creds{ utils::getLastFmCredentials(_db.getTLSSession(), listen.userId) };
if (creds.apiKey.empty() || creds.apiSecret.empty() || creds.sessionKey.empty())
{
LOG(DEBUG, "Missing Last.fm credentials for user, skipping");
LMS_LOG_LASTFM(DEBUG, "Missing Last.fm credentials for user, skipping");
return;
}
const std::optional<TrackInfo> info{ getTrackInfo(_db.getTLSSession(), listen) };
if (!info)
{
LOG(DEBUG, "Cannot build scrobble params: skipping");
LMS_LOG_LASTFM(DEBUG, "Cannot build scrobble params: skipping");
return;
}
@@ -244,7 +244,7 @@ namespace lms::scrobbling::lastFm
const utils::LastFmCredentials creds{ utils::getLastFmCredentials(_db.getTLSSession(), userId) };
if (creds.apiKey.empty() || creds.apiSecret.empty() || creds.sessionKey.empty())
{
LOG(DEBUG, "Missing Last.fm credentials for user, skipping");
LMS_LOG_LASTFM(DEBUG, "Missing Last.fm credentials for user, skipping");
continue;
}
@@ -280,7 +280,7 @@ namespace lms::scrobbling::lastFm
if (validListens.empty())
return;
LOG(DEBUG, "Sending scrobble batch of " << validListens.size() << " listens");
LMS_LOG_LASTFM(DEBUG, "Sending scrobble batch of " << validListens.size() << " listens");
params["api_key"] = creds.apiKey;
params["sk"] = creds.sessionKey;
@@ -304,7 +304,7 @@ namespace lms::scrobbling::lastFm
void ScrobblingsSynchronizer::scheduleSubmit(std::chrono::seconds fromNow)
{
LOG(DEBUG, "Scheduled pending retry in " << fromNow.count() << " seconds");
LMS_LOG_LASTFM(DEBUG, "Scheduled pending retry in " << fromNow.count() << " seconds");
_submitTimer.expires_after(fromNow);
_submitTimer.async_wait(boost::asio::bind_executor(_strand, [this](const boost::system::error_code& ec) {
if (ec == boost::asio::error::operation_aborted)
@@ -93,7 +93,7 @@ namespace lms::scrobbling::lastFm::utils
Wt::Json::Object root;
if (!Wt::Json::parse(std::string{ msgBody }, root, error))
{
LOG(ERROR, "Cannot parse auth.getToken response: " << error.what());
LMS_LOG_LASTFM(ERROR, "Cannot parse auth.getToken response: " << error.what());
return {};
}
@@ -106,7 +106,7 @@ namespace lms::scrobbling::lastFm::utils
Wt::Json::Object root;
if (!Wt::Json::parse(std::string{ msgBody }, root, error))
{
LOG(ERROR, "Cannot parse auth.getSession response: " << error.what());
LMS_LOG_LASTFM(ERROR, "Cannot parse auth.getSession response: " << error.what());
return {};
}
@@ -117,7 +117,7 @@ namespace lms::scrobbling::lastFm::utils
}
catch (const Wt::WException& e)
{
LOG(ERROR, "Cannot extract session key: " << e.what());
LMS_LOG_LASTFM(ERROR, "Cannot extract session key: " << e.what());
return {};
}
}
@@ -27,7 +27,7 @@
#include "database/objects/UserId.hpp"
#define LOG(sev, message) LMS_LOG(SCROBBLING, sev, "[lastfm] " << message)
#define LMS_LOG_LASTFM(sev, message) LMS_LOG(SCROBBLING, sev, "[lastfm] " << message)
namespace lms::db
{
@@ -45,7 +45,7 @@ namespace lms::scrobbling::listenBrainz
const bool res{ duration >= std::chrono::minutes(4) || (duration >= track->getDuration() / 2) };
if (!res)
LOG(DEBUG, "Track cannot be scrobbled since played duration is too short: " << duration.count() << "s, total duration = " << std::chrono::duration_cast<std::chrono::seconds>(track->getDuration()).count() << "s");
LMS_LOG_LISTENBRAINZ(DEBUG, "Track cannot be scrobbled since played duration is too short: " << duration.count() << "s, total duration = " << std::chrono::duration_cast<std::chrono::seconds>(track->getDuration()).count() << "s");
return res;
}
@@ -58,12 +58,12 @@ namespace lms::scrobbling::listenBrainz
, _client{ core::http::createClient(_ioContext, _baseAPIUrl) }
, _listensSynchronizer{ _ioContext, db, *_client }
{
LOG(INFO, "Starting ListenBrainz backend... API endpoint = '" << _baseAPIUrl << "'");
LMS_LOG_LISTENBRAINZ(INFO, "Starting ListenBrainz backend... API endpoint = '" << _baseAPIUrl << "'");
}
ListenBrainzBackend::~ListenBrainzBackend()
{
LOG(INFO, "Stopped ListenBrainz backend!");
LMS_LOG_LISTENBRAINZ(INFO, "Stopped ListenBrainz backend!");
}
void ListenBrainzBackend::listenStarted(const Listen& listen)
@@ -46,7 +46,7 @@ namespace lms::scrobbling::listenBrainz
if (listenObject.type("listened_at") == Wt::Json::Type::Number)
listen.listenedAt = Wt::WDateTime::fromTime_t(static_cast<int>(listenObject.get("listened_at")));
if (!listen.listenedAt.isValid())
LOG(ERROR, "Invalid or missing 'listened_at' field!");
LMS_LOG_LISTENBRAINZ(ERROR, "Invalid or missing 'listened_at' field!");
if (metadata.type("additional_info") == Wt::Json::Type::Object)
{
@@ -77,7 +77,7 @@ namespace lms::scrobbling::listenBrainz
const Wt::Json::Object& payload = root.get("payload");
const Wt::Json::Array& listens = payload.get("listens");
LOG(DEBUG, "Parsing " << listens.size() << " listens...");
LMS_LOG_LISTENBRAINZ(DEBUG, "Parsing " << listens.size() << " listens...");
result.listenCount = listens.size();
if (listens.empty())
@@ -92,13 +92,13 @@ namespace lms::scrobbling::listenBrainz
}
catch (const Wt::WException& error)
{
LOG(ERROR, "Cannot parse 'listen': " << error.what());
LMS_LOG_LISTENBRAINZ(ERROR, "Cannot parse 'listen': " << error.what());
}
}
}
catch (const Wt::WException& error)
{
LOG(ERROR, "Cannot parse 'listens': " << error.what());
LMS_LOG_LISTENBRAINZ(ERROR, "Cannot parse 'listens': " << error.what());
}
return result;
@@ -79,7 +79,7 @@ namespace lms::scrobbling::listenBrainz
const std::vector<Artist> artists{ getTrackArtists(track) };
if (artists.empty())
{
LOG(DEBUG, "Track cannot be scrobbled since it does not have any artist");
LMS_LOG_LISTENBRAINZ(DEBUG, "Track cannot be scrobbled since it does not have any artist");
return std::nullopt;
}
@@ -158,7 +158,7 @@ namespace lms::scrobbling::listenBrainz
}
catch (const Wt::WException& e)
{
LOG(ERROR, "Cannot parse listen count response: " << e.what());
LMS_LOG_LISTENBRAINZ(ERROR, "Cannot parse listen count response: " << e.what());
return std::nullopt;
}
}
@@ -176,12 +176,12 @@ namespace lms::scrobbling::listenBrainz
// if duplicated files, do not record it (let the user correct its database)
if (tracks.size() == 1)
{
LOG(DEBUG, "Matched listen '" << listen << "' using track MBID");
LMS_LOG_LISTENBRAINZ(DEBUG, "Matched listen '" << listen << "' using track MBID");
return tracks.front()->getId();
}
else if (tracks.size() > 1)
{
LOG(DEBUG, "Too many matches for listen '" << listen << "' using track MBID!");
LMS_LOG_LISTENBRAINZ(DEBUG, "Too many matches for listen '" << listen << "' using track MBID!");
return {};
}
}
@@ -192,12 +192,12 @@ namespace lms::scrobbling::listenBrainz
// if duplicated files, do not record it (let the user correct its database)
if (tracks.size() == 1)
{
LOG(DEBUG, "Matched listen '" << listen << "' using recording MBID");
LMS_LOG_LISTENBRAINZ(DEBUG, "Matched listen '" << listen << "' using recording MBID");
return tracks.front()->getId();
}
else if (tracks.size() > 1)
{
LOG(DEBUG, "Too many matches for listen '" << listen << "' using recording MBID!");
LMS_LOG_LISTENBRAINZ(DEBUG, "Too many matches for listen '" << listen << "' using recording MBID!");
return {};
}
}
@@ -216,16 +216,16 @@ namespace lms::scrobbling::listenBrainz
// conservative behavior: in case of multiple matches: reject
if (tracks.results.size() == 1)
{
LOG(DEBUG, "Matched listen '" << listen << "' using metadata");
LMS_LOG_LISTENBRAINZ(DEBUG, "Matched listen '" << listen << "' using metadata");
return tracks.results.front();
}
else if (tracks.results.size() > 1)
{
LOG(DEBUG, "Too many matches for listen '" << listen << "' using metadata");
LMS_LOG_LISTENBRAINZ(DEBUG, "Too many matches for listen '" << listen << "' using metadata");
return {};
}
LOG(DEBUG, "No match for listen '" << listen << "'");
LMS_LOG_LISTENBRAINZ(DEBUG, "No match for listen '" << listen << "'");
return {};
}
} // namespace
@@ -237,7 +237,7 @@ namespace lms::scrobbling::listenBrainz
, _maxSyncListenCount{ core::Service<core::IConfig>::get()->getULong("listenbrainz-max-sync-listen-count", 1000) }
, _syncListensPeriod{ core::Service<core::IConfig>::get()->getULong("listenbrainz-sync-listens-period-hours", 1) }
{
LOG(INFO, "Starting Listens synchronizer, maxSyncListenCount = " << _maxSyncListenCount << ", _syncListensPeriod = " << _syncListensPeriod.count() << " hours");
LMS_LOG_LISTENBRAINZ(INFO, "Starting Listens synchronizer, maxSyncListenCount = " << _maxSyncListenCount << ", _syncListensPeriod = " << _syncListensPeriod.count() << " hours");
scheduleSync(std::chrono::seconds{ 30 });
}
@@ -287,14 +287,14 @@ namespace lms::scrobbling::listenBrainz
std::string bodyText{ listenToJsonString(_db.getTLSSession(), listen, timePoint, timePoint.isValid() ? "single" : "playing_now") };
if (bodyText.empty())
{
LOG(DEBUG, "Cannot convert listen to json: skipping");
LMS_LOG_LISTENBRAINZ(DEBUG, "Cannot convert listen to json: skipping");
return;
}
const std::string listenBrainzToken{ utils::getListenBrainzToken(_db.getTLSSession(), listen.userId) };
if (listenBrainzToken.empty())
{
LOG(DEBUG, "No listenbrainz token found: skipping");
LMS_LOG_LISTENBRAINZ(DEBUG, "No listenbrainz token found: skipping");
return;
}
@@ -323,7 +323,7 @@ namespace lms::scrobbling::listenBrainz
dbListen = session.create<db::Listen>(user, track, db::ScrobblingBackend::ListenBrainz, listen.listenedAt);
dbListen.modify()->setSyncState(scrobblingState);
LOG(DEBUG, "LISTEN CREATED for user " << user->getLoginName() << ", track '" << track->getName() << "' AT " << listen.listenedAt.toString());
LMS_LOG_LISTENBRAINZ(DEBUG, "LISTEN CREATED for user " << user->getLoginName() << ", track '" << track->getName() << "' AT " << listen.listenedAt.toString());
return true;
}
@@ -365,7 +365,7 @@ namespace lms::scrobbling::listenBrainz
}
}
LOG(DEBUG, "Queing " << pendingListens.size() << " pending listen");
LMS_LOG_LISTENBRAINZ(DEBUG, "Queing " << pendingListens.size() << " pending listen");
for (const TimedListen& pendingListen : pendingListens)
enqueListen(pendingListen);
@@ -396,12 +396,12 @@ namespace lms::scrobbling::listenBrainz
if (_syncListensPeriod.count() == 0 || _maxSyncListenCount == 0)
return;
LOG(DEBUG, "Scheduled sync in " << fromNow.count() << " seconds...");
LMS_LOG_LISTENBRAINZ(DEBUG, "Scheduled sync in " << fromNow.count() << " seconds...");
_syncTimer.expires_after(fromNow);
_syncTimer.async_wait(boost::asio::bind_executor(_strand, [this](const boost::system::error_code& ec) {
if (ec == boost::asio::error::operation_aborted)
{
LOG(DEBUG, "getListens aborted");
LMS_LOG_LISTENBRAINZ(DEBUG, "getListens aborted");
return;
}
else if (ec)
@@ -415,7 +415,7 @@ namespace lms::scrobbling::listenBrainz
void ListensSynchronizer::startSync()
{
LOG(DEBUG, "Starting sync!");
LMS_LOG_LISTENBRAINZ(DEBUG, "Starting sync!");
assert(!isSyncing());
@@ -450,7 +450,7 @@ namespace lms::scrobbling::listenBrainz
void ListensSynchronizer::onSyncEnded(UserContext& context)
{
boost::asio::post(boost::asio::bind_executor(_strand, [this, &context] {
LOG(INFO, "Sync done for user '" << context.listenBrainzUserName << "', fetched: " << context.fetchedListenCount << ", matched: " << context.matchedListenCount << ", imported: " << context.importedListenCount);
LMS_LOG_LISTENBRAINZ(INFO, "Sync done for user '" << context.listenBrainzUserName << "', fetched: " << context.fetchedListenCount << ", matched: " << context.matchedListenCount << ", imported: " << context.importedListenCount);
context.syncing = false;
if (!isSyncing())
@@ -500,7 +500,7 @@ namespace lms::scrobbling::listenBrainz
const auto listenCount{ parseListenCount(msg.body()) };
boost::asio::post(boost::asio::bind_executor(_strand, [this, listenCount, &context] {
if (listenCount)
LOG(DEBUG, "Listen count for listenbrainz user '" << context.listenBrainzUserName << "' = " << *listenCount);
LMS_LOG_LISTENBRAINZ(DEBUG, "Listen count for listenbrainz user '" << context.listenBrainzUserName << "' = " << *listenCount);
bool needSync{ listenCount && (!context.listenCount || *context.listenCount != *listenCount) };
context.listenCount = listenCount;
@@ -559,7 +559,7 @@ namespace lms::scrobbling::listenBrainz
// update oldest listen for the next query
if (!parsedListen.listenedAt.isValid())
{
LOG(DEBUG, "Skipping entry due to invalid listenedAt");
LMS_LOG_LISTENBRAINZ(DEBUG, "Skipping entry due to invalid listenedAt");
continue;
}
@@ -49,13 +49,13 @@ namespace lms::scrobbling::listenBrainz::utils
Wt::Json::Object root;
if (!Wt::Json::parse(std::string{ msgBody }, root, error))
{
LOG(ERROR, "Cannot parse 'validate-token' result: " << error.what());
LMS_LOG_LISTENBRAINZ(ERROR, "Cannot parse 'validate-token' result: " << error.what());
return listenBrainzUserName;
}
if (!root.get("valid").orIfNull(false))
{
LOG(INFO, "Invalid listenbrainz user");
LMS_LOG_LISTENBRAINZ(INFO, "Invalid listenbrainz user");
return listenBrainzUserName;
}
@@ -23,7 +23,7 @@
#include "database/objects/UserId.hpp"
#define LOG(sev, message) LMS_LOG(SCROBBLING, sev, "[listenbrainz] " << message)
#define LMS_LOG_LISTENBRAINZ(sev, message) LMS_LOG(SCROBBLING, sev, "[listenbrainz] " << message)
namespace lms::db
{