1
0
mirror of https://github.com/strawberrymusicplayer/strawberry synced 2025-02-03 10:57:33 +01:00

Decode HTML entities in lyrics

This commit is contained in:
Jonas Kvinge 2021-01-11 16:05:39 +01:00
parent c5cd648b5d
commit b85819ed9d
7 changed files with 21 additions and 6 deletions

View File

@ -650,11 +650,17 @@ QStringList Updateify(const QStringList &list) {
QString DecodeHtmlEntities(const QString &text) {
QString copy(text);
copy.replace("&", "&");
copy.replace(""", "\"");
copy.replace("'", "'");
copy.replace("&lt;", "<");
copy.replace("&gt;", ">");
copy.replace("&amp;", "&")
.replace("&#38;", "&")
.replace("&quot;", "\"")
.replace("&#34;", "\"")
.replace("&apos;", "'")
.replace("&#39;", "'")
.replace("&lt;", "<")
.replace("&#60;", "<")
.replace("&gt;", ">")
.replace("&#62;", ">");
return copy;
}

View File

@ -37,6 +37,7 @@
#include "core/logging.h"
#include "core/network.h"
#include "core/utilities.h"
#include "jsonlyricsprovider.h"
#include "lyricsfetcher.h"
#include "lyricsprovider.h"
@ -129,6 +130,7 @@ void AuddLyricsProvider::HandleSearchReply(QNetworkReply *reply, const quint64 i
if (result.artist.toLower() != artist.toLower() && result.title.toLower() != title.toLower()) continue;
result.lyrics = json_obj["lyrics"].toString();
if (result.lyrics.isEmpty() || result.lyrics.length() > kMaxLength || result.lyrics == "error") continue;
result.lyrics = Utilities::DecodeHtmlEntities(result.lyrics);
//qLog(Debug) << "AudDLyrics:" << result.artist << result.title << result.lyrics.length();

View File

@ -127,6 +127,7 @@ void ChartLyricsProvider::HandleSearchReply(QNetworkReply *reply, const quint64
else if (type == QXmlStreamReader::EndElement) {
if (name == "GetLyricResult") {
if (!result.artist.isEmpty() && !result.title.isEmpty() && !result.lyrics.isEmpty() && (result.artist.toLower() == artist.toLower() || result.title.toLower() == title.toLower())) {
result.lyrics = Utilities::DecodeHtmlEntities(result.lyrics);
results << result;
}
result = LyricsSearchResult();

View File

@ -515,7 +515,7 @@ void GeniusLyricsProvider::HandleLyricReply(QNetworkReply *reply, const int sear
LyricsSearchResult result;
result.artist = lyric.artist;
result.title = lyric.title;
result.lyrics = lyrics;
result.lyrics = Utilities::DecodeHtmlEntities(lyrics);
search->results.append(result);
}

View File

@ -35,6 +35,7 @@
#include "core/logging.h"
#include "core/network.h"
#include "core/utilities.h"
#include "lyricsprovider.h"
#include "lyricsfetcher.h"
#include "lololyricsprovider.h"
@ -137,6 +138,7 @@ void LoloLyricsProvider::HandleSearchReply(QNetworkReply *reply, const quint64 i
else if (type == QXmlStreamReader::EndElement) {
if (name == "result") {
if (!result.lyrics.isEmpty()) {
result.lyrics = Utilities::DecodeHtmlEntities(result.lyrics);
results << result;
}
result = LyricsSearchResult();

View File

@ -34,6 +34,7 @@
#include "core/logging.h"
#include "core/network.h"
#include "core/utilities.h"
#include "jsonlyricsprovider.h"
#include "lyricsfetcher.h"
#include "lyricsprovider.h"
@ -200,6 +201,7 @@ void MusixmatchLyricsProvider::HandleSearchReply(QNetworkReply *reply, const qui
result.lyrics = obj_lyrics["body"].toString();
if (!result.lyrics.isEmpty() && (artist.toLower() == result.artist.toLower() || title.toLower() == result.title.toLower())) {
result.lyrics = Utilities::DecodeHtmlEntities(result.lyrics);
results.append(result);
}

View File

@ -32,6 +32,7 @@
#include "core/logging.h"
#include "core/network.h"
#include "core/utilities.h"
#include "lyricsfetcher.h"
#include "jsonlyricsprovider.h"
#include "ovhlyricsprovider.h"
@ -107,6 +108,7 @@ void OVHLyricsProvider::HandleSearchReply(QNetworkReply *reply, const quint64 id
emit SearchFinished(id, LyricsSearchResults());
}
else {
result.lyrics = Utilities::DecodeHtmlEntities(result.lyrics);
qLog(Debug) << "OVHLyrics: Got lyrics for" << artist << title;
emit SearchFinished(id, LyricsSearchResults() << result);
}