2018-02-27 18:06:05 +01:00
|
|
|
/*
|
|
|
|
* Strawberry Music Player
|
|
|
|
* This file was part of Clementine.
|
|
|
|
* Copyright 2012, Martin Björklund <mbj4668@gmail.com>
|
|
|
|
* Copyright 2016, 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/>.
|
2018-08-09 18:39:44 +02:00
|
|
|
*
|
2018-02-27 18:06:05 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DISCOGSCOVERPROVIDER_H
|
|
|
|
#define DISCOGSCOVERPROVIDER_H
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QHash>
|
|
|
|
#include <QMetaType>
|
|
|
|
#include <QString>
|
|
|
|
#include <QNetworkAccessManager>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <QNetworkReply>
|
|
|
|
|
|
|
|
#include "coverprovider.h"
|
2018-05-01 00:41:33 +02:00
|
|
|
#include "albumcoverfetcher.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
|
|
|
// This struct represents a single search-for-cover request. It identifies and describes the request.
|
|
|
|
struct DiscogsCoverSearchContext {
|
2019-07-07 21:14:24 +02:00
|
|
|
DiscogsCoverSearchContext() : id(-1), r_count(0) {}
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
// The unique request identifier
|
2018-02-27 18:06:05 +01:00
|
|
|
int id;
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
// The search query
|
2018-02-27 18:06:05 +01:00
|
|
|
QString artist;
|
|
|
|
QString album;
|
2018-03-02 22:51:42 +01:00
|
|
|
int r_count;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
CoverSearchResults results;
|
|
|
|
};
|
|
|
|
Q_DECLARE_METATYPE(DiscogsCoverSearchContext)
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
// This struct represents a single release request. It identifies and describes the request.
|
2018-03-02 22:51:42 +01:00
|
|
|
struct DiscogsCoverReleaseContext {
|
2019-07-07 21:14:24 +02:00
|
|
|
DiscogsCoverReleaseContext() : id(-1) {}
|
2018-03-02 22:51:42 +01:00
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
int id; // The unique request identifier
|
|
|
|
int s_id; // The search request identifier
|
2018-03-02 22:51:42 +01:00
|
|
|
|
|
|
|
QString resource_url;
|
|
|
|
};
|
|
|
|
Q_DECLARE_METATYPE(DiscogsCoverReleaseContext)
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
class DiscogsCoverProvider : public CoverProvider {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2019-04-14 16:40:05 +02:00
|
|
|
explicit DiscogsCoverProvider(Application *app, QObject *parent = nullptr);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-03-02 22:51:42 +01:00
|
|
|
bool StartSearch(const QString &artist, const QString &album, int s_id);
|
2018-10-02 00:38:52 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
void CancelSearch(int id);
|
|
|
|
|
|
|
|
private slots:
|
2018-03-02 22:51:42 +01:00
|
|
|
void HandleSearchReply(QNetworkReply *reply, int s_id);
|
2018-03-17 14:28:45 +01:00
|
|
|
void HandleReleaseReply(QNetworkReply *reply, int s_id, int r_id);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
private:
|
2018-03-17 14:28:45 +01:00
|
|
|
static const char *kUrlSearch;
|
|
|
|
static const char *kUrlReleases;
|
|
|
|
static const char *kAccessKeyB64;
|
|
|
|
static const char *kSecretKeyB64;
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
QNetworkAccessManager *network_;
|
2018-03-02 22:51:42 +01:00
|
|
|
QHash<int, DiscogsCoverSearchContext*> requests_search_;
|
|
|
|
QHash<int, DiscogsCoverReleaseContext*> requests_release_;
|
2018-03-05 21:05:30 +01:00
|
|
|
|
2019-04-17 22:22:35 +02:00
|
|
|
bool StartRelease(DiscogsCoverSearchContext *s_ctx, int r_id, QString &resource_url);
|
2018-03-02 22:51:42 +01:00
|
|
|
|
|
|
|
void SendSearchRequest(DiscogsCoverSearchContext *s_ctx);
|
|
|
|
void SendReleaseRequest(DiscogsCoverSearchContext *s_ctx, DiscogsCoverReleaseContext *r_ctx);
|
2018-12-02 23:29:22 +01:00
|
|
|
QByteArray GetReplyData(QNetworkReply *reply);
|
|
|
|
QJsonObject ExtractJsonObj(const QByteArray &data);
|
|
|
|
QJsonValue ExtractData(const QByteArray &data, const QString name, const bool silent = false);
|
2018-03-02 22:51:42 +01:00
|
|
|
void EndSearch(DiscogsCoverSearchContext *s_ctx, DiscogsCoverReleaseContext *r_ctx);
|
|
|
|
void EndSearch(DiscogsCoverSearchContext *s_ctx);
|
2018-03-17 14:28:45 +01:00
|
|
|
void EndSearch(DiscogsCoverReleaseContext *r_ctx);
|
2018-12-02 23:29:22 +01:00
|
|
|
void Error(QString error, QVariant debug = QVariant());
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // DISCOGSCOVERPROVIDER_H
|