Create common class for Musixmatch
This commit is contained in:
parent
d722035883
commit
ec99df3144
|
@ -162,6 +162,8 @@ set(SOURCES
|
||||||
lyrics/musixmatchlyricsprovider.cpp
|
lyrics/musixmatchlyricsprovider.cpp
|
||||||
lyrics/chartlyricsprovider.cpp
|
lyrics/chartlyricsprovider.cpp
|
||||||
|
|
||||||
|
providers/musixmatchprovider.cpp
|
||||||
|
|
||||||
settings/settingsdialog.cpp
|
settings/settingsdialog.cpp
|
||||||
settings/settingspage.cpp
|
settings/settingspage.cpp
|
||||||
settings/behavioursettingspage.cpp
|
settings/behavioursettingspage.cpp
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
|
|
||||||
#include "core/logging.h"
|
#include "core/logging.h"
|
||||||
#include "core/networkaccessmanager.h"
|
#include "core/networkaccessmanager.h"
|
||||||
|
#include "providers/musixmatchprovider.h"
|
||||||
#include "albumcoverfetcher.h"
|
#include "albumcoverfetcher.h"
|
||||||
#include "jsoncoverprovider.h"
|
#include "jsoncoverprovider.h"
|
||||||
#include "musixmatchcoverprovider.h"
|
#include "musixmatchcoverprovider.h"
|
||||||
|
@ -56,22 +57,10 @@ bool MusixmatchCoverProvider::StartSearch(const QString &artist, const QString &
|
||||||
|
|
||||||
Q_UNUSED(title);
|
Q_UNUSED(title);
|
||||||
|
|
||||||
QString artist_stripped = artist;
|
if (artist.isEmpty() || album.isEmpty()) return false;
|
||||||
QString album_stripped = album;
|
|
||||||
|
|
||||||
artist_stripped = artist_stripped.replace('/', '-')
|
QString artist_stripped = StringFixup(artist);
|
||||||
.remove(QRegularExpression("[^\\w0-9\\- ]", QRegularExpression::UseUnicodePropertiesOption))
|
QString album_stripped = StringFixup(album);
|
||||||
.simplified()
|
|
||||||
.replace(' ', '-')
|
|
||||||
.replace(QRegularExpression("(-)\\1+"), "-")
|
|
||||||
.toLower();
|
|
||||||
|
|
||||||
album_stripped = album_stripped.replace('/', '-')
|
|
||||||
.remove(QRegularExpression("[^\\w0-9\\- ]", QRegularExpression::UseUnicodePropertiesOption))
|
|
||||||
.simplified()
|
|
||||||
.replace(' ', '-')
|
|
||||||
.replace(QRegularExpression("(-)\\1+"), "-")
|
|
||||||
.toLower();
|
|
||||||
|
|
||||||
if (artist_stripped.isEmpty() || album_stripped.isEmpty()) return false;
|
if (artist_stripped.isEmpty() || album_stripped.isEmpty()) return false;
|
||||||
|
|
||||||
|
|
|
@ -29,11 +29,12 @@
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include "jsoncoverprovider.h"
|
#include "jsoncoverprovider.h"
|
||||||
|
#include "providers/musixmatchprovider.h"
|
||||||
|
|
||||||
class QNetworkReply;
|
class QNetworkReply;
|
||||||
class NetworkAccessManager;
|
class NetworkAccessManager;
|
||||||
|
|
||||||
class MusixmatchCoverProvider : public JsonCoverProvider {
|
class MusixmatchCoverProvider : public JsonCoverProvider, MusixmatchProvider {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -39,9 +39,7 @@
|
||||||
#include "jsonlyricsprovider.h"
|
#include "jsonlyricsprovider.h"
|
||||||
#include "lyricsfetcher.h"
|
#include "lyricsfetcher.h"
|
||||||
#include "musixmatchlyricsprovider.h"
|
#include "musixmatchlyricsprovider.h"
|
||||||
|
#include "providers/musixmatchprovider.h"
|
||||||
const char *MusixmatchLyricsProvider::kApiUrl = "https://api.musixmatch.com/ws/1.1";
|
|
||||||
const char *MusixmatchLyricsProvider::kApiKey = "Y2FhMDRlN2Y4OWE5OTIxYmZlOGMzOWQzOGI3ZGU4MjE=";
|
|
||||||
|
|
||||||
MusixmatchLyricsProvider::MusixmatchLyricsProvider(NetworkAccessManager *network, QObject *parent) : JsonLyricsProvider("Musixmatch", true, false, network, parent), rate_limit_exceeded_(false) {}
|
MusixmatchLyricsProvider::MusixmatchLyricsProvider(NetworkAccessManager *network, QObject *parent) : JsonLyricsProvider("Musixmatch", true, false, network, parent), rate_limit_exceeded_(false) {}
|
||||||
|
|
||||||
|
@ -247,18 +245,6 @@ void MusixmatchLyricsProvider::HandleSearchReply(QNetworkReply *reply, LyricsSea
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MusixmatchLyricsProvider::StringFixup(QString string) {
|
|
||||||
|
|
||||||
return string.replace('/', '-')
|
|
||||||
.replace('\'', '-')
|
|
||||||
.remove(QRegularExpression("[^\\w0-9\\- ]", QRegularExpression::UseUnicodePropertiesOption))
|
|
||||||
.simplified()
|
|
||||||
.replace(' ', '-')
|
|
||||||
.replace(QRegularExpression("(-)\\1+"), "-")
|
|
||||||
.toLower();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MusixmatchLyricsProvider::CreateLyricsRequest(LyricsSearchContextPtr search) {
|
bool MusixmatchLyricsProvider::CreateLyricsRequest(LyricsSearchContextPtr search) {
|
||||||
|
|
||||||
QString artist_stripped = StringFixup(search->artist);
|
QString artist_stripped = StringFixup(search->artist);
|
||||||
|
|
|
@ -33,11 +33,12 @@
|
||||||
|
|
||||||
#include "jsonlyricsprovider.h"
|
#include "jsonlyricsprovider.h"
|
||||||
#include "lyricsfetcher.h"
|
#include "lyricsfetcher.h"
|
||||||
|
#include "providers/musixmatchprovider.h"
|
||||||
|
|
||||||
class QNetworkReply;
|
class QNetworkReply;
|
||||||
class NetworkAccessManager;
|
class NetworkAccessManager;
|
||||||
|
|
||||||
class MusixmatchLyricsProvider : public JsonLyricsProvider {
|
class MusixmatchLyricsProvider : public JsonLyricsProvider, public MusixmatchProvider {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -60,7 +61,6 @@ class MusixmatchLyricsProvider : public JsonLyricsProvider {
|
||||||
|
|
||||||
using LyricsSearchContextPtr = std::shared_ptr<LyricsSearchContext>;
|
using LyricsSearchContextPtr = std::shared_ptr<LyricsSearchContext>;
|
||||||
|
|
||||||
QString StringFixup(QString string);
|
|
||||||
bool SendSearchRequest(LyricsSearchContextPtr search);
|
bool SendSearchRequest(LyricsSearchContextPtr search);
|
||||||
bool CreateLyricsRequest(LyricsSearchContextPtr search);
|
bool CreateLyricsRequest(LyricsSearchContextPtr search);
|
||||||
bool SendLyricsRequest(LyricsSearchContextPtr search, const QUrl &url);
|
bool SendLyricsRequest(LyricsSearchContextPtr search, const QUrl &url);
|
||||||
|
@ -72,8 +72,6 @@ class MusixmatchLyricsProvider : public JsonLyricsProvider {
|
||||||
void HandleLyricsReply(QNetworkReply *reply, LyricsSearchContextPtr search, const QUrl &url);
|
void HandleLyricsReply(QNetworkReply *reply, LyricsSearchContextPtr search, const QUrl &url);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const char *kApiUrl;
|
|
||||||
static const char *kApiKey;
|
|
||||||
QList<LyricsSearchContextPtr> requests_search_;
|
QList<LyricsSearchContextPtr> requests_search_;
|
||||||
QList<QNetworkReply*> replies_;
|
QList<QNetworkReply*> replies_;
|
||||||
bool rate_limit_exceeded_;
|
bool rate_limit_exceeded_;
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* Strawberry Music Player
|
||||||
|
* Copyright 2020-2022, 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 <QString>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
|
#include "musixmatchprovider.h"
|
||||||
|
|
||||||
|
const char *MusixmatchProvider::kApiUrl = "https://api.musixmatch.com/ws/1.1";
|
||||||
|
const char *MusixmatchProvider::kApiKey = "Y2FhMDRlN2Y4OWE5OTIxYmZlOGMzOWQzOGI3ZGU4MjE=";
|
||||||
|
|
||||||
|
QString MusixmatchProvider::StringFixup(QString string) {
|
||||||
|
|
||||||
|
return string.replace('/', '-')
|
||||||
|
.replace('\'', '-')
|
||||||
|
.remove(QRegularExpression("[^\\w0-9\\- ]", QRegularExpression::UseUnicodePropertiesOption))
|
||||||
|
.simplified()
|
||||||
|
.replace(' ', '-')
|
||||||
|
.replace(QRegularExpression("(-)\\1+"), "-")
|
||||||
|
.toLower();
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* Strawberry Music Player
|
||||||
|
* Copyright 2020-2022, 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 MUSIXMATCHPROVIDER_H
|
||||||
|
#define MUSIXMATCHPROVIDER_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
|
class MusixmatchProvider {
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QString StringFixup(QString string);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static const char *kApiUrl;
|
||||||
|
static const char *kApiKey;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MUSIXMATCHPROVIDER_H
|
Loading…
Reference in New Issue