2020-05-08 18:35:36 +02:00
|
|
|
/*
|
|
|
|
* Strawberry Music Player
|
2022-10-17 20:29:44 +02:00
|
|
|
* Copyright 2020-2022, 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 MUSIXMATCHLYRICSPROVIDER_H
|
|
|
|
#define MUSIXMATCHLYRICSPROVIDER_H
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <QtGlobal>
|
|
|
|
#include <QObject>
|
2020-05-12 21:28:42 +02:00
|
|
|
#include <QList>
|
2020-05-08 18:35:36 +02:00
|
|
|
#include <QVariant>
|
|
|
|
#include <QString>
|
2022-10-17 20:29:44 +02:00
|
|
|
#include <QUrl>
|
2020-05-08 18:35:36 +02:00
|
|
|
|
2023-07-21 05:55:24 +02:00
|
|
|
#include "core/shared_ptr.h"
|
2020-05-08 18:35:36 +02:00
|
|
|
#include "jsonlyricsprovider.h"
|
2023-03-06 21:42:59 +01:00
|
|
|
#include "lyricssearchrequest.h"
|
|
|
|
#include "lyricssearchresult.h"
|
2022-10-18 22:49:15 +02:00
|
|
|
#include "providers/musixmatchprovider.h"
|
2020-05-08 18:35:36 +02:00
|
|
|
|
|
|
|
class QNetworkReply;
|
2020-12-09 18:39:37 +01:00
|
|
|
class NetworkAccessManager;
|
2020-05-08 18:35:36 +02:00
|
|
|
|
2022-10-18 22:49:15 +02:00
|
|
|
class MusixmatchLyricsProvider : public JsonLyricsProvider, public MusixmatchProvider {
|
2020-05-08 18:35:36 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2023-07-21 05:55:24 +02:00
|
|
|
explicit MusixmatchLyricsProvider(SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
|
2020-06-15 21:55:05 +02:00
|
|
|
~MusixmatchLyricsProvider() override;
|
2020-05-08 18:35:36 +02:00
|
|
|
|
2023-03-06 21:42:59 +01:00
|
|
|
bool StartSearch(const int id, const LyricsSearchRequest &request) override;
|
2021-10-30 02:21:29 +02:00
|
|
|
void CancelSearch(const int id) override;
|
2020-05-08 18:35:36 +02:00
|
|
|
|
|
|
|
private:
|
2022-10-17 20:29:44 +02:00
|
|
|
struct LyricsSearchContext {
|
|
|
|
explicit LyricsSearchContext() : id(-1) {}
|
|
|
|
int id;
|
2023-03-06 21:42:59 +01:00
|
|
|
LyricsSearchRequest request;
|
2022-10-17 20:29:44 +02:00
|
|
|
QList<QUrl> requests_lyrics_;
|
|
|
|
LyricsSearchResults results;
|
|
|
|
};
|
|
|
|
|
2023-07-21 05:55:24 +02:00
|
|
|
using LyricsSearchContextPtr = SharedPtr<LyricsSearchContext>;
|
2022-10-17 20:29:44 +02:00
|
|
|
|
|
|
|
bool SendSearchRequest(LyricsSearchContextPtr search);
|
|
|
|
bool CreateLyricsRequest(LyricsSearchContextPtr search);
|
2023-03-06 21:42:59 +01:00
|
|
|
void SendLyricsRequest(const LyricsSearchRequest &request, const QString &artist, const QString &title);
|
2022-10-17 20:29:44 +02:00
|
|
|
bool SendLyricsRequest(LyricsSearchContextPtr search, const QUrl &url);
|
|
|
|
void EndSearch(LyricsSearchContextPtr search, const QUrl &url = QUrl());
|
2020-06-15 21:55:05 +02:00
|
|
|
void Error(const QString &error, const QVariant &debug = QVariant()) override;
|
2020-05-08 18:35:36 +02:00
|
|
|
|
|
|
|
private slots:
|
2022-10-17 20:29:44 +02:00
|
|
|
void HandleSearchReply(QNetworkReply *reply, LyricsSearchContextPtr search);
|
|
|
|
void HandleLyricsReply(QNetworkReply *reply, LyricsSearchContextPtr search, const QUrl &url);
|
2020-05-08 18:35:36 +02:00
|
|
|
|
|
|
|
private:
|
2022-10-17 20:29:44 +02:00
|
|
|
QList<LyricsSearchContextPtr> requests_search_;
|
2020-05-12 21:28:42 +02:00
|
|
|
QList<QNetworkReply*> replies_;
|
2023-03-06 21:42:59 +01:00
|
|
|
bool use_api_;
|
2020-05-08 18:35:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // MUSIXMATCHLYRICSPROVIDER_H
|