2020-05-08 18:35:36 +02:00
|
|
|
/*
|
|
|
|
* Strawberry Music Player
|
2021-03-20 21:14:47 +01:00
|
|
|
* Copyright 2020-2021, Jonas Kvinge <jonas@jkvinge.net>
|
2020-05-08 18:35:36 +02: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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GENIUSLYRICSPROVIDER_H
|
|
|
|
#define GENIUSLYRICSPROVIDER_H
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2020-05-08 18:47:55 +02:00
|
|
|
#include <memory>
|
2020-05-08 18:35:36 +02:00
|
|
|
|
|
|
|
#include <QtGlobal>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QList>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QVariant>
|
|
|
|
#include <QString>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QSslError>
|
|
|
|
#include <QJsonArray>
|
|
|
|
|
|
|
|
#include "jsonlyricsprovider.h"
|
|
|
|
#include "lyricsfetcher.h"
|
|
|
|
|
|
|
|
class QNetworkReply;
|
2020-12-09 18:39:37 +01:00
|
|
|
class NetworkAccessManager;
|
2020-05-08 18:35:36 +02:00
|
|
|
class LocalRedirectServer;
|
|
|
|
|
|
|
|
class GeniusLyricsProvider : public JsonLyricsProvider {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2021-08-12 23:00:10 +02:00
|
|
|
explicit GeniusLyricsProvider(NetworkAccessManager *network, QObject *parent = nullptr);
|
2020-06-15 21:55:05 +02:00
|
|
|
~GeniusLyricsProvider() override;
|
2020-05-08 18:35:36 +02:00
|
|
|
|
2020-06-15 21:55:05 +02:00
|
|
|
bool IsAuthenticated() const override { return !access_token_.isEmpty(); }
|
|
|
|
void Authenticate() override;
|
|
|
|
void Deauthenticate() override { access_token_.clear(); }
|
2020-05-08 18:35:36 +02:00
|
|
|
|
2021-10-30 02:21:29 +02:00
|
|
|
bool StartSearch(const QString &artist, const QString &album, const QString &title, int id) override;
|
|
|
|
void CancelSearch(const int id) override;
|
2020-05-08 18:35:36 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
struct GeniusLyricsLyricContext {
|
|
|
|
explicit GeniusLyricsLyricContext() {}
|
|
|
|
QString artist;
|
|
|
|
QString title;
|
|
|
|
QUrl url;
|
|
|
|
};
|
|
|
|
struct GeniusLyricsSearchContext {
|
|
|
|
explicit GeniusLyricsSearchContext() : id(-1) {}
|
|
|
|
int id;
|
|
|
|
QString artist;
|
|
|
|
QString title;
|
|
|
|
QMap<QUrl, GeniusLyricsLyricContext> requests_lyric_;
|
|
|
|
LyricsSearchResults results;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
void RequestAccessToken(const QUrl &url, const QUrl &redirect_url);
|
|
|
|
void AuthError(const QString &error = QString(), const QVariant &debug = QVariant());
|
2020-06-15 21:55:05 +02:00
|
|
|
void Error(const QString &error, const QVariant &debug = QVariant()) override;
|
2021-06-20 19:04:08 +02:00
|
|
|
void EndSearch(std::shared_ptr<GeniusLyricsSearchContext> search, const GeniusLyricsLyricContext &lyric = GeniusLyricsLyricContext());
|
2020-05-08 18:35:36 +02:00
|
|
|
|
|
|
|
private slots:
|
2021-06-20 19:04:08 +02:00
|
|
|
void HandleLoginSSLErrors(const QList<QSslError> &ssl_errors);
|
2020-05-08 18:35:36 +02:00
|
|
|
void RedirectArrived();
|
|
|
|
void AccessTokenRequestFinished(QNetworkReply *reply);
|
2021-10-30 02:21:29 +02:00
|
|
|
void HandleSearchReply(QNetworkReply *reply, const int id);
|
2020-05-08 18:35:36 +02:00
|
|
|
void HandleLyricReply(QNetworkReply *reply, const int search_id, const QUrl &url);
|
|
|
|
|
|
|
|
private:
|
|
|
|
static const char *kSettingsGroup;
|
|
|
|
static const char *kClientIDB64;
|
|
|
|
static const char *kClientSecretB64;
|
|
|
|
static const char *kOAuthAuthorizeUrl;
|
|
|
|
static const char *kOAuthAccessTokenUrl;
|
|
|
|
static const char *kOAuthRedirectUrl;
|
|
|
|
static const char *kUrlSearch;
|
|
|
|
|
|
|
|
private:
|
|
|
|
LocalRedirectServer *server_;
|
|
|
|
QString code_verifier_;
|
|
|
|
QString code_challenge_;
|
|
|
|
QString access_token_;
|
|
|
|
QStringList login_errors_;
|
|
|
|
QMap<int, std::shared_ptr<GeniusLyricsSearchContext>> requests_search_;
|
2020-05-12 21:28:42 +02:00
|
|
|
QList<QNetworkReply*> replies_;
|
2020-05-08 18:35:36 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // GENIUSLYRICSPROVIDER_H
|