Add lyrics from elyrics.net and lyricsmode.com
This commit is contained in:
@@ -186,6 +186,8 @@ set(SOURCES
|
||||
lyrics/chartlyricsprovider.cpp
|
||||
lyrics/songlyricscomlyricsprovider.cpp
|
||||
lyrics/azlyricscomlyricsprovider.cpp
|
||||
lyrics/elyricsnetlyricsprovider.cpp
|
||||
lyrics/lyricsmodecomlyricsprovider.cpp
|
||||
|
||||
providers/musixmatchprovider.cpp
|
||||
|
||||
@@ -426,6 +428,8 @@ set(HEADERS
|
||||
lyrics/chartlyricsprovider.h
|
||||
lyrics/songlyricscomlyricsprovider.h
|
||||
lyrics/azlyricscomlyricsprovider.h
|
||||
lyrics/elyricsnetlyricsprovider.h
|
||||
lyrics/lyricsmodecomlyricsprovider.h
|
||||
|
||||
settings/settingsdialog.h
|
||||
settings/settingspage.h
|
||||
|
||||
@@ -66,6 +66,8 @@
|
||||
#include "lyrics/chartlyricsprovider.h"
|
||||
#include "lyrics/songlyricscomlyricsprovider.h"
|
||||
#include "lyrics/azlyricscomlyricsprovider.h"
|
||||
#include "lyrics/elyricsnetlyricsprovider.h"
|
||||
#include "lyrics/lyricsmodecomlyricsprovider.h"
|
||||
|
||||
#include "scrobbler/audioscrobbler.h"
|
||||
#include "scrobbler/lastfmscrobbler.h"
|
||||
@@ -166,6 +168,8 @@ class ApplicationImpl {
|
||||
lyrics_providers->AddProvider(new ChartLyricsProvider(app->network()));
|
||||
lyrics_providers->AddProvider(new SongLyricsComLyricsProvider(app->network()));
|
||||
lyrics_providers->AddProvider(new AzLyricsComLyricsProvider(app->network()));
|
||||
lyrics_providers->AddProvider(new ElyricsNetLyricsProvider(app->network()));
|
||||
lyrics_providers->AddProvider(new LyricsModeComLyricsProvider(app->network()));
|
||||
lyrics_providers->ReloadSettings();
|
||||
return lyrics_providers;
|
||||
}),
|
||||
|
||||
54
src/lyrics/elyricsnetlyricsprovider.cpp
Normal file
54
src/lyrics/elyricsnetlyricsprovider.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2023, 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 <QObject>
|
||||
#include <QByteArray>
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/networkaccessmanager.h"
|
||||
#include "lyricssearchrequest.h"
|
||||
#include "elyricsnetlyricsprovider.h"
|
||||
|
||||
const char ElyricsNetLyricsProvider::kUrl[] = "https://www.elyrics.net/read/";
|
||||
const char ElyricsNetLyricsProvider::kStartTag[] = "<div[^>]*>";
|
||||
const char ElyricsNetLyricsProvider::kEndTag[] = "<\\/div>";
|
||||
const char ElyricsNetLyricsProvider::kLyricsStart[] = "<div id='inlyr'>";
|
||||
|
||||
ElyricsNetLyricsProvider::ElyricsNetLyricsProvider(SharedPtr<NetworkAccessManager> network, QObject *parent)
|
||||
: HtmlLyricsProvider("elyrics.net", true, kStartTag, kEndTag, kLyricsStart, false, network, parent) {}
|
||||
|
||||
QUrl ElyricsNetLyricsProvider::Url(const LyricsSearchRequest &request) {
|
||||
|
||||
return QUrl(kUrl + request.artist[0].toLower() + "/" + StringFixup(request.artist) + "-lyrics/" + StringFixup(request.title) + "-lyrics.html");
|
||||
|
||||
}
|
||||
|
||||
QString ElyricsNetLyricsProvider::StringFixup(QString string) {
|
||||
|
||||
return string
|
||||
.replace(' ', '-')
|
||||
.replace(QRegularExpression("[^\\w0-9_-]", QRegularExpression::UseUnicodePropertiesOption), "_")
|
||||
.simplified()
|
||||
.toLower();
|
||||
|
||||
}
|
||||
54
src/lyrics/elyricsnetlyricsprovider.h
Normal file
54
src/lyrics/elyricsnetlyricsprovider.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2023, 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 ELYRICSNETLYRICSPROVIDER_H
|
||||
#define ELYRICSNETLYRICSPROVIDER_H
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/networkaccessmanager.h"
|
||||
#include "htmllyricsprovider.h"
|
||||
#include "lyricssearchrequest.h"
|
||||
|
||||
class ElyricsNetLyricsProvider : public HtmlLyricsProvider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ElyricsNetLyricsProvider(SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
|
||||
|
||||
protected:
|
||||
QUrl Url(const LyricsSearchRequest &request) override;
|
||||
|
||||
private:
|
||||
QString StringFixup(QString string);
|
||||
|
||||
private:
|
||||
static const char kUrl[];
|
||||
static const char kStartTag[];
|
||||
static const char kEndTag[];
|
||||
static const char kLyricsStart[];
|
||||
};
|
||||
|
||||
#endif // ELYRICSNETLYRICSPROVIDER_H
|
||||
@@ -158,7 +158,9 @@ QString HtmlLyricsProvider::ParseLyricsFromHTML(const QString &content, const QR
|
||||
lyrics.append(content.mid(start_lyrics_idx, end_lyrics_idx - start_lyrics_idx)
|
||||
.remove('\r')
|
||||
.remove('\n')
|
||||
.remove(QRegularExpression("<script>.*</script>"))
|
||||
.remove(QRegularExpression("<a [^>]*>[^<]*</a>"))
|
||||
.remove(QRegularExpression("<script>[^>]*</script>"))
|
||||
.remove(QRegularExpression("<div [^>]*>×</div>"))
|
||||
.replace(QRegularExpression("<br[^>]*>"), "\n")
|
||||
.remove(QRegularExpression("<[^>]*>"))
|
||||
.trimmed());
|
||||
|
||||
54
src/lyrics/lyricsmodecomlyricsprovider.cpp
Normal file
54
src/lyrics/lyricsmodecomlyricsprovider.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2023, 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 <QObject>
|
||||
#include <QByteArray>
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/networkaccessmanager.h"
|
||||
#include "lyricssearchrequest.h"
|
||||
#include "lyricsmodecomlyricsprovider.h"
|
||||
|
||||
const char LyricsModeComLyricsProvider::kUrl[] = "https://www.lyricsmode.com/lyrics/";
|
||||
const char LyricsModeComLyricsProvider::kStartTag[] = "<div[^>]*>";
|
||||
const char LyricsModeComLyricsProvider::kEndTag[] = "<\\/div>";
|
||||
const char LyricsModeComLyricsProvider::kLyricsStart[] = "<div id=\"lyrics_text\" [^>]*>";
|
||||
|
||||
LyricsModeComLyricsProvider::LyricsModeComLyricsProvider(SharedPtr<NetworkAccessManager> network, QObject *parent)
|
||||
: HtmlLyricsProvider("lyricsmode.com", true, kStartTag, kEndTag, kLyricsStart, false, network, parent) {}
|
||||
|
||||
QUrl LyricsModeComLyricsProvider::Url(const LyricsSearchRequest &request) {
|
||||
|
||||
return QUrl(kUrl + request.artist[0].toLower() + "/" + StringFixup(request.artist) + "/" + StringFixup(request.title) + ".html");
|
||||
|
||||
}
|
||||
|
||||
QString LyricsModeComLyricsProvider::StringFixup(QString string) {
|
||||
|
||||
return string
|
||||
.replace(' ', '_')
|
||||
.remove(QRegularExpression("[^\\w0-9_-]", QRegularExpression::UseUnicodePropertiesOption))
|
||||
.simplified()
|
||||
.toLower();
|
||||
|
||||
}
|
||||
54
src/lyrics/lyricsmodecomlyricsprovider.h
Normal file
54
src/lyrics/lyricsmodecomlyricsprovider.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2023, 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 LYRICSMODECOMLYRICSPROVIDER_H
|
||||
#define LYRICSMODECOMLYRICSPROVIDER_H
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/networkaccessmanager.h"
|
||||
#include "htmllyricsprovider.h"
|
||||
#include "lyricssearchrequest.h"
|
||||
|
||||
class LyricsModeComLyricsProvider : public HtmlLyricsProvider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LyricsModeComLyricsProvider(SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
|
||||
|
||||
protected:
|
||||
QUrl Url(const LyricsSearchRequest &request) override;
|
||||
|
||||
private:
|
||||
QString StringFixup(QString string);
|
||||
|
||||
private:
|
||||
static const char kUrl[];
|
||||
static const char kStartTag[];
|
||||
static const char kEndTag[];
|
||||
static const char kLyricsStart[];
|
||||
};
|
||||
|
||||
#endif // LYRICSMODECOMLYRICSPROVIDER_H
|
||||
Reference in New Issue
Block a user