1
0
mirror of https://github.com/strawberrymusicplayer/strawberry synced 2025-02-02 02:26:44 +01:00

Reduce network access managers

This commit is contained in:
Jonas Kvinge 2021-08-12 23:00:10 +02:00
parent f2d52f83fe
commit e6858719c9
41 changed files with 91 additions and 104 deletions

View File

@ -128,17 +128,17 @@ class ApplicationImpl {
cover_providers_([=]() {
CoverProviders *cover_providers = new CoverProviders(app);
// Initialize the repository of cover providers.
cover_providers->AddProvider(new LastFmCoverProvider(app, app));
cover_providers->AddProvider(new MusicbrainzCoverProvider(app, app));
cover_providers->AddProvider(new DiscogsCoverProvider(app, app));
cover_providers->AddProvider(new DeezerCoverProvider(app, app));
cover_providers->AddProvider(new MusixmatchCoverProvider(app, app));
cover_providers->AddProvider(new SpotifyCoverProvider(app, app));
cover_providers->AddProvider(new LastFmCoverProvider(app, cover_providers->network(), app));
cover_providers->AddProvider(new MusicbrainzCoverProvider(app, cover_providers->network(), app));
cover_providers->AddProvider(new DiscogsCoverProvider(app, cover_providers->network(), app));
cover_providers->AddProvider(new DeezerCoverProvider(app, cover_providers->network(), app));
cover_providers->AddProvider(new MusixmatchCoverProvider(app, cover_providers->network(), app));
cover_providers->AddProvider(new SpotifyCoverProvider(app, cover_providers->network(), app));
#ifdef HAVE_TIDAL
cover_providers->AddProvider(new TidalCoverProvider(app, app));
cover_providers->AddProvider(new TidalCoverProvider(app, cover_providers->network(), app));
#endif
#ifdef HAVE_QOBUZ
cover_providers->AddProvider(new QobuzCoverProvider(app, app));
cover_providers->AddProvider(new QobuzCoverProvider(app, cover_providers->network(), app));
#endif
cover_providers->ReloadSettings();
return cover_providers;
@ -152,12 +152,12 @@ class ApplicationImpl {
lyrics_providers_([=]() {
LyricsProviders *lyrics_providers = new LyricsProviders(app);
// Initialize the repository of lyrics providers.
lyrics_providers->AddProvider(new AuddLyricsProvider(app));
lyrics_providers->AddProvider(new GeniusLyricsProvider(app));
lyrics_providers->AddProvider(new OVHLyricsProvider(app));
lyrics_providers->AddProvider(new LoloLyricsProvider(app));
lyrics_providers->AddProvider(new MusixmatchLyricsProvider(app));
lyrics_providers->AddProvider(new ChartLyricsProvider(app));
lyrics_providers->AddProvider(new AuddLyricsProvider(lyrics_providers->network(), app));
lyrics_providers->AddProvider(new GeniusLyricsProvider(lyrics_providers->network(), app));
lyrics_providers->AddProvider(new OVHLyricsProvider(lyrics_providers->network(), app));
lyrics_providers->AddProvider(new LoloLyricsProvider(lyrics_providers->network(), app));
lyrics_providers->AddProvider(new MusixmatchLyricsProvider(lyrics_providers->network(), app));
lyrics_providers->AddProvider(new ChartLyricsProvider(lyrics_providers->network(), app));
lyrics_providers->ReloadSettings();
return lyrics_providers;
}),

View File

@ -27,4 +27,4 @@
#include "core/application.h"
#include "coverprovider.h"
CoverProvider::CoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool batch, const bool allow_missing_album, Application *app, QObject *parent) : QObject(parent), app_(app), name_(name), enabled_(enabled), order_(0), authentication_required_(authentication_required), quality_(quality), batch_(batch), allow_missing_album_(allow_missing_album) {}
CoverProvider::CoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool batch, const bool allow_missing_album, Application *app, NetworkAccessManager *network, QObject *parent) : QObject(parent), app_(app), network_(network), name_(name), enabled_(enabled), order_(0), authentication_required_(authentication_required), quality_(quality), batch_(batch), allow_missing_album_(allow_missing_album) {}

View File

@ -33,6 +33,7 @@
#include "albumcoverfetcher.h"
class Application;
class NetworkAccessManager;
// Each implementation of this interface downloads covers from one online service.
// There are no limitations on what this service might be - last.fm, Amazon, Google Images - you name it.
@ -40,7 +41,7 @@ class CoverProvider : public QObject {
Q_OBJECT
public:
explicit CoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool batch, const bool allow_missing_album, Application *app, QObject *parent);
explicit CoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool batch, const bool allow_missing_album, Application *app, NetworkAccessManager *network, QObject *parent);
// A name (very short description) of this provider, like "last.fm".
QString name() const { return name_; }
@ -73,8 +74,9 @@ class CoverProvider : public QObject {
void SearchResults(int, CoverProviderSearchResults);
void SearchFinished(int, CoverProviderSearchResults);
private:
protected:
Application *app_;
NetworkAccessManager *network_;
QString name_;
bool enabled_;
int order_;

View File

@ -33,6 +33,7 @@
#include <QtDebug>
#include "core/logging.h"
#include "core/networkaccessmanager.h"
#include "coverprovider.h"
#include "coverproviders.h"
@ -40,7 +41,7 @@
int CoverProviders::NextOrderId = 0;
CoverProviders::CoverProviders(QObject *parent) : QObject(parent) {}
CoverProviders::CoverProviders(QObject *parent) : QObject(parent), network_(new NetworkAccessManager(this)) {}
CoverProviders::~CoverProviders() {

View File

@ -32,6 +32,7 @@
#include <QString>
#include <QAtomicInt>
class NetworkAccessManager;
class CoverProvider;
// This is a repository for cover providers.
@ -59,6 +60,8 @@ class CoverProviders : public QObject {
int NextId();
NetworkAccessManager *network() const { return network_; }
private slots:
void ProviderDestroyed();
@ -67,6 +70,8 @@ class CoverProviders : public QObject {
static int NextOrderId;
NetworkAccessManager *network_;
QMap<CoverProvider*, QString> cover_providers_;
QMutex mutex_;

View File

@ -32,7 +32,6 @@
#include <QString>
#include <QUrl>
#include <QUrlQuery>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QJsonDocument>
@ -53,9 +52,8 @@
const char *DeezerCoverProvider::kApiUrl = "https://api.deezer.com";
const int DeezerCoverProvider::kLimit = 10;
DeezerCoverProvider::DeezerCoverProvider(Application *app, QObject *parent)
: JsonCoverProvider("Deezer", true, false, 2.0, true, true, app, parent),
network_(new NetworkAccessManager(this)) {}
DeezerCoverProvider::DeezerCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent)
: JsonCoverProvider("Deezer", true, false, 2.0, true, true, app, network, parent) {}
DeezerCoverProvider::~DeezerCoverProvider() {

View File

@ -40,7 +40,7 @@ class DeezerCoverProvider : public JsonCoverProvider {
Q_OBJECT
public:
explicit DeezerCoverProvider(Application *app, QObject *parent = nullptr);
explicit DeezerCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent = nullptr);
~DeezerCoverProvider() override;
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id) override;
@ -58,7 +58,6 @@ class DeezerCoverProvider : public JsonCoverProvider {
static const char *kApiUrl;
static const int kLimit;
NetworkAccessManager *network_;
QList<QNetworkReply*> replies_;
};

View File

@ -39,7 +39,6 @@
#include <QUrl>
#include <QUrlQuery>
#include <QTimer>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QJsonDocument>
@ -61,9 +60,8 @@ const char *DiscogsCoverProvider::kAccessKeyB64 = "dGh6ZnljUGJlZ1NEeXBuSFFxSVk="
const char *DiscogsCoverProvider::kSecretKeyB64 = "ZkFIcmlaSER4aHhRSlF2U3d0bm5ZVmdxeXFLWUl0UXI=";
const int DiscogsCoverProvider::kRequestsDelay = 1000;
DiscogsCoverProvider::DiscogsCoverProvider(Application *app, QObject *parent)
: JsonCoverProvider("Discogs", false, false, 0.0, false, false, app, parent),
network_(new NetworkAccessManager(this)),
DiscogsCoverProvider::DiscogsCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent)
: JsonCoverProvider("Discogs", false, false, 0.0, false, false, app, network, parent),
timer_flush_requests_(new QTimer(this)) {
timer_flush_requests_->setInterval(kRequestsDelay);

View File

@ -49,7 +49,7 @@ class DiscogsCoverProvider : public JsonCoverProvider {
Q_OBJECT
public:
explicit DiscogsCoverProvider(Application *app, QObject *parent = nullptr);
explicit DiscogsCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent = nullptr);
~DiscogsCoverProvider() override;
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id) override;
@ -99,7 +99,6 @@ class DiscogsCoverProvider : public JsonCoverProvider {
static const char *kSecretKeyB64;
static const int kRequestsDelay;
NetworkAccessManager *network_;
QTimer *timer_flush_requests_;
QQueue<std::shared_ptr<DiscogsCoverSearchContext>> queue_search_requests_;
QQueue<DiscogsCoverReleaseContext> queue_release_requests_;

View File

@ -28,11 +28,12 @@
#include <QJsonObject>
#include "core/application.h"
#include "core/networkaccessmanager.h"
#include "coverprovider.h"
#include "jsoncoverprovider.h"
JsonCoverProvider::JsonCoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool batch, const bool allow_missing_album, Application *app, QObject *parent)
: CoverProvider(name, enabled, authentication_required, quality, batch, allow_missing_album, app, parent) {}
JsonCoverProvider::JsonCoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool batch, const bool allow_missing_album, Application *app, NetworkAccessManager *network, QObject *parent)
: CoverProvider(name, enabled, authentication_required, quality, batch, allow_missing_album, app, network, parent) {}
QJsonObject JsonCoverProvider::ExtractJsonObj(const QByteArray &data) {

View File

@ -30,15 +30,16 @@
#include "coverprovider.h"
class Application;
class NetworkAccessManager;
class JsonCoverProvider : public CoverProvider {
Q_OBJECT
public:
explicit JsonCoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool batch, const bool allow_missing_album, Application *app, QObject *parent);
explicit JsonCoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool batch, const bool allow_missing_album, Application *app, NetworkAccessManager *network, QObject *parent);
protected:
QJsonObject ExtractJsonObj(const QByteArray &data);
};
#endif // JSONCOVERPROVIDER_H

View File

@ -31,7 +31,6 @@
#include <QString>
#include <QUrl>
#include <QUrlQuery>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QCryptographicHash>
@ -53,9 +52,8 @@ const char *LastFmCoverProvider::kUrl = "https://ws.audioscrobbler.com/2.0/";
const char *LastFmCoverProvider::kApiKey = "211990b4c96782c05d1536e7219eb56e";
const char *LastFmCoverProvider::kSecret = "80fd738f49596e9709b1bf9319c444a8";
LastFmCoverProvider::LastFmCoverProvider(Application *app, QObject *parent)
: JsonCoverProvider("Last.fm", true, false, 1.0, true, false, app, parent),
network_(new NetworkAccessManager(this)) {}
LastFmCoverProvider::LastFmCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent)
: JsonCoverProvider("Last.fm", true, false, 1.0, true, false, app, network, parent) {}
LastFmCoverProvider::~LastFmCoverProvider() {

View File

@ -39,7 +39,7 @@ class LastFmCoverProvider : public JsonCoverProvider {
Q_OBJECT
public:
explicit LastFmCoverProvider(Application *app, QObject *parent = nullptr);
explicit LastFmCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent = nullptr);
~LastFmCoverProvider() override;
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id) override;
@ -65,7 +65,6 @@ class LastFmCoverProvider : public JsonCoverProvider {
static const char *kApiKey;
static const char *kSecret;
NetworkAccessManager *network_;
QList<QNetworkReply*> replies_;
};

