Do not report tracks with no artist + correctly skip on error
This commit is contained in:
@@ -98,6 +98,12 @@ namespace
|
|||||||
if (artists.empty())
|
if (artists.empty())
|
||||||
artists = track->getArtists({Database::TrackArtistLinkType::ReleaseArtist});
|
artists = track->getArtists({Database::TrackArtistLinkType::ReleaseArtist});
|
||||||
|
|
||||||
|
if (artists.empty())
|
||||||
|
{
|
||||||
|
LOG(DEBUG) << "Track cannot be scrobbled since it does not have any artist";
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
Wt::Json::Object additionalInfo;
|
Wt::Json::Object additionalInfo;
|
||||||
additionalInfo["listening_from"] = "LMS";
|
additionalInfo["listening_from"] = "LMS";
|
||||||
if (track->getRelease())
|
if (track->getRelease())
|
||||||
@@ -106,7 +112,6 @@ namespace
|
|||||||
additionalInfo["release_mbid"] = Wt::Json::Value {std::string {MBID->getAsString()}};
|
additionalInfo["release_mbid"] = Wt::Json::Value {std::string {MBID->getAsString()}};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!artists.empty())
|
|
||||||
{
|
{
|
||||||
Wt::Json::Array artistMBIDs;
|
Wt::Json::Array artistMBIDs;
|
||||||
for (const Database::Artist::pointer& artist : artists)
|
for (const Database::Artist::pointer& artist : artists)
|
||||||
@@ -130,10 +135,7 @@ namespace
|
|||||||
|
|
||||||
Wt::Json::Object trackMetadata;
|
Wt::Json::Object trackMetadata;
|
||||||
trackMetadata["additional_info"] = std::move(additionalInfo);
|
trackMetadata["additional_info"] = std::move(additionalInfo);
|
||||||
|
trackMetadata["artist_name"] = Wt::Json::Value {artists.front()->getName()};
|
||||||
if (!artists.empty())
|
|
||||||
trackMetadata["artist_name"] = Wt::Json::Value {artists.front()->getName()};
|
|
||||||
|
|
||||||
trackMetadata["track_name"] = Wt::Json::Value {track->getName()};
|
trackMetadata["track_name"] = Wt::Json::Value {track->getName()};
|
||||||
if (track->getRelease())
|
if (track->getRelease())
|
||||||
trackMetadata["release_name"] = Wt::Json::Value {track->getRelease()->getName()};
|
trackMetadata["release_name"] = Wt::Json::Value {track->getRelease()->getName()};
|
||||||
@@ -262,6 +264,8 @@ namespace Scrobbling
|
|||||||
|
|
||||||
_sendQueue.emplace_back(QueuedListen {listen, timePoint});
|
_sendQueue.emplace_back(QueuedListen {listen, timePoint});
|
||||||
|
|
||||||
|
LOG(DEBUG) << "listen queue size = " << _sendQueue.size();
|
||||||
|
|
||||||
if (_state == State::Idle)
|
if (_state == State::Idle)
|
||||||
sendNextQueuedListen();
|
sendNextQueuedListen();
|
||||||
}
|
}
|
||||||
@@ -270,27 +274,33 @@ namespace Scrobbling
|
|||||||
ListenBrainzScrobbler::sendNextQueuedListen()
|
ListenBrainzScrobbler::sendNextQueuedListen()
|
||||||
{
|
{
|
||||||
assert(_state == State::Idle);
|
assert(_state == State::Idle);
|
||||||
if (_sendQueue.empty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
sendListen(_sendQueue.front().listen, _sendQueue.front().timePoint);
|
while (!_sendQueue.empty())
|
||||||
_state = State::Sending;
|
{
|
||||||
|
if (sendListen(_sendQueue.front().listen, _sendQueue.front().timePoint))
|
||||||
|
{
|
||||||
|
_state = State::Sending;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
_sendQueue.pop_front();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
bool
|
||||||
ListenBrainzScrobbler::sendListen(const Listen& listen, const Wt::WDateTime& timePoint)
|
ListenBrainzScrobbler::sendListen(const Listen& listen, const Wt::WDateTime& timePoint)
|
||||||
{
|
{
|
||||||
Database::Session& session {_db.getTLSSession()};
|
Database::Session& session {_db.getTLSSession()};
|
||||||
|
|
||||||
const std::optional<UUID> listenBrainzToken {getListenBrainzToken(session, listen.userId)};
|
const std::optional<UUID> listenBrainzToken {getListenBrainzToken(session, listen.userId)};
|
||||||
if (!listenBrainzToken)
|
if (!listenBrainzToken)
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
std::string payload {listenToJsonString(session, listen, timePoint, timePoint.isValid() ? "single" : "playing_now")};
|
std::string payload {listenToJsonString(session, listen, timePoint, timePoint.isValid() ? "single" : "playing_now")};
|
||||||
if (payload.empty())
|
if (payload.empty())
|
||||||
{
|
{
|
||||||
LOG(DEBUG) << "Cannot convert listen to json: skipping";
|
LOG(DEBUG) << "Cannot convert listen to json: skipping";
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// now send this
|
// now send this
|
||||||
@@ -300,9 +310,13 @@ namespace Scrobbling
|
|||||||
|
|
||||||
const std::string endPoint {_apiEndpoint + "submit-listens"};
|
const std::string endPoint {_apiEndpoint + "submit-listens"};
|
||||||
if (!_client.post(endPoint, message))
|
if (!_client.post(endPoint, message))
|
||||||
|
{
|
||||||
LOG(ERROR) << "Cannot post to '" << endPoint << "': invalid scheme or URL?";
|
LOG(ERROR) << "Cannot post to '" << endPoint << "': invalid scheme or URL?";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
LOG(DEBUG) << "POST done to '" << endPoint << "'";
|
LOG(DEBUG) << "Listen POST done to '" << endPoint << "'";
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace Scrobbling
|
|||||||
|
|
||||||
void enqueListen(const Listen& listen, const Wt::WDateTime& timePoint);
|
void enqueListen(const Listen& listen, const Wt::WDateTime& timePoint);
|
||||||
void sendNextQueuedListen();
|
void sendNextQueuedListen();
|
||||||
void sendListen(const Listen& listen, const Wt::WDateTime& timePoint);
|
bool sendListen(const Listen& listen, const Wt::WDateTime& timePoint);
|
||||||
void onClientDone(Wt::AsioWrapper::error_code ec, const Wt::Http::Message& msg);
|
void onClientDone(Wt::AsioWrapper::error_code ec, const Wt::Http::Message& msg);
|
||||||
void throttle(std::chrono::seconds duration);
|
void throttle(std::chrono::seconds duration);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user