From 8393cdb2de47523a9939fedcf9df7cee47efe1cf Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Wed, 20 Sep 2023 19:02:28 +0200 Subject: [PATCH] Add lyrics from elyrics.net and lyricsmode.com --- README.md | 2 +- debian/control.in | 2 +- ...rawberrymusicplayer.strawberry.appdata.xml | 2 +- dist/unix/strawberry.spec.in | 2 +- src/CMakeLists.txt | 4 ++ src/core/application.cpp | 4 ++ src/lyrics/elyricsnetlyricsprovider.cpp | 54 +++++++++++++++++++ src/lyrics/elyricsnetlyricsprovider.h | 54 +++++++++++++++++++ src/lyrics/htmllyricsprovider.cpp | 4 +- src/lyrics/lyricsmodecomlyricsprovider.cpp | 54 +++++++++++++++++++ src/lyrics/lyricsmodecomlyricsprovider.h | 54 +++++++++++++++++++ 11 files changed, 231 insertions(+), 5 deletions(-) create mode 100644 src/lyrics/elyricsnetlyricsprovider.cpp create mode 100644 src/lyrics/elyricsnetlyricsprovider.h create mode 100644 src/lyrics/lyricsmodecomlyricsprovider.cpp create mode 100644 src/lyrics/lyricsmodecomlyricsprovider.h diff --git a/README.md b/README.md index 974e1cfc..373b7a65 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Funding developers is a way to contribute to open source projects you appreciate * Edit tags on audio files * Fetch tags from MusicBrainz * Album cover art from [Last.fm](https://www.last.fm/), [Musicbrainz](https://musicbrainz.org/), [Discogs](https://www.discogs.com/), [Musixmatch](https://www.musixmatch.com/), [Deezer](https://www.deezer.com/), [Tidal](https://www.tidal.com/), [Qobuz](https://www.qobuz.com/) and [Spotify](https://www.spotify.com/) - * Song lyrics from [Genius](https://genius.com/), [Musixmatch](https://www.musixmatch.com/), [ChartLyrics](http://www.chartlyrics.com/), [lyrics.ovh](https://lyrics.ovh/), [lololyrics.com](https://www.lololyrics.com/), [songlyrics.com](https://www.songlyrics.com/) and [azlyrics.com](https://www.azlyrics.com/) + * Song lyrics from [Genius](https://genius.com/), [Musixmatch](https://www.musixmatch.com/), [ChartLyrics](http://www.chartlyrics.com/), [lyrics.ovh](https://lyrics.ovh/), [lololyrics.com](https://www.lololyrics.com/), [songlyrics.com](https://www.songlyrics.com/), [azlyrics.com](https://www.azlyrics.com/), [elyrics.net](https://www.elyrics.net/) and [lyricsmode.com](https://www.lyricsmode.com/) * Support for multiple backends * Audio analyzer * Audio equalizer diff --git a/debian/control.in b/debian/control.in index e84dabc1..e38eb70a 100644 --- a/debian/control.in +++ b/debian/control.in @@ -52,7 +52,7 @@ Description: music player and music collection organizer - Edit tags on audio files - Automatically retrieve tags from MusicBrainz - Album cover art from Last.fm, Musicbrainz, Discogs, Musixmatch, Deezer, Tidal, Qobuz and Spotify - - Song lyrics from Genius, Musixmatch, ChartLyrics, lyrics.ovh, lololyrics.com, songlyrics.com and azlyrics.com + - Song lyrics from Genius, Musixmatch, ChartLyrics, lyrics.ovh, lololyrics.com, songlyrics.com, azlyrics.com, elyrics.net and lyricsmode.com - Audio analyzer - Audio equalizer - Transfer music to mass-storage USB players, MTP compatible devices and iPod Nano/Classic diff --git a/dist/unix/org.strawberrymusicplayer.strawberry.appdata.xml b/dist/unix/org.strawberrymusicplayer.strawberry.appdata.xml index 81007353..32e3d1bc 100644 --- a/dist/unix/org.strawberrymusicplayer.strawberry.appdata.xml +++ b/dist/unix/org.strawberrymusicplayer.strawberry.appdata.xml @@ -29,7 +29,7 @@
  • Edit tags on audio files
  • Automatically retrieve tags from MusicBrainz
  • Album cover art from Last.fm, Musicbrainz, Discogs, Musixmatch, Deezer, Tidal, Qobuz and Spotify
  • -
  • Song lyrics from Genius, Musixmatch, ChartLyrics, lyrics.ovh, lololyrics.com, songlyrics.com and azlyrics.com
  • +
  • Song lyrics from Genius, Musixmatch, ChartLyrics, lyrics.ovh, lololyrics.com, songlyrics.com, azlyrics.com, elyrics.net and lyricsmode.com
  • Support for multiple backends
  • Audio analyzer and equalizer
  • Transfer music to mass-storage USB players, MTP compatible devices and iPod Nano/Classic
  • diff --git a/dist/unix/strawberry.spec.in b/dist/unix/strawberry.spec.in index 9a6aa7fe..9ef5c29a 100644 --- a/dist/unix/strawberry.spec.in +++ b/dist/unix/strawberry.spec.in @@ -118,7 +118,7 @@ Features: - Edit tags on audio files - Automatically retrieve tags from MusicBrainz - Album cover art from Last.fm, Musicbrainz, Discogs, Musixmatch, Deezer, Tidal, Qobuz and Spotify - - Song lyrics from Genius, Musixmatch, ChartLyrics, lyrics.ovh, lololyrics.com, songlyrics.com and azlyrics.com + - Song lyrics from Genius, Musixmatch, ChartLyrics, lyrics.ovh, lololyrics.com, songlyrics.com, azlyrics.com, elyrics.net and lyricsmode.com - Support for multiple backends - Audio analyzer - Audio equalizer diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f1719f7d..44796841 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/core/application.cpp b/src/core/application.cpp index a481d213..84c39b5a 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -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; }), diff --git a/src/lyrics/elyricsnetlyricsprovider.cpp b/src/lyrics/elyricsnetlyricsprovider.cpp new file mode 100644 index 00000000..8e10b80c --- /dev/null +++ b/src/lyrics/elyricsnetlyricsprovider.cpp @@ -0,0 +1,54 @@ +/* + * Strawberry Music Player + * Copyright 2023, Jonas Kvinge + * + * 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 . + * + */ + +#include +#include +#include +#include +#include +#include + +#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[] = "]*>"; +const char ElyricsNetLyricsProvider::kEndTag[] = "<\\/div>"; +const char ElyricsNetLyricsProvider::kLyricsStart[] = "
    "; + +ElyricsNetLyricsProvider::ElyricsNetLyricsProvider(SharedPtr 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(); + +} diff --git a/src/lyrics/elyricsnetlyricsprovider.h b/src/lyrics/elyricsnetlyricsprovider.h new file mode 100644 index 00000000..8a5ee0a9 --- /dev/null +++ b/src/lyrics/elyricsnetlyricsprovider.h @@ -0,0 +1,54 @@ +/* + * Strawberry Music Player + * Copyright 2023, Jonas Kvinge + * + * 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 . + * + */ + +#ifndef ELYRICSNETLYRICSPROVIDER_H +#define ELYRICSNETLYRICSPROVIDER_H + +#include +#include +#include +#include +#include +#include + +#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 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 diff --git a/src/lyrics/htmllyricsprovider.cpp b/src/lyrics/htmllyricsprovider.cpp index 3c677da9..fb9f3bfa 100644 --- a/src/lyrics/htmllyricsprovider.cpp +++ b/src/lyrics/htmllyricsprovider.cpp @@ -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("")) + .remove(QRegularExpression("]*>[^<]*")) + .remove(QRegularExpression("")) + .remove(QRegularExpression("
    ]*>×
    ")) .replace(QRegularExpression("]*>"), "\n") .remove(QRegularExpression("<[^>]*>")) .trimmed()); diff --git a/src/lyrics/lyricsmodecomlyricsprovider.cpp b/src/lyrics/lyricsmodecomlyricsprovider.cpp new file mode 100644 index 00000000..d4a2fcba --- /dev/null +++ b/src/lyrics/lyricsmodecomlyricsprovider.cpp @@ -0,0 +1,54 @@ +/* + * Strawberry Music Player + * Copyright 2023, Jonas Kvinge + * + * 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 . + * + */ + +#include +#include +#include +#include +#include +#include + +#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[] = "]*>"; +const char LyricsModeComLyricsProvider::kEndTag[] = "<\\/div>"; +const char LyricsModeComLyricsProvider::kLyricsStart[] = "
    ]*>"; + +LyricsModeComLyricsProvider::LyricsModeComLyricsProvider(SharedPtr 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(); + +} diff --git a/src/lyrics/lyricsmodecomlyricsprovider.h b/src/lyrics/lyricsmodecomlyricsprovider.h new file mode 100644 index 00000000..55021d82 --- /dev/null +++ b/src/lyrics/lyricsmodecomlyricsprovider.h @@ -0,0 +1,54 @@ +/* + * Strawberry Music Player + * Copyright 2023, Jonas Kvinge + * + * 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 . + * + */ + +#ifndef LYRICSMODECOMLYRICSPROVIDER_H +#define LYRICSMODECOMLYRICSPROVIDER_H + +#include +#include +#include +#include +#include +#include + +#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 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