View File

@ -30,7 +30,6 @@
#include <QUrl>
#include <QUrlQuery>
#include <QTimer>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QJsonDocument>
@ -51,9 +50,8 @@ const char *MusicbrainzCoverProvider::kAlbumCoverUrl = "https://coverartarchive.
const int MusicbrainzCoverProvider::kLimit = 8;
const int MusicbrainzCoverProvider::kRequestsDelay = 1000;
MusicbrainzCoverProvider::MusicbrainzCoverProvider(Application *app, QObject *parent)
: JsonCoverProvider("MusicBrainz", true, false, 1.5, true, false, app, parent),
network_(new NetworkAccessManager(this)),
MusicbrainzCoverProvider::MusicbrainzCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent)
: JsonCoverProvider("MusicBrainz", true, false, 1.5, true, false, app, network, parent),
timer_flush_requests_(new QTimer(this)) {
timer_flush_requests_->setInterval(kRequestsDelay);

View File

@ -41,7 +41,7 @@ class MusicbrainzCoverProvider : public JsonCoverProvider {
Q_OBJECT
public:
explicit MusicbrainzCoverProvider(Application *app, QObject *parent = nullptr);
explicit MusicbrainzCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent = nullptr);
~MusicbrainzCoverProvider() override;
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id) override;
@ -68,7 +68,6 @@ class MusicbrainzCoverProvider : public JsonCoverProvider {
static const int kLimit;
static const int kRequestsDelay;
NetworkAccessManager *network_;
QTimer *timer_flush_requests_;
QQueue<SearchRequest> queue_search_requests_;
QList<QNetworkReply*> replies_;

View File

@ -26,7 +26,6 @@
#include <QUrl>
#include <QUrlQuery>
#include <QRegularExpression>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QJsonDocument>
@ -40,9 +39,8 @@
#include "jsoncoverprovider.h"
#include "musixmatchcoverprovider.h"
MusixmatchCoverProvider::MusixmatchCoverProvider(Application *app, QObject *parent)
: JsonCoverProvider("Musixmatch", true, false, 1.0, true, false, app, parent),
network_(new NetworkAccessManager(this)) {}
MusixmatchCoverProvider::MusixmatchCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent)
: JsonCoverProvider("Musixmatch", true, false, 1.0, true, false, app, network, parent) {}
MusixmatchCoverProvider::~MusixmatchCoverProvider() {

View File

@ -37,7 +37,7 @@ class MusixmatchCoverProvider : public JsonCoverProvider {
Q_OBJECT
public:
explicit MusixmatchCoverProvider(Application *app, QObject *parent = nullptr);
explicit MusixmatchCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent = nullptr);
~MusixmatchCoverProvider() override;
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id) override;
@ -50,7 +50,6 @@ class MusixmatchCoverProvider : public JsonCoverProvider {
void HandleSearchReply(QNetworkReply *reply, const int id, const QString &artist, const QString &album);
private:
NetworkAccessManager *network_;
QList<QNetworkReply*> replies_;
};

