Add Json cover provider class

This commit is contained in:
Jonas Kvinge 2020-05-10 12:49:11 +02:00
parent dfecd0cd12
commit 623147dea7
20 changed files with 148 additions and 240 deletions

View File

@ -182,6 +182,7 @@ set(SOURCES
covermanager/coverexportrunnable.cpp
covermanager/currentalbumcoverloader.cpp
covermanager/coverfromurldialog.cpp
covermanager/jsoncoverprovider.cpp
covermanager/lastfmcoverprovider.cpp
covermanager/musicbrainzcoverprovider.cpp
covermanager/discogscoverprovider.cpp
@ -377,6 +378,7 @@ set(HEADERS
covermanager/coverexportrunnable.h
covermanager/currentalbumcoverloader.h
covermanager/coverfromurldialog.h
covermanager/jsoncoverprovider.h
covermanager/lastfmcoverprovider.h
covermanager/musicbrainzcoverprovider.h
covermanager/discogscoverprovider.h

View File

@ -26,6 +26,7 @@
#include <QtGlobal>
#include <QObject>
#include <QVariant>
#include <QString>
#include <QStringList>
@ -63,6 +64,8 @@ class CoverProvider : public QObject {
virtual bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id) = 0;
virtual void CancelSearch(const int id) { Q_UNUSED(id); }
virtual void Error(const QString &error, const QVariant &debug = QVariant()) = 0;
signals:
void AuthenticationComplete(bool, QStringList = QStringList());
void AuthenticationSuccess();

View File

@ -45,13 +45,13 @@
#include "core/logging.h"
#include "core/song.h"
#include "albumcoverfetcher.h"
#include "coverprovider.h"
#include "jsoncoverprovider.h"
#include "deezercoverprovider.h"
const char *DeezerCoverProvider::kApiUrl = "https://api.deezer.com";
const int DeezerCoverProvider::kLimit = 10;
DeezerCoverProvider::DeezerCoverProvider(Application *app, QObject *parent): CoverProvider("Deezer", true, false, 2.0, true, true, app, parent), network_(new NetworkAccessManager(this)) {}
DeezerCoverProvider::DeezerCoverProvider(Application *app, QObject *parent): JsonCoverProvider("Deezer", true, false, 2.0, true, true, app, parent), network_(new NetworkAccessManager(this)) {}
bool DeezerCoverProvider::StartSearch(const QString &artist, const QString &album, const QString &title, const int id) {
@ -139,36 +139,6 @@ QByteArray DeezerCoverProvider::GetReplyData(QNetworkReply *reply) {
return data;
}
QJsonObject DeezerCoverProvider::ExtractJsonObj(const QByteArray &data) {
QJsonParseError error;
QJsonDocument json_doc = QJsonDocument::fromJson(data, &error);
if (error.error != QJsonParseError::NoError) {
Error("Reply from server missing Json data.", data);
return QJsonObject();
}
if (json_doc.isEmpty()) {
Error("Received empty Json document.", json_doc);
return QJsonObject();
}
if (!json_doc.isObject()) {
Error("Json document is not an object.", json_doc);
return QJsonObject();
}
QJsonObject json_obj = json_doc.object();
if (json_obj.isEmpty()) {
Error("Received empty Json object.", json_doc);
return QJsonObject();
}
return json_obj;
}
QJsonValue DeezerCoverProvider::ExtractData(const QByteArray &data) {

View File

@ -29,13 +29,13 @@
#include <QJsonValue>
#include <QJsonObject>
#include "coverprovider.h"
#include "jsoncoverprovider.h"
class QNetworkAccessManager;
class QNetworkReply;
class Application;
class DeezerCoverProvider : public CoverProvider {
class DeezerCoverProvider : public JsonCoverProvider {
Q_OBJECT
public:
@ -48,7 +48,6 @@ class DeezerCoverProvider : public CoverProvider {
private:
QByteArray GetReplyData(QNetworkReply *reply);
QJsonObject ExtractJsonObj(const QByteArray &data);
QJsonValue ExtractData(const QByteArray &data);
void Error(const QString &error, const QVariant &debug = QVariant());

View File

@ -50,15 +50,15 @@
#include "core/logging.h"
#include "core/network.h"
#include "core/utilities.h"
#include "coverprovider.h"
#include "albumcoverfetcher.h"
#include "jsoncoverprovider.h"
#include "discogscoverprovider.h"
const char *DiscogsCoverProvider::kUrlSearch = "https://api.discogs.com/database/search";
const char *DiscogsCoverProvider::kAccessKeyB64 = "dGh6ZnljUGJlZ1NEeXBuSFFxSVk=";
const char *DiscogsCoverProvider::kSecretKeyB64 = "ZkFIcmlaSER4aHhRSlF2U3d0bm5ZVmdxeXFLWUl0UXI=";
DiscogsCoverProvider::DiscogsCoverProvider(Application *app, QObject *parent) : CoverProvider("Discogs", false, false, 0.0, false, false, app, parent), network_(new NetworkAccessManager(this)) {}
DiscogsCoverProvider::DiscogsCoverProvider(Application *app, QObject *parent) : JsonCoverProvider("Discogs", false, false, 0.0, false, false, app, parent), network_(new NetworkAccessManager(this)) {}
DiscogsCoverProvider::~DiscogsCoverProvider() {
requests_search_.clear();
@ -171,33 +171,6 @@ QByteArray DiscogsCoverProvider::GetReplyData(QNetworkReply *reply) {
}
QJsonObject DiscogsCoverProvider::ExtractJsonObj(const QByteArray &data) {
QJsonParseError error;
QJsonDocument json_doc = QJsonDocument::fromJson(data, &error);
if (error.error != QJsonParseError::NoError) {
Error("Reply from server missing Json data.", data);
return QJsonObject();
}
if (json_doc.isEmpty()) {
Error("Received empty Json document.", json_doc);
return QJsonObject();
}
if (!json_doc.isObject()) {
Error("Json document is not an object.", json_doc);
return QJsonObject();
}
QJsonObject json_obj = json_doc.object();
if (json_obj.isEmpty()) {
Error("Received empty Json object.", json_doc);
return QJsonObject();
}
return json_obj;
}
void DiscogsCoverProvider::HandleSearchReply(QNetworkReply *reply, const int id) {
reply->deleteLater();

View File

@ -34,14 +34,14 @@
#include <QString>
#include <QJsonObject>
#include "coverprovider.h"
#include "jsoncoverprovider.h"
#include "albumcoverfetcher.h"
class QNetworkAccessManager;
class QNetworkReply;
class Application;
class DiscogsCoverProvider : public CoverProvider {
class DiscogsCoverProvider : public JsonCoverProvider {
Q_OBJECT
public:
@ -77,7 +77,6 @@ class DiscogsCoverProvider : public CoverProvider {
QNetworkReply *CreateRequest(QUrl url, const ParamList &params_provided = ParamList());
QByteArray GetReplyData(QNetworkReply *reply);
QJsonObject ExtractJsonObj(const QByteArray &data);
void StartRelease(std::shared_ptr<DiscogsCoverSearchContext> search, const quint64 release_id, const QUrl &url);
void EndSearch(std::shared_ptr<DiscogsCoverSearchContext> search, const DiscogsCoverReleaseContext &release = DiscogsCoverReleaseContext());
void Error(const QString &error, const QVariant &debug = QVariant());

View File

@ -0,0 +1,64 @@
/*
* Strawberry Music Player
* Copyright 2018, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Strawberry is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "config.h"
#include <QtGlobal>
#include <QObject>
#include <QByteArray>
#include <QString>
#include <QJsonDocument>
#include <QJsonValue>
#include <QJsonObject>
#include "core/application.h"
#include "coverprovider.h"
#include "jsoncoverprovider.h"
JsonCoverProvider::JsonCoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool fetchall, const bool allow_missing_album, Application *app, QObject *parent) : CoverProvider(name, enabled, authentication_required, quality, fetchall, allow_missing_album, app, parent) {}
QJsonObject JsonCoverProvider::ExtractJsonObj(const QByteArray &data) {
QJsonParseError json_error;
QJsonDocument json_doc = QJsonDocument::fromJson(data, &json_error);
if (json_error.error != QJsonParseError::NoError) {
Error(QString("Failed to parse json data: %1").arg(json_error.errorString()));
return QJsonObject();
}
if (json_doc.isEmpty()) {
Error("Received empty Json document.", data);
return QJsonObject();
}
if (!json_doc.isObject()) {
Error("Json document is not an object.", json_doc);
return QJsonObject();
}
QJsonObject json_obj = json_doc.object();
if (json_obj.isEmpty()) {
Error("Received empty Json object.", json_doc);
return QJsonObject();
}
return json_obj;
}

View File

@ -0,0 +1,46 @@
/*
* Strawberry Music Player
* Copyright 2018, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Strawberry is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef JSONCOVERPROVIDER_H
#define JSONCOVERPROVIDER_H
#include "config.h"
#include <QObject>
#include <QByteArray>
#include <QString>
#include <QJsonObject>
#include "coverprovider.h"
class QNetworkAccessManager;
class QNetworkReply;
class Application;
class JsonCoverProvider : public CoverProvider {
Q_OBJECT
public:
explicit JsonCoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool fetchall, const bool allow_missing_album, Application *app, QObject *parent);
QJsonObject ExtractJsonObj(const QByteArray &data);
};
#endif // JSONCOVERPROVIDER_H

View File

@ -45,7 +45,7 @@
#include "core/network.h"
#include "core/logging.h"
#include "coverprovider.h"
#include "jsoncoverprovider.h"
#include "albumcoverfetcher.h"
#include "lastfmcoverprovider.h"
@ -53,7 +53,7 @@ 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) : CoverProvider("Last.fm", true, false, 1.0, true, false, app, parent), network_(new NetworkAccessManager(this)) {}
LastFmCoverProvider::LastFmCoverProvider(Application *app, QObject *parent) : JsonCoverProvider("Last.fm", true, false, 1.0, true, false, app, parent), network_(new NetworkAccessManager(this)) {}
bool LastFmCoverProvider::StartSearch(const QString &artist, const QString &album, const QString &title, const int id) {
@ -303,33 +303,6 @@ QByteArray LastFmCoverProvider::GetReplyData(QNetworkReply *reply) {
}
QJsonObject LastFmCoverProvider::ExtractJsonObj(const QByteArray &data) {
QJsonParseError error;
QJsonDocument json_doc = QJsonDocument::fromJson(data, &error);
if (error.error != QJsonParseError::NoError) {
Error("Reply from server missing Json data.", data);
return QJsonObject();
}
if (json_doc.isEmpty()) {
Error("Received empty Json document.", json_doc);
return QJsonObject();
}
if (!json_doc.isObject()) {
Error("Json document is not an object.", json_doc);
return QJsonObject();
}
QJsonObject json_obj = json_doc.object();
if (json_obj.isEmpty()) {
Error("Received empty Json object.", json_doc);
return QJsonObject();
}
return json_obj;
}
void LastFmCoverProvider::Error(const QString &error, const QVariant &debug) {
qLog(Error) << "LastFm:" << error;

View File

@ -28,13 +28,13 @@
#include <QString>
#include <QJsonObject>
#include "coverprovider.h"
#include "jsoncoverprovider.h"
class QNetworkAccessManager;
class QNetworkReply;
class Application;
class LastFmCoverProvider : public CoverProvider {
class LastFmCoverProvider : public JsonCoverProvider {
Q_OBJECT
public:
@ -54,7 +54,6 @@ class LastFmCoverProvider : public CoverProvider {
};
QByteArray GetReplyData(QNetworkReply *reply);
QJsonObject ExtractJsonObj(const QByteArray &data);
LastFmImageSize ImageSizeFromString(const QString &size);
void Error(const QString &error, const QVariant &debug = QVariant());

View File

@ -41,14 +41,14 @@
#include "core/network.h"
#include "core/logging.h"
#include "albumcoverfetcher.h"
#include "coverprovider.h"
#include "jsoncoverprovider.h"
#include "musicbrainzcoverprovider.h"
const char *MusicbrainzCoverProvider::kReleaseSearchUrl = "https://musicbrainz.org/ws/2/release/";
const char *MusicbrainzCoverProvider::kAlbumCoverUrl = "https://coverartarchive.org/release/%1/front";
const int MusicbrainzCoverProvider::kLimit = 8;
MusicbrainzCoverProvider::MusicbrainzCoverProvider(Application *app, QObject *parent): CoverProvider("MusicBrainz", true, false, 1.5, true, false, app, parent), network_(new NetworkAccessManager(this)) {}
MusicbrainzCoverProvider::MusicbrainzCoverProvider(Application *app, QObject *parent): JsonCoverProvider("MusicBrainz", true, false, 1.5, true, false, app, parent), network_(new NetworkAccessManager(this)) {}
bool MusicbrainzCoverProvider::StartSearch(const QString &artist, const QString &album, const QString &title, const int id) {
@ -218,33 +218,6 @@ QByteArray MusicbrainzCoverProvider::GetReplyData(QNetworkReply *reply) {
}
QJsonObject MusicbrainzCoverProvider::ExtractJsonObj(const QByteArray &data) {
QJsonParseError error;
QJsonDocument json_doc = QJsonDocument::fromJson(data, &error);
if (error.error != QJsonParseError::NoError) {
Error("Reply from server is missing Json data.", data);
return QJsonObject();
}
if (json_doc.isEmpty()) {
Error("Received empty Json document.", json_doc);
return QJsonObject();
}
if (!json_doc.isObject()) {
Error("Json document is not an object.", json_doc);
return QJsonObject();
}
QJsonObject json_obj = json_doc.object();
if (json_obj.isEmpty()) {
Error("Received empty Json object.", json_doc);
return QJsonObject();
}
return json_obj;
}
void MusicbrainzCoverProvider::Error(const QString &error, const QVariant &debug) {
qLog(Error) << "Musicbrainz:" << error;

View File

@ -28,13 +28,13 @@
#include <QString>
#include <QJsonObject>
#include "coverprovider.h"
#include "jsoncoverprovider.h"
class QNetworkAccessManager;
class QNetworkReply;
class Application;
class MusicbrainzCoverProvider : public CoverProvider {
class MusicbrainzCoverProvider : public JsonCoverProvider {
Q_OBJECT
public:
explicit MusicbrainzCoverProvider(Application *app, QObject *parent = nullptr);
@ -46,7 +46,6 @@ class MusicbrainzCoverProvider : public CoverProvider {
private:
QByteArray GetReplyData(QNetworkReply *reply);
QJsonObject ExtractJsonObj(const QByteArray &data);
void Error(const QString &error, const QVariant &debug = QVariant());
private:

View File

@ -37,10 +37,10 @@
#include "core/logging.h"
#include "core/network.h"
#include "albumcoverfetcher.h"
#include "coverprovider.h"
#include "jsoncoverprovider.h"
#include "musixmatchcoverprovider.h"
MusixmatchCoverProvider::MusixmatchCoverProvider(Application *app, QObject *parent): CoverProvider("Musixmatch", true, false, 1.0, true, false, app, parent), network_(new NetworkAccessManager(this)) {}
MusixmatchCoverProvider::MusixmatchCoverProvider(Application *app, QObject *parent): JsonCoverProvider("Musixmatch", true, false, 1.0, true, false, app, parent), network_(new NetworkAccessManager(this)) {}
bool MusixmatchCoverProvider::StartSearch(const QString &artist, const QString &album, const QString &title, const int id) {

View File

@ -27,12 +27,12 @@
#include <QVariant>
#include <QString>
#include "coverprovider.h"
#include "jsoncoverprovider.h"
class QNetworkAccessManager;
class QNetworkReply;
class MusixmatchCoverProvider : public CoverProvider {
class MusixmatchCoverProvider : public JsonCoverProvider {
Q_OBJECT
public:

View File

@ -44,13 +44,14 @@
#include "core/logging.h"
#include "core/song.h"
#include "albumcoverfetcher.h"
#include "jsoncoverprovider.h"
#include "qobuzcoverprovider.h"
const char *QobuzCoverProvider::kApiUrl = "https://www.qobuz.com/api.json/0.2";
const char *QobuzCoverProvider::kAppID = "OTQyODUyNTY3";
const int QobuzCoverProvider::kLimit = 10;
QobuzCoverProvider::QobuzCoverProvider(Application *app, QObject *parent) : CoverProvider("Qobuz", true, false, 2.0, true, true, app, parent), network_(new NetworkAccessManager(this)) {}
QobuzCoverProvider::QobuzCoverProvider(Application *app, QObject *parent) : JsonCoverProvider("Qobuz", true, false, 2.0, true, true, app, parent), network_(new NetworkAccessManager(this)) {}
bool QobuzCoverProvider::StartSearch(const QString &artist, const QString &album, const QString &title, const int id) {
@ -139,36 +140,6 @@ QByteArray QobuzCoverProvider::GetReplyData(QNetworkReply *reply) {
}
QJsonObject QobuzCoverProvider::ExtractJsonObj(const QByteArray &data) {
QJsonParseError json_error;
QJsonDocument json_doc = QJsonDocument::fromJson(data, &json_error);
if (json_error.error != QJsonParseError::NoError) {
Error("Reply from server missing Json data.", data);
return QJsonObject();
}
if (json_doc.isEmpty()) {
Error("Received empty Json document.", data);
return QJsonObject();
}
if (!json_doc.isObject()) {
Error("Json document is not an object.", json_doc);
return QJsonObject();
}
QJsonObject json_obj = json_doc.object();
if (json_obj.isEmpty()) {
Error("Received empty Json object.", json_doc);
return QJsonObject();
}
return json_obj;
}
void QobuzCoverProvider::HandleSearchReply(QNetworkReply *reply, const int id) {
reply->deleteLater();

View File

@ -28,13 +28,13 @@
#include <QString>
#include <QJsonObject>
#include "coverprovider.h"
#include "jsoncoverprovider.h"
class QNetworkAccessManager;
class QNetworkReply;
class Application;
class QobuzCoverProvider : public CoverProvider {
class QobuzCoverProvider : public JsonCoverProvider {
Q_OBJECT
public:
@ -47,7 +47,6 @@ class QobuzCoverProvider : public CoverProvider {
private:
QByteArray GetReplyData(QNetworkReply *reply);
QJsonObject ExtractJsonObj(const QByteArray &data);
void Error(const QString &error, const QVariant &debug = QVariant());
private:

View File

@ -49,7 +49,7 @@
#include "core/utilities.h"
#include "internet/localredirectserver.h"
#include "albumcoverfetcher.h"
#include "coverprovider.h"
#include "jsoncoverprovider.h"
#include "spotifycoverprovider.h"
const char *SpotifyCoverProvider::kSettingsGroup = "Spotify";
@ -61,7 +61,7 @@ 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) : CoverProvider("Spotify", true, true, 2.5, true, true, app, parent), network_(new NetworkAccessManager(this)), server_(nullptr) {
SpotifyCoverProvider::SpotifyCoverProvider(Application *app, QObject *parent) : JsonCoverProvider("Spotify", true, true, 2.5, true, true, app, parent), network_(new NetworkAccessManager(this)), server_(nullptr) {
QSettings s;
s.beginGroup(kSettingsGroup);
@ -266,7 +266,7 @@ void SpotifyCoverProvider::AccessTokenRequestFinished(QNetworkReply *reply) {
QJsonDocument json_doc = QJsonDocument::fromJson(data, &json_error);
if (json_error.error != QJsonParseError::NoError) {
AuthError("Authentication reply from server missing Json data.");
Error(QString("Failed to parse Json data in authentication reply: %1").arg(json_error.errorString()));
return;
}
@ -394,36 +394,6 @@ QByteArray SpotifyCoverProvider::GetReplyData(QNetworkReply *reply) {
}
QJsonObject SpotifyCoverProvider::ExtractJsonObj(const QByteArray &data) {
QJsonParseError json_error;
QJsonDocument json_doc = QJsonDocument::fromJson(data, &json_error);
if (json_error.error != QJsonParseError::NoError) {
Error(QString("Failed to parse json data: %1").arg(json_error.errorString()));
return QJsonObject();
}
if (json_doc.isEmpty()) {
Error("Received empty Json document.", data);
return QJsonObject();
}
if (!json_doc.isObject()) {
Error("Json document is not an object.", json_doc);
return QJsonObject();
}
QJsonObject json_obj = json_doc.object();
if (json_obj.isEmpty()) {
Error("Received empty Json object.", json_doc);
return QJsonObject();
}
return json_obj;
}
void SpotifyCoverProvider::HandleSearchReply(QNetworkReply *reply, const int id, const QString &extract) {
reply->deleteLater();

View File

@ -33,14 +33,14 @@
#include <QJsonValue>
#include <QJsonObject>
#include "coverprovider.h"
#include "jsoncoverprovider.h"
class QNetworkAccessManager;
class QNetworkReply;
class Application;
class LocalRedirectServer;
class SpotifyCoverProvider : public CoverProvider {
class SpotifyCoverProvider : public JsonCoverProvider {
Q_OBJECT
public:
@ -61,7 +61,6 @@ class SpotifyCoverProvider : public CoverProvider {
private:
void RequestAccessToken(const QUrl &url, const QUrl &redirect_url);
QByteArray GetReplyData(QNetworkReply *reply);
QJsonObject ExtractJsonObj(const QByteArray &data);
void AuthError(const QString &error = QString(), const QVariant &debug = QVariant());
void Error(const QString &error, const QVariant &debug = QVariant());

View File

@ -45,7 +45,7 @@
#include "internet/internetservices.h"
#include "tidal/tidalservice.h"
#include "albumcoverfetcher.h"
#include "coverprovider.h"
#include "jsoncoverprovider.h"
#include "tidalcoverprovider.h"
const char *TidalCoverProvider::kApiUrl = "https://api.tidalhifi.com/v1";
@ -53,7 +53,7 @@ const char *TidalCoverProvider::kResourcesUrl = "https://resources.tidal.com";
const int TidalCoverProvider::kLimit = 10;
TidalCoverProvider::TidalCoverProvider(Application *app, QObject *parent) :
CoverProvider("Tidal", true, true, 2.5, true, true, app, parent),
JsonCoverProvider("Tidal", true, true, 2.5, true, true, app, parent),
service_(app->internet_services()->Service<TidalService>()),
network_(new NetworkAccessManager(this)) {
@ -152,36 +152,6 @@ QByteArray TidalCoverProvider::GetReplyData(QNetworkReply *reply) {
}
QJsonObject TidalCoverProvider::ExtractJsonObj(const QByteArray &data) {
QJsonParseError json_error;
QJsonDocument json_doc = QJsonDocument::fromJson(data, &json_error);
if (json_error.error != QJsonParseError::NoError) {
Error("Reply from server missing Json data.", data);
return QJsonObject();
}
if (json_doc.isEmpty()) {
Error("Received empty Json document.", data);
return QJsonObject();
}
if (!json_doc.isObject()) {
Error("Json document is not an object.", json_doc);
return QJsonObject();
}
QJsonObject json_obj = json_doc.object();
if (json_obj.isEmpty()) {
Error("Received empty Json object.", json_doc);
return QJsonObject();
}
return json_obj;
}
void TidalCoverProvider::HandleSearchReply(QNetworkReply *reply, const int id) {
reply->deleteLater();

View File

@ -32,14 +32,14 @@
#include <QJsonValue>
#include <QJsonObject>
#include "coverprovider.h"
#include "jsoncoverprovider.h"
#include "tidal/tidalservice.h"
class QNetworkAccessManager;
class QNetworkReply;
class Application;
class TidalCoverProvider : public CoverProvider {
class TidalCoverProvider : public JsonCoverProvider {
Q_OBJECT
public:
@ -55,7 +55,6 @@ class TidalCoverProvider : public CoverProvider {
private:
QByteArray GetReplyData(QNetworkReply *reply);
QJsonObject ExtractJsonObj(const QByteArray &data);
void Error(const QString &error, const QVariant &debug = QVariant());
private: