strawberry-audio-player-win.../src/covermanager/lastfmcoverprovider.h

74 lines
1.9 KiB
C
Raw Normal View History

2018-02-27 18:06:05 +01:00
/*
* Strawberry Music Player
2018-12-15 00:43:50 +01:00
* Copyright 2018, Jonas Kvinge <jonas@jkvinge.net>
2018-02-27 18:06:05 +01:00
*
* 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/>.
2018-08-09 18:39:44 +02:00
*
2018-02-27 18:06:05 +01:00
*/
#ifndef LASTFMCOVERPROVIDER_H
#define LASTFMCOVERPROVIDER_H
#include "config.h"
#include <stdbool.h>
2018-02-27 18:06:05 +01:00
#include <QObject>
2018-12-15 00:52:58 +01:00
#include <QVariant>
#include <QByteArray>
#include <QString>
#include <QNetworkAccessManager>
#include <QNetworkReply>
2018-12-15 00:52:58 +01:00
#include <QJsonValue>
#include <QJsonObject>
#include <QJsonArray>
2018-02-27 18:06:05 +01:00
#include "coverprovider.h"
2018-02-27 18:06:05 +01:00
2019-04-14 16:40:05 +02:00
class Application;
2018-02-27 18:06:05 +01:00
class LastFmCoverProvider : public CoverProvider {
Q_OBJECT
public:
2019-04-14 16:40:05 +02:00
explicit LastFmCoverProvider(Application *app, QObject *parent = nullptr);
2018-02-27 18:06:05 +01:00
bool StartSearch(const QString &artist, const QString &album, int id);
private slots:
2018-02-27 18:06:05 +01:00
void QueryFinished(QNetworkReply *reply, int id);
private:
2018-12-15 00:43:50 +01:00
static const char *kUrl;
static const char *kApiKey;
static const char *kSecret;
enum LastFmImageSize {
Unknown,
Small,
Medium,
Large,
ExtraLarge
};
QByteArray GetReplyData(QNetworkReply *reply);
QJsonObject ExtractJsonObj(const QByteArray &data);
QJsonValue ExtractResults(const QByteArray &data);
LastFmImageSize ImageSizeFromString(const QString size);
void Error(QString error, QVariant debug = QVariant());
2018-02-27 18:06:05 +01:00
QNetworkAccessManager *network_;
2018-02-27 18:06:05 +01:00
};
2018-12-15 00:43:50 +01:00
#endif // LASTFMCOVERPROVIDER_H
2018-02-27 18:06:05 +01:00