View File

@ -30,7 +30,6 @@
#include <QString>
#include <QUrl>
#include <QUrlQuery>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QJsonDocument>
@ -52,10 +51,9 @@
const int QobuzCoverProvider::kLimit = 10;
QobuzCoverProvider::QobuzCoverProvider(Application *app, QObject *parent)
: JsonCoverProvider("Qobuz", true, true, 2.0, true, true, app, parent),
service_(app->internet_services()->Service<QobuzService>()),
network_(new NetworkAccessManager(this)) {}
QobuzCoverProvider::QobuzCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent)
: JsonCoverProvider("Qobuz", true, true, 2.0, true, true, app, network, parent),
service_(app->internet_services()->Service<QobuzService>()) {}
QobuzCoverProvider::~QobuzCoverProvider() {

View File

@ -42,7 +42,7 @@ class QobuzCoverProvider : public JsonCoverProvider {
Q_OBJECT
public:
explicit QobuzCoverProvider(Application *app, QObject *parent = nullptr);
explicit QobuzCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent = nullptr);
~QobuzCoverProvider() override;
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id) override;
@ -65,7 +65,6 @@ class QobuzCoverProvider : public JsonCoverProvider {
static const int kLimit;
QobuzService *service_;
NetworkAccessManager *network_;
QList<QNetworkReply*> replies_;
};

