Fix musicbrainz tagfetcher

This commit is contained in:
Jonas Kvinge 2019-08-04 16:02:22 +02:00
parent 28bca261fb
commit be1e14df81
2 changed files with 11 additions and 12 deletions

View File

@ -81,7 +81,7 @@ QByteArray MusicBrainzClient::GetReplyData(QNetworkReply *reply, QString &error)
else {
if (reply->error() != QNetworkReply::NoError && reply->error() < 200) {
// This is a network error, there is nothing more to do.
error = Error(QString("%1 (%2)").arg(reply->errorString()).arg(reply->error()));
Error(QString("%1 (%2)").arg(reply->errorString()).arg(reply->error()));
}
else {
// See if there is Json data containing "error" - then use that instead.
@ -99,10 +99,11 @@ QByteArray MusicBrainzClient::GetReplyData(QNetworkReply *reply, QString &error)
error = QString("%1 (%2)").arg(reply->errorString()).arg(reply->error());
}
else {
error = Error(QString("Received HTTP code %1").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt()));
error = QString("Received HTTP code %1").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
}
Error(error, data);
}
error = Error(error);
else Error(error);
}
return QByteArray();
}
@ -136,7 +137,7 @@ void MusicBrainzClient::Start(const int id, const QStringList &mbid_list) {
++request_number;
if (request_number > kMaxRequestPerTrack) break;
Request request(id, mbid, request_number);
requests_pending_.enqueue(request);
requests_pending_.insert(id, request);
}
if (!timer_flush_requests_->isActive()) {
@ -166,7 +167,7 @@ void MusicBrainzClient::FlushRequests() {
if (!requests_.isEmpty() || requests_pending_.isEmpty()) return;
Request request = requests_pending_.dequeue();
Request request = requests_pending_.take(requests_pending_.firstKey());
const ParamList params = ParamList() << Param("inc", "artists+releases+media");
@ -216,7 +217,7 @@ void MusicBrainzClient::RequestFinished(QNetworkReply *reply, const int id, cons
}
// No more pending requests for this id: emit the results we have.
if (!requests_.contains(id)) {
if (!requests_.contains(id) && !requests_pending_.contains(id)) {
// Merge the results we have
ResultList ret;
QList<PendingResults> result_list_list = pending_results_.take(id);
@ -493,13 +494,12 @@ MusicBrainzClient::ResultList MusicBrainzClient::UniqueResults(const ResultList&
}
}
return ret;
}
QString MusicBrainzClient::Error(QString error, QVariant debug) {
void MusicBrainzClient::Error(const QString &error, QVariant debug) {
qLog(Error) << "MusicBrainz:" << error;
if (debug.isValid()) qLog(Debug) << debug;
return error;
}

View File

@ -31,7 +31,6 @@
#include <QList>
#include <QMap>
#include <QMultiMap>
#include <QQueue>
#include <QString>
#include <QStringList>
#include <QNetworkReply>
@ -199,7 +198,7 @@ class MusicBrainzClient : public QObject {
static void ParseArtist(QXmlStreamReader* reader, QString* artist);
static Release ParseRelease(QXmlStreamReader* reader);
static ResultList UniqueResults(const ResultList& results, UniqueResultsSortOption opt = SortResults);
QString Error(QString error, QVariant debug = QVariant());
void Error(const QString &error, QVariant debug = QVariant());
private:
@ -212,7 +211,7 @@ class MusicBrainzClient : public QObject {
QNetworkAccessManager* network_;
NetworkTimeouts* timeouts_;
QQueue<Request> requests_pending_;
QMultiMap<int, Request> requests_pending_;
QMultiMap<int, QNetworkReply*> requests_;
// Results we received so far, kept here until all the replies are finished
QMap<int, QList<PendingResults>> pending_results_;