From e46b92dd7d65a099c69af846bf8d2882aca7e495 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sat, 15 Oct 2022 14:34:09 +0200 Subject: [PATCH] GeniusLyricsProvider: Use new function for parsing HTML --- src/lyrics/geniuslyricsprovider.cpp | 44 ++++------------------------- 1 file changed, 5 insertions(+), 39 deletions(-) diff --git a/src/lyrics/geniuslyricsprovider.cpp b/src/lyrics/geniuslyricsprovider.cpp index fe608873f..f877e08d0 100644 --- a/src/lyrics/geniuslyricsprovider.cpp +++ b/src/lyrics/geniuslyricsprovider.cpp @@ -478,52 +478,18 @@ void GeniusLyricsProvider::HandleLyricReply(QNetworkReply *reply, const int sear EndSearch(search, lyric); return; } - QString content = data; - // Extract the lyrics from HTML. - - QString tag_begin = "
"; - QString tag_end = "
"; - qint64 begin_idx = content.indexOf(tag_begin); - QString lyrics; - if (begin_idx > 0) { - begin_idx += tag_begin.length(); - qint64 end_idx = content.indexOf(tag_end, begin_idx); - if (end_idx > 0) { - QString text = content.mid(begin_idx, end_idx - begin_idx); - text = text.replace(QRegularExpression("]+>"), "\n"); - text = text.remove(QRegularExpression("<[^>]*>")); - text = text.trimmed(); - if (text.length() < 6000) { - lyrics = text; - } - } - } - else { - QRegularExpressionMatch rematch = QRegularExpression("
]+>").match(content); - if (rematch.hasMatch()) { - begin_idx = content.indexOf(rematch.captured()); - if (begin_idx > 0) { - begin_idx += rematch.captured().length(); - qint64 end_idx = content.indexOf("
", begin_idx + rematch.captured().length()); - if (end_idx > 0) { - QString text = content.mid(begin_idx, end_idx - begin_idx); - text = text.replace(QRegularExpression("]+>"), "\n"); - text = text.remove(QRegularExpression("<[^>]*>")); - text = text.trimmed(); - if (text.length() < 6000 && !text.contains("there are no lyrics to", Qt::CaseInsensitive)) { - lyrics = text; - } - } - } - } + QString content = QString::fromUtf8(data); + QString lyrics = ParseLyricsFromHTML(content, QRegularExpression("]*>"), QRegularExpression("<\\/div>"), QRegularExpression("
]+>")); + if (lyrics.isEmpty()) { + lyrics = ParseLyricsFromHTML(content, QRegularExpression("]*>"), QRegularExpression("<\\/div>"), QRegularExpression("
")); } if (!lyrics.isEmpty()) { LyricsSearchResult result; result.artist = lyric.artist; result.title = lyric.title; - result.lyrics = Utilities::DecodeHtmlEntities(lyrics); + result.lyrics = lyrics; search->results.append(result); }