View File

@ -30,7 +30,6 @@
#include <QUrl>
#include <QUrlQuery>
#include <QDateTime>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QSslError>
@ -63,9 +62,8 @@ const char *SpotifyCoverProvider::kClientSecretB64 = "N2ZlMDMxODk1NTBlNDE3ZGI1ZW
const char *SpotifyCoverProvider::kApiUrl = "https://api.spotify.com/v1";
const int SpotifyCoverProvider::kLimit = 10;
SpotifyCoverProvider::SpotifyCoverProvider(Application *app, QObject *parent)
: JsonCoverProvider("Spotify", true, true, 2.5, true, true, app, parent),
network_(new NetworkAccessManager(this)),
SpotifyCoverProvider::SpotifyCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent)
: JsonCoverProvider("Spotify", true, true, 2.5, true, true, app, network, parent),
server_(nullptr),
expires_in_(0),
login_time_(0) {

View File

@ -45,7 +45,7 @@ class SpotifyCoverProvider : public JsonCoverProvider {
Q_OBJECT
public:
explicit SpotifyCoverProvider(Application *app, QObject *parent = nullptr);
explicit SpotifyCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent = nullptr);
~SpotifyCoverProvider() override;
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id) override;
@ -81,7 +81,6 @@ class SpotifyCoverProvider : public JsonCoverProvider {
static const char *kApiUrl;
static const int kLimit;
NetworkAccessManager *network_;
LocalRedirectServer *server_;
QStringList login_errors_;
QString code_verifier_;

View File

@ -29,7 +29,6 @@
#include <QString>
#include <QUrl>
#include <QUrlQuery>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QJsonDocument>
@ -50,10 +49,9 @@
const int TidalCoverProvider::kLimit = 10;
TidalCoverProvider::TidalCoverProvider(Application *app, QObject *parent)
: JsonCoverProvider("Tidal", true, true, 2.5, true, true, app, parent),
service_(app->internet_services()->Service<TidalService>()),
network_(new NetworkAccessManager(this)) {}
TidalCoverProvider::TidalCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent)
: JsonCoverProvider("Tidal", true, true, 2.5, true, true, app, network, parent),
service_(app->internet_services()->Service<TidalService>()) {}
TidalCoverProvider::~TidalCoverProvider() {

View File

@ -43,7 +43,7 @@ class TidalCoverProvider : public JsonCoverProvider {
Q_OBJECT
public:
explicit TidalCoverProvider(Application *app, QObject *parent = nullptr);
explicit TidalCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent = nullptr);
~TidalCoverProvider() override;
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id) override;
@ -63,7 +63,6 @@ class TidalCoverProvider : public JsonCoverProvider {
static const int kLimit;
TidalService *service_;
NetworkAccessManager *network_;
QList<QNetworkReply*> replies_;
};

