Delete remaining network replies and local redirct server in destructor
This commit is contained in:
@@ -48,6 +48,17 @@ const int AuddLyricsProvider::kMaxLength = 6000;
|
||||
|
||||
AuddLyricsProvider::AuddLyricsProvider(QObject *parent) : JsonLyricsProvider("AudD", true, false, parent), network_(new NetworkAccessManager(this)) {}
|
||||
|
||||
AuddLyricsProvider::~AuddLyricsProvider() {
|
||||
|
||||
while (!replies_.isEmpty()) {
|
||||
QNetworkReply *reply = replies_.takeFirst();
|
||||
disconnect(reply, nullptr, this, nullptr);
|
||||
reply->abort();
|
||||
reply->deleteLater();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool AuddLyricsProvider::StartSearch(const QString &artist, const QString &album, const QString &title, const quint64 id) {
|
||||
|
||||
Q_UNUSED(album);
|
||||
@@ -65,6 +76,7 @@ bool AuddLyricsProvider::StartSearch(const QString &artist, const QString &album
|
||||
QNetworkRequest req(url);
|
||||
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
|
||||
QNetworkReply *reply = network_->get(req);
|
||||
replies_ << reply;
|
||||
connect(reply, &QNetworkReply::finished, [=] { HandleSearchReply(reply, id, artist, title); });
|
||||
|
||||
//qLog(Debug) << "AudDLyrics: Sending request for" << url;
|
||||
@@ -77,6 +89,9 @@ void AuddLyricsProvider::CancelSearch(const quint64 id) { Q_UNUSED(id); }
|
||||
|
||||
void AuddLyricsProvider::HandleSearchReply(QNetworkReply *reply, const quint64 id, const QString &artist, const QString &title) {
|
||||
|
||||
if (!replies_.contains(reply)) return;
|
||||
replies_.removeAll(reply);
|
||||
disconnect(reply, nullptr, this, nullptr);
|
||||
reply->deleteLater();
|
||||
|
||||
QJsonArray json_result = ExtractResult(reply, artist, title);
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
#include <QJsonArray>
|
||||
@@ -39,10 +40,15 @@ class AuddLyricsProvider : public JsonLyricsProvider {
|
||||
|
||||
public:
|
||||
explicit AuddLyricsProvider(QObject *parent = nullptr);
|
||||
~AuddLyricsProvider();
|
||||
|
||||
bool StartSearch(const QString &artist, const QString &album, const QString &title, quint64 id);
|
||||
void CancelSearch(const quint64 id);
|
||||
|
||||
private:
|
||||
void Error(const QString &error, const QVariant &debug = QVariant());
|
||||
QJsonArray ExtractResult(QNetworkReply *reply, const QString &artist, const QString &title);
|
||||
|
||||
private slots:
|
||||
void HandleSearchReply(QNetworkReply *reply, const quint64 id, const QString &artist, const QString &title);
|
||||
|
||||
@@ -51,9 +57,7 @@ class AuddLyricsProvider : public JsonLyricsProvider {
|
||||
static const char *kAPITokenB64;
|
||||
static const int kMaxLength;
|
||||
QNetworkAccessManager *network_;
|
||||
void Error(const QString &error, const QVariant &debug = QVariant());
|
||||
|
||||
QJsonArray ExtractResult(QNetworkReply *reply, const QString &artist, const QString &title);
|
||||
QList<QNetworkReply*> replies_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#include <QNetworkReply>
|
||||
#include <QXmlStreamReader>
|
||||
|
||||
#include "core/closure.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/network.h"
|
||||
#include "core/utilities.h"
|
||||
@@ -44,6 +43,17 @@ const char *ChartLyricsProvider::kUrlSearch = "http://api.chartlyrics.com/apiv1.
|
||||
|
||||
ChartLyricsProvider::ChartLyricsProvider(QObject *parent) : LyricsProvider("ChartLyrics", false, false, parent), network_(new NetworkAccessManager(this)) {}
|
||||
|
||||
ChartLyricsProvider::~ChartLyricsProvider() {
|
||||
|
||||
while (!replies_.isEmpty()) {
|
||||
QNetworkReply *reply = replies_.takeFirst();
|
||||
disconnect(reply, nullptr, this, nullptr);
|
||||
reply->abort();
|
||||
reply->deleteLater();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool ChartLyricsProvider::StartSearch(const QString &artist, const QString&, const QString &title, const quint64 id) {
|
||||
|
||||
const ParamList params = ParamList() << Param("artist", artist)
|
||||
@@ -57,7 +67,8 @@ bool ChartLyricsProvider::StartSearch(const QString &artist, const QString&, con
|
||||
QUrl url(kUrlSearch);
|
||||
url.setQuery(url_query);
|
||||
QNetworkReply *reply = network_->get(QNetworkRequest(url));
|
||||
NewClosure(reply, SIGNAL(finished()), this, SLOT(HandleSearchReply(QNetworkReply*, const quint64, const QString&, const QString&)), reply, id, artist, title);
|
||||
replies_ << reply;
|
||||
connect(reply, &QNetworkReply::finished, [=] { HandleSearchReply(reply, id, artist, title); });
|
||||
|
||||
//qLog(Debug) << "ChartLyrics: Sending request for" << url;
|
||||
|
||||
@@ -69,6 +80,9 @@ void ChartLyricsProvider::CancelSearch(const quint64) {}
|
||||
|
||||
void ChartLyricsProvider::HandleSearchReply(QNetworkReply *reply, const quint64 id, const QString &artist, const QString &title) {
|
||||
|
||||
if (!replies_.contains(reply)) return;
|
||||
replies_.removeAll(reply);
|
||||
disconnect(reply, nullptr, this, nullptr);
|
||||
reply->deleteLater();
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
|
||||
@@ -23,19 +23,22 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
|
||||
#include "lyricsprovider.h"
|
||||
#include "lyricsfetcher.h"
|
||||
|
||||
class QNetworkAccessManager;
|
||||
class QNetworkReply;
|
||||
|
||||
class ChartLyricsProvider : public LyricsProvider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ChartLyricsProvider(QObject *parent = nullptr);
|
||||
~ChartLyricsProvider();
|
||||
|
||||
bool StartSearch(const QString &artist, const QString &album, const QString &title, const quint64 id);
|
||||
void CancelSearch(quint64 id);
|
||||
@@ -50,6 +53,7 @@ class ChartLyricsProvider : public LyricsProvider {
|
||||
static const char *kUrlSearch;
|
||||
|
||||
QNetworkAccessManager *network_;
|
||||
QList<QNetworkReply*> replies_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -73,6 +73,17 @@ GeniusLyricsProvider::GeniusLyricsProvider(QObject *parent) : JsonLyricsProvider
|
||||
|
||||
}
|
||||
|
||||
GeniusLyricsProvider::~GeniusLyricsProvider() {
|
||||
|
||||
while (!replies_.isEmpty()) {
|
||||
QNetworkReply *reply = replies_.takeFirst();
|
||||
disconnect(reply, nullptr, this, nullptr);
|
||||
reply->abort();
|
||||
reply->deleteLater();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GeniusLyricsProvider::Authenticate() {
|
||||
|
||||
QUrl redirect_url(kOAuthRedirectUrl);
|
||||
@@ -182,6 +193,7 @@ void GeniusLyricsProvider::RequestAccessToken(const QUrl &url, const QUrl &redir
|
||||
QByteArray query = new_url_query.toString(QUrl::FullyEncoded).toUtf8();
|
||||
|
||||
QNetworkReply *reply = network_->post(req, query);
|
||||
replies_ << reply;
|
||||
connect(reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(HandleLoginSSLErrors(QList<QSslError>)));
|
||||
connect(reply, &QNetworkReply::finished, [=] { AccessTokenRequestFinished(reply); });
|
||||
|
||||
@@ -204,6 +216,9 @@ void GeniusLyricsProvider::HandleLoginSSLErrors(QList<QSslError> ssl_errors) {
|
||||
|
||||
void GeniusLyricsProvider::AccessTokenRequestFinished(QNetworkReply *reply) {
|
||||
|
||||
if (!replies_.contains(reply)) return;
|
||||
replies_.removeAll(reply);
|
||||
disconnect(reply, nullptr, this, nullptr);
|
||||
reply->deleteLater();
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError || reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() != 200) {
|
||||
@@ -309,6 +324,7 @@ bool GeniusLyricsProvider::StartSearch(const QString &artist, const QString &alb
|
||||
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
|
||||
req.setRawHeader("Authorization", "Bearer " + access_token_.toUtf8());
|
||||
QNetworkReply *reply = network_->get(req);
|
||||
replies_ << reply;
|
||||
connect(reply, &QNetworkReply::finished, [=] { HandleSearchReply(reply, id); });
|
||||
|
||||
//qLog(Debug) << "GeniusLyrics: Sending request for" << url;
|
||||
@@ -321,6 +337,9 @@ void GeniusLyricsProvider::CancelSearch(const quint64 id) { Q_UNUSED(id); }
|
||||
|
||||
void GeniusLyricsProvider::HandleSearchReply(QNetworkReply *reply, const quint64 id) {
|
||||
|
||||
if (!replies_.contains(reply)) return;
|
||||
replies_.removeAll(reply);
|
||||
disconnect(reply, nullptr, this, nullptr);
|
||||
reply->deleteLater();
|
||||
|
||||
if (!requests_search_.contains(id)) return;
|
||||
@@ -422,6 +441,7 @@ void GeniusLyricsProvider::HandleSearchReply(QNetworkReply *reply, const quint64
|
||||
QNetworkRequest req(url);
|
||||
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
|
||||
QNetworkReply *new_reply = network_->get(req);
|
||||
replies_ << new_reply;
|
||||
connect(new_reply, &QNetworkReply::finished, [=] { HandleLyricReply(new_reply, search->id, url); });
|
||||
|
||||
}
|
||||
@@ -432,6 +452,9 @@ void GeniusLyricsProvider::HandleSearchReply(QNetworkReply *reply, const quint64
|
||||
|
||||
void GeniusLyricsProvider::HandleLyricReply(QNetworkReply *reply, const int search_id, const QUrl &url) {
|
||||
|
||||
if (!replies_.contains(reply)) return;
|
||||
replies_.removeAll(reply);
|
||||
disconnect(reply, nullptr, this, nullptr);
|
||||
reply->deleteLater();
|
||||
|
||||
if (!requests_search_.contains(search_id)) return;
|
||||
|
||||
@@ -48,6 +48,7 @@ class GeniusLyricsProvider : public JsonLyricsProvider {
|
||||
|
||||
public:
|
||||
explicit GeniusLyricsProvider(QObject *parent = nullptr);
|
||||
~GeniusLyricsProvider();
|
||||
|
||||
bool IsAuthenticated() { return !access_token_.isEmpty(); }
|
||||
void Authenticate();
|
||||
@@ -102,6 +103,7 @@ class GeniusLyricsProvider : public JsonLyricsProvider {
|
||||
QString access_token_;
|
||||
QStringList login_errors_;
|
||||
QMap<int, std::shared_ptr<GeniusLyricsSearchContext>> requests_search_;
|
||||
QList<QNetworkReply*> replies_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
#include <QJsonObject>
|
||||
|
||||
@@ -43,6 +43,17 @@ const char *LoloLyricsProvider::kUrlSearch = "http://api.lololyrics.com/0.5/getL
|
||||
|
||||
LoloLyricsProvider::LoloLyricsProvider(QObject *parent) : LyricsProvider("LoloLyrics", true, false, parent), network_(new NetworkAccessManager(this)) {}
|
||||
|
||||
LoloLyricsProvider::~LoloLyricsProvider() {
|
||||
|
||||
while (!replies_.isEmpty()) {
|
||||
QNetworkReply *reply = replies_.takeFirst();
|
||||
disconnect(reply, nullptr, this, nullptr);
|
||||
reply->abort();
|
||||
reply->deleteLater();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool LoloLyricsProvider::StartSearch(const QString &artist, const QString &album, const QString &title, const quint64 id) {
|
||||
|
||||
Q_UNUSED(album);
|
||||
@@ -60,6 +71,7 @@ bool LoloLyricsProvider::StartSearch(const QString &artist, const QString &album
|
||||
QNetworkRequest req(url);
|
||||
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
|
||||
QNetworkReply *reply = network_->get(req);
|
||||
replies_ << reply;
|
||||
connect(reply, &QNetworkReply::finished, [=] { HandleSearchReply(reply, id, artist, title); });
|
||||
|
||||
//qLog(Debug) << "LoloLyrics: Sending request for" << url;
|
||||
@@ -72,6 +84,9 @@ void LoloLyricsProvider::CancelSearch(const quint64 id) { Q_UNUSED(id); }
|
||||
|
||||
void LoloLyricsProvider::HandleSearchReply(QNetworkReply *reply, const quint64 id, const QString &artist, const QString &title) {
|
||||
|
||||
if (!replies_.contains(reply)) return;
|
||||
replies_.removeAll(reply);
|
||||
disconnect(reply, nullptr, this, nullptr);
|
||||
reply->deleteLater();
|
||||
|
||||
QString failure_reason;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
|
||||
@@ -37,17 +38,21 @@ class LoloLyricsProvider : public LyricsProvider {
|
||||
|
||||
public:
|
||||
explicit LoloLyricsProvider(QObject *parent = nullptr);
|
||||
~LoloLyricsProvider();
|
||||
|
||||
bool StartSearch(const QString &artist, const QString &album, const QString &title, const quint64 id);
|
||||
void CancelSearch(const quint64 id);
|
||||
|
||||
private:
|
||||
void Error(const QString &error, const QVariant &debug = QVariant());
|
||||
|
||||
private slots:
|
||||
void HandleSearchReply(QNetworkReply *reply, const quint64 id, const QString &artist, const QString &title);
|
||||
|
||||
private:
|
||||
static const char *kUrlSearch;
|
||||
QNetworkAccessManager *network_;
|
||||
void Error(const QString &error, const QVariant &debug = QVariant());
|
||||
QList<QNetworkReply*> replies_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -41,6 +41,17 @@
|
||||
|
||||
MusixmatchLyricsProvider::MusixmatchLyricsProvider(QObject *parent) : JsonLyricsProvider("Musixmatch", true, false, parent), network_(new NetworkAccessManager(this)) {}
|
||||
|
||||
MusixmatchLyricsProvider::~MusixmatchLyricsProvider() {
|
||||
|
||||
while (!replies_.isEmpty()) {
|
||||
QNetworkReply *reply = replies_.takeFirst();
|
||||
disconnect(reply, nullptr, this, nullptr);
|
||||
reply->abort();
|
||||
reply->deleteLater();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool MusixmatchLyricsProvider::StartSearch(const QString &artist, const QString &album, const QString &title, const quint64 id) {
|
||||
|
||||
QString artist_stripped = artist;
|
||||
@@ -66,6 +77,7 @@ bool MusixmatchLyricsProvider::StartSearch(const QString &artist, const QString
|
||||
QNetworkRequest req(url);
|
||||
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
|
||||
QNetworkReply *reply = network_->get(req);
|
||||
replies_ << reply;
|
||||
connect(reply, &QNetworkReply::finished, [=] { HandleSearchReply(reply, id, artist, album, title); });
|
||||
|
||||
qLog(Debug) << "MusixmatchLyrics: Sending request for" << artist_stripped << title_stripped << url;
|
||||
@@ -80,6 +92,9 @@ void MusixmatchLyricsProvider::HandleSearchReply(QNetworkReply *reply, const qui
|
||||
|
||||
Q_UNUSED(album);
|
||||
|
||||
if (!replies_.contains(reply)) return;
|
||||
replies_.removeAll(reply);
|
||||
disconnect(reply, nullptr, this, nullptr);
|
||||
reply->deleteLater();
|
||||
|
||||
LyricsSearchResults results;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
|
||||
@@ -38,6 +39,7 @@ class MusixmatchLyricsProvider : public JsonLyricsProvider {
|
||||
|
||||
public:
|
||||
explicit MusixmatchLyricsProvider(QObject *parent = nullptr);
|
||||
~MusixmatchLyricsProvider();
|
||||
|
||||
bool StartSearch(const QString &artist, const QString &album, const QString &title, const quint64 id);
|
||||
void CancelSearch(const quint64 id);
|
||||
@@ -50,6 +52,7 @@ class MusixmatchLyricsProvider : public JsonLyricsProvider {
|
||||
|
||||
private:
|
||||
QNetworkAccessManager *network_;
|
||||
QList<QNetworkReply*> replies_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -40,6 +40,17 @@ const char *OVHLyricsProvider::kUrlSearch = "https://api.lyrics.ovh/v1/";
|
||||
|
||||
OVHLyricsProvider::OVHLyricsProvider(QObject *parent) : JsonLyricsProvider("Lyrics.ovh", true, false, parent), network_(new NetworkAccessManager(this)) {}
|
||||
|
||||
OVHLyricsProvider::~OVHLyricsProvider() {
|
||||
|
||||
while (!replies_.isEmpty()) {
|
||||
QNetworkReply *reply = replies_.takeFirst();
|
||||
disconnect(reply, nullptr, this, nullptr);
|
||||
reply->abort();
|
||||
reply->deleteLater();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool OVHLyricsProvider::StartSearch(const QString &artist, const QString &album, const QString &title, const quint64 id) {
|
||||
|
||||
Q_UNUSED(album);
|
||||
@@ -48,6 +59,7 @@ bool OVHLyricsProvider::StartSearch(const QString &artist, const QString &album,
|
||||
QNetworkRequest req(url);
|
||||
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
|
||||
QNetworkReply *reply = network_->get(req);
|
||||
replies_ << reply;
|
||||
connect(reply, &QNetworkReply::finished, [=] { HandleSearchReply(reply, id, artist, title); });
|
||||
|
||||
//qLog(Debug) << "OVHLyrics: Sending request for" << url;
|
||||
@@ -60,6 +72,9 @@ void OVHLyricsProvider::CancelSearch(const quint64 id) { Q_UNUSED(id); }
|
||||
|
||||
void OVHLyricsProvider::HandleSearchReply(QNetworkReply *reply, const quint64 id, const QString &artist, const QString &title) {
|
||||
|
||||
if (!replies_.contains(reply)) return;
|
||||
replies_.removeAll(reply);
|
||||
disconnect(reply, nullptr, this, nullptr);
|
||||
reply->deleteLater();
|
||||
|
||||
QJsonObject json_obj = ExtractJsonObj(reply);
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
|
||||
@@ -37,17 +38,21 @@ class OVHLyricsProvider : public JsonLyricsProvider {
|
||||
|
||||
public:
|
||||
explicit OVHLyricsProvider(QObject *parent = nullptr);
|
||||
~OVHLyricsProvider();
|
||||
|
||||
bool StartSearch(const QString &artist, const QString &album, const QString &title, const quint64 id);
|
||||
void CancelSearch(const quint64 id);
|
||||
|
||||
private:
|
||||
void Error(const QString &error, const QVariant &debug = QVariant());
|
||||
|
||||
private slots:
|
||||
void HandleSearchReply(QNetworkReply *reply, const quint64 id, const QString &artist, const QString &title);
|
||||
|
||||
private:
|
||||
static const char *kUrlSearch;
|
||||
QNetworkAccessManager *network_;
|
||||
void Error(const QString &error, const QVariant &debug = QVariant());
|
||||
QList<QNetworkReply*> replies_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user