From 877403342c0352bc52d934c787b4e6d251855727 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Fri, 11 Oct 2019 20:11:33 +0000 Subject: lyrics: fixed some parsing issues git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@9089 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/General/lyrics/lyricsprovider.cpp | 47 +++++++++++++++++----- src/plugins/General/lyrics/lyricswindow.cpp | 13 +++++- .../lyrics/providers/ultimate_providers.xml | 8 ++-- 3 files changed, 54 insertions(+), 14 deletions(-) (limited to 'src/plugins/General') diff --git a/src/plugins/General/lyrics/lyricsprovider.cpp b/src/plugins/General/lyrics/lyricsprovider.cpp index 58728ec88..4dae451dd 100644 --- a/src/plugins/General/lyrics/lyricsprovider.cpp +++ b/src/plugins/General/lyrics/lyricsprovider.cpp @@ -92,7 +92,8 @@ QString LyricsProvider::format(const QByteArray &data, const TrackInfo &track) c if(!codec) codec = QTextCodec::codecForName("UTF-8"); - QString content = codec->toUnicode(data); + const QString content = codec->toUnicode(data); + QString out; for(const QString &indicator : qAsConst(m_invalidIndicators)) { @@ -105,6 +106,7 @@ QString LyricsProvider::format(const QByteArray &data, const TrackInfo &track) c for(const Rule &rule : qAsConst(m_extractRules)) { Rule tmpRule = rule; + QString tmpContent = content; for(Item &item : tmpRule) { @@ -117,15 +119,37 @@ QString LyricsProvider::format(const QByteArray &data, const TrackInfo &track) c } } - content = extract(content, rule); + tmpContent = extract(tmpContent, tmpRule); + + if(!tmpContent.isEmpty()) + { + for(const Rule &excludeRule : qAsConst(m_excludeRules)) + tmpContent = exclude(tmpContent, excludeRule); + } + if(tmpContent.isEmpty()) + { + tmpContent = content; + } + else + { + out = tmpContent; + break; + } + } + + while (out.endsWith("
")) + { + out.chop(6); + out = out.trimmed(); } - for(const Rule &rule : qAsConst(m_excludeRules)) + while (out.endsWith("
")) { - content = exclude(content, rule); + out.chop(4); + out = out.trimmed(); } - return content; + return out; } const QString &LyricsProvider::name() const @@ -177,6 +201,7 @@ QString LyricsProvider::extract(const QString &content, const Rule &rule) const for(const Item &item : qAsConst(rule)) { + if(!item.url.isEmpty()) { QString url = item.url; @@ -186,14 +211,16 @@ QString LyricsProvider::extract(const QString &content, const Rule &rule) const } else if(!item.tag.isEmpty()) { - out = out.section(item.tag, 1).section(QString(""); + QRegularExpressionMatch m = re.match(item.tag); + out = out.section(item.tag, 1).section(QString("").arg(m.captured(1)), 0, 0); } else { out = out.section(item.begin, 1).section(item.end, 0, 0); } } - return out; + return out.trimmed(); } QString LyricsProvider::exclude(const QString &content, const LyricsProvider::Rule &rule) const @@ -204,12 +231,14 @@ QString LyricsProvider::exclude(const QString &content, const LyricsProvider::Ru { if(!item.tag.isEmpty()) { - out = out.section(item.tag, 0, 0) + out.section(item.tag, 1).section(QString(""); + QRegularExpressionMatch m = re.match(item.tag); + out = out.section(item.tag, 0, 0) + out.section(item.tag, 1).section(QString("").arg(m.captured(1)), 1); } else { out = out.section(item.begin, 0, 0) + out.section(item.begin, 1).section(item.end, 1); } } - return out; + return out.trimmed(); } diff --git a/src/plugins/General/lyrics/lyricswindow.cpp b/src/plugins/General/lyrics/lyricswindow.cpp index d2ef7cd59..5036bc4c8 100644 --- a/src/plugins/General/lyrics/lyricswindow.cpp +++ b/src/plugins/General/lyrics/lyricswindow.cpp @@ -89,10 +89,12 @@ void LyricsWindow::onRequestFinished(QNetworkReply *reply) if(provider) { QString content = provider->format(data, m_info); + qDebug() << content; if(!content.isEmpty()) { + m_ui.textBrowser->append(QString("%1").arg(provider->name())); m_ui.textBrowser->append(content); - m_ui.textBrowser->append("


"); + m_ui.textBrowser->append("
-------------------------------------
"); } } } @@ -100,6 +102,10 @@ void LyricsWindow::onRequestFinished(QNetworkReply *reply) { m_tasks.insert(m_http->get(QNetworkRequest(redirectTarget.toUrl())), name); } + else + { + qWarning() << "error:" << reply->errorString(); + } reply->deleteLater(); } @@ -110,12 +116,15 @@ void LyricsWindow::on_searchPushButton_clicked() for(LyricsProvider *provider : m_parser.providers()) { + //if(provider->name() == "lyrics.wikia.com") + { QString url = provider->getUrl(m_info); - qDebug() << provider->name(); + qDebug() << provider->name() << url; QNetworkRequest request; request.setUrl(url); request.setRawHeader("User-Agent", QString("qmmp/%1").arg(Qmmp::strVersion()).toLatin1()); m_tasks.insert(m_http->get(request), provider->name()); + } } } diff --git a/src/plugins/General/lyrics/providers/ultimate_providers.xml b/src/plugins/General/lyrics/providers/ultimate_providers.xml index 98a043695..086e75f8b 100644 --- a/src/plugins/General/lyrics/providers/ultimate_providers.xml +++ b/src/plugins/General/lyrics/providers/ultimate_providers.xml @@ -92,10 +92,12 @@ - + + + @@ -133,7 +135,7 @@ - + @@ -295,7 +297,7 @@ - + -- cgit v1.2.3-13-gbd6f