View File

@ -27,7 +27,6 @@
#include <QString>
#include <QUrl>
#include <QUrlQuery>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QJsonObject>
@ -47,7 +46,7 @@ const char *AuddLyricsProvider::kUrlSearch = "https://api.audd.io/findLyrics/";
const char *AuddLyricsProvider::kAPITokenB64 = "ZjA0NjQ4YjgyNDM3ZTc1MjY3YjJlZDI5ZDBlMzQxZjk=";
const int AuddLyricsProvider::kMaxLength = 6000;
AuddLyricsProvider::AuddLyricsProvider(QObject *parent) : JsonLyricsProvider("AudD", true, false, parent), network_(new NetworkAccessManager(this)) {}
AuddLyricsProvider::AuddLyricsProvider(NetworkAccessManager *network, QObject *parent) : JsonLyricsProvider("AudD", true, false, network, parent) {}
AuddLyricsProvider::~AuddLyricsProvider() {

View File

@ -39,7 +39,7 @@ class AuddLyricsProvider : public JsonLyricsProvider {
Q_OBJECT
public:
explicit AuddLyricsProvider(QObject *parent = nullptr);
explicit AuddLyricsProvider(NetworkAccessManager *network, QObject *parent = nullptr);
~AuddLyricsProvider() override;
bool StartSearch(const QString &artist, const QString &album, const QString &title, quint64 id) override;
@ -56,7 +56,6 @@ class AuddLyricsProvider : public JsonLyricsProvider {
static const char *kUrlSearch;
static const char *kAPITokenB64;
static const int kMaxLength;
NetworkAccessManager *network_;
QList<QNetworkReply*> replies_;
};

View File

@ -27,7 +27,6 @@
#include <QString>
#include <QUrl>
#include <QUrlQuery>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QXmlStreamReader>
@ -41,7 +40,7 @@
const char *ChartLyricsProvider::kUrlSearch = "http://api.chartlyrics.com/apiv1.asmx/SearchLyricDirect";
ChartLyricsProvider::ChartLyricsProvider(QObject *parent) : LyricsProvider("ChartLyrics", false, false, parent), network_(new NetworkAccessManager(this)) {}
ChartLyricsProvider::ChartLyricsProvider(NetworkAccessManager *network, QObject *parent) : LyricsProvider("ChartLyrics", false, false, network, parent) {}
ChartLyricsProvider::~ChartLyricsProvider() {

View File

@ -37,7 +37,7 @@ class ChartLyricsProvider : public LyricsProvider {
Q_OBJECT
public:
explicit ChartLyricsProvider(QObject *parent = nullptr);
explicit ChartLyricsProvider(NetworkAccessManager *network, QObject *parent = nullptr);
~ChartLyricsProvider() override;
bool StartSearch(const QString &artist, const QString &album, const QString &title, const quint64 id) override;
@ -51,8 +51,6 @@ class ChartLyricsProvider : public LyricsProvider {
private:
static const char *kUrlSearch;
NetworkAccessManager *network_;
QList<QNetworkReply*> replies_;
};

View File

@ -29,7 +29,6 @@
#include <QString>
#include <QUrl>
#include <QUrlQuery>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QSslError>
@ -62,7 +61,7 @@ const char *GeniusLyricsProvider::kUrlSearch = "https://api.genius.com/search/";
const char *GeniusLyricsProvider::kClientIDB64 = "RUNTNXU4U1VyMU1KUU5hdTZySEZteUxXY2hkanFiY3lfc2JjdXBpNG5WMU9SNUg4dTBZelEtZTZCdFg2dl91SQ==";
const char *GeniusLyricsProvider::kClientSecretB64 = "VE9pMU9vUjNtTXZ3eFR3YVN0QVRyUjVoUlhVWDI1Ylp5X240eEt1M0ZkYlNwRG5JUnd0LXFFbHdGZkZkRWY2VzJ1S011UnQzM3c2Y3hqY0tVZ3NGN2c=";
GeniusLyricsProvider::GeniusLyricsProvider(QObject *parent) : JsonLyricsProvider("Genius", true, true, parent), network_(new NetworkAccessManager(this)), server_(nullptr) {
GeniusLyricsProvider::GeniusLyricsProvider(NetworkAccessManager *network, QObject *parent) : JsonLyricsProvider("Genius", true, true, network, parent), server_(nullptr) {
QSettings s;
s.beginGroup(kSettingsGroup);

View File

@ -46,7 +46,7 @@ class GeniusLyricsProvider : public JsonLyricsProvider {
Q_OBJECT
public:
explicit GeniusLyricsProvider(QObject *parent = nullptr);
explicit GeniusLyricsProvider(NetworkAccessManager *network, QObject *parent = nullptr);
~GeniusLyricsProvider() override;
bool IsAuthenticated() const override { return !access_token_.isEmpty(); }
@ -95,7 +95,6 @@ class GeniusLyricsProvider : public JsonLyricsProvider {
static const char *kUrlSearch;
private:
NetworkAccessManager *network_;
LocalRedirectServer *server_;
QString code_verifier_;
QString code_challenge_;

View File

@ -27,10 +27,11 @@
#include <QJsonDocument>
#include <QJsonObject>
#include "core/networkaccessmanager.h"
#include "lyricsprovider.h"
#include "jsonlyricsprovider.h"
JsonLyricsProvider::JsonLyricsProvider(const QString &name, const bool enabled, const bool authentication_required, QObject *parent) : LyricsProvider(name, enabled, authentication_required, parent) {}
JsonLyricsProvider::JsonLyricsProvider(const QString &name, const bool enabled, const bool authentication_required, NetworkAccessManager *network, QObject *parent) : LyricsProvider(name, enabled, authentication_required, network, parent) {}
QByteArray JsonLyricsProvider::ExtractData(QNetworkReply *reply) {

View File

@ -31,14 +31,16 @@
#include "lyricsprovider.h"
class NetworkAccessManager;
class QNetworkReply;
class JsonLyricsProvider : public LyricsProvider {
Q_OBJECT
public:
explicit JsonLyricsProvider(const QString &name, const bool enabled = true, const bool authentication_required = false, QObject *parent = nullptr);
explicit JsonLyricsProvider(const QString &name, const bool enabled, const bool authentication_required, NetworkAccessManager *network, QObject *parent = nullptr);
protected:
QByteArray ExtractData(QNetworkReply *reply);
QJsonObject ExtractJsonObj(const QByteArray &data);
QJsonObject ExtractJsonObj(QNetworkReply *reply);

View File

@ -27,7 +27,6 @@
#include <QString>
#include <QUrl>
#include <QUrlQuery>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QXmlStreamReader>
@ -42,7 +41,7 @@
const char *LoloLyricsProvider::kUrlSearch = "http://api.lololyrics.com/0.5/getLyric";
LoloLyricsProvider::LoloLyricsProvider(QObject *parent) : LyricsProvider("LoloLyrics", true, false, parent), network_(new NetworkAccessManager(this)) {}
LoloLyricsProvider::LoloLyricsProvider(NetworkAccessManager *network, QObject *parent) : LyricsProvider("LoloLyrics", true, false, network, parent) {}
LoloLyricsProvider::~LoloLyricsProvider() {

View File

@ -37,7 +37,7 @@ class LoloLyricsProvider : public LyricsProvider {
Q_OBJECT
public:
explicit LoloLyricsProvider(QObject *parent = nullptr);
explicit LoloLyricsProvider(NetworkAccessManager *network, QObject *parent = nullptr);
~LoloLyricsProvider() override;
bool StartSearch(const QString &artist, const QString &album, const QString &title, const quint64 id) override;
@ -51,7 +51,6 @@ class LoloLyricsProvider : public LyricsProvider {
private:
static const char *kUrlSearch;
NetworkAccessManager *network_;
QList<QNetworkReply*> replies_;
};

View File

@ -22,7 +22,8 @@
#include <QObject>
#include <QString>
#include "core/networkaccessmanager.h"
#include "lyricsprovider.h"
LyricsProvider::LyricsProvider(const QString &name, const bool enabled, const bool authentication_required, QObject *parent)
: QObject(parent), name_(name), enabled_(enabled), order_(0), authentication_required_(authentication_required) {}
LyricsProvider::LyricsProvider(const QString &name, const bool enabled, const bool authentication_required, NetworkAccessManager *network, QObject *parent)
: QObject(parent), network_(network), name_(name), enabled_(enabled), order_(0), authentication_required_(authentication_required) {}

View File

@ -31,11 +31,13 @@
#include "lyricsfetcher.h"
class NetworkAccessManager;
class LyricsProvider : public QObject {
Q_OBJECT
public:
explicit LyricsProvider(const QString &name, const bool enabled, const bool authentication_required, QObject *parent);
explicit LyricsProvider(const QString &name, const bool enabled, const bool authentication_required, NetworkAccessManager *network, QObject *parent);
typedef QPair<QString, QString> Param;
typedef QList<Param> ParamList;
@ -62,7 +64,8 @@ class LyricsProvider : public QObject {
void AuthenticationFailure(QStringList);
void SearchFinished(quint64 id, LyricsSearchResults results);
private:
protected:
NetworkAccessManager *network_;
QString name_;
bool enabled_;
int order_;

View File

@ -31,6 +31,8 @@
#include <QtDebug>
#include "core/logging.h"
#include "core/networkaccessmanager.h"
#include "lyricsprovider.h"
#include "lyricsproviders.h"
@ -38,7 +40,7 @@
int LyricsProviders::NextOrderId = 0;
LyricsProviders::LyricsProviders(QObject *parent) : QObject(parent) {}
LyricsProviders::LyricsProviders(QObject *parent) : QObject(parent), network_(new NetworkAccessManager(this)) {}
LyricsProviders::~LyricsProviders() {

View File

@ -30,6 +30,7 @@
#include <QString>
#include <QAtomicInt>
class NetworkAccessManager;
class LyricsProvider;
class LyricsProviders : public QObject {
@ -48,6 +49,8 @@ class LyricsProviders : public QObject {
bool HasAnyProviders() const { return !lyrics_providers_.isEmpty(); }
int NextId();
NetworkAccessManager *network() const { return network_; }
private slots:
void ProviderDestroyed();
@ -56,6 +59,8 @@ class LyricsProviders : public QObject {
static int NextOrderId;
NetworkAccessManager *network_;
QMap<LyricsProvider*, QString> lyrics_providers_;
QList<LyricsProvider*> ordered_providers_;
QMutex mutex_;

View File

@ -26,7 +26,6 @@
#include <QUrl>
#include <QUrlQuery>
#include <QRegularExpression>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QJsonObject>
@ -40,7 +39,7 @@
#include "lyricsprovider.h"
#include "musixmatchlyricsprovider.h"
MusixmatchLyricsProvider::MusixmatchLyricsProvider(QObject *parent) : JsonLyricsProvider("Musixmatch", true, false, parent), network_(new NetworkAccessManager(this)) {}
MusixmatchLyricsProvider::MusixmatchLyricsProvider(NetworkAccessManager *network, QObject *parent) : JsonLyricsProvider("Musixmatch", true, false, network, parent) {}
MusixmatchLyricsProvider::~MusixmatchLyricsProvider() {

View File

@ -38,7 +38,7 @@ class MusixmatchLyricsProvider : public JsonLyricsProvider {
Q_OBJECT
public:
explicit MusixmatchLyricsProvider(QObject *parent = nullptr);
explicit MusixmatchLyricsProvider(NetworkAccessManager *network, QObject *parent = nullptr);
~MusixmatchLyricsProvider() override;
bool StartSearch(const QString &artist, const QString &album, const QString &title, const quint64 id) override;
@ -51,7 +51,6 @@ class MusixmatchLyricsProvider : public JsonLyricsProvider {
void HandleSearchReply(QNetworkReply *reply, const quint64 id, const QString &artist, const QString &album, const QString &title);
private:
NetworkAccessManager *network_;
QList<QNetworkReply*> replies_;
};

View File

@ -23,7 +23,6 @@
#include <QVariant>
#include <QString>
#include <QUrl>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QJsonObject>
@ -39,7 +38,7 @@
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(NetworkAccessManager *network, QObject *parent) : JsonLyricsProvider("Lyrics.ovh", true, false, network, parent) {}
OVHLyricsProvider::~OVHLyricsProvider() {

View File

@ -37,7 +37,7 @@ class OVHLyricsProvider : public JsonLyricsProvider {
Q_OBJECT
public:
explicit OVHLyricsProvider(QObject *parent = nullptr);
explicit OVHLyricsProvider(NetworkAccessManager *network, QObject *parent = nullptr);
~OVHLyricsProvider() override;
bool StartSearch(const QString &artist, const QString &album, const QString &title, const quint64 id) override;
@ -51,7 +51,6 @@ class OVHLyricsProvider : public JsonLyricsProvider {
private:
static const char *kUrlSearch;
NetworkAccessManager *network_;
QList<QNetworkReply*> replies_;
};