aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/General/lyrics/lyricswindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/General/lyrics/lyricswindow.cpp')
-rw-r--r--src/plugins/General/lyrics/lyricswindow.cpp45
1 files changed, 44 insertions, 1 deletions
diff --git a/src/plugins/General/lyrics/lyricswindow.cpp b/src/plugins/General/lyrics/lyricswindow.cpp
index 1ef17718a..836faa866 100644
--- a/src/plugins/General/lyrics/lyricswindow.cpp
+++ b/src/plugins/General/lyrics/lyricswindow.cpp
@@ -20,6 +20,7 @@
#include <QHttp>
#include <QUrl>
+#include <QRegExp>
#include <qmmp/qmmp.h>
#include "lyricswindow.h"
@@ -27,6 +28,7 @@
LyricsWindow::LyricsWindow(const QString &artist, const QString &title, QWidget *parent)
: QWidget(parent)
{
+ m_parse_url = FALSE;
ui.setupUi(this);
setWindowFlags(Qt::Dialog);
setAttribute(Qt::WA_DeleteOnClose);
@@ -54,9 +56,49 @@ LyricsWindow::~LyricsWindow()
void LyricsWindow::showText(bool error)
{
if (error)
+ {
ui.textEdit->setText(m_http->errorString());
+ m_parse_url = FALSE;
+ return;
+ }
+ QString content = QString::fromUtf8(m_http->readAll().constData());
+ if(m_parse_url)
+ {
+ QRegExp url_regexp("<a href=\\'([^\\']*)\\' title=\\'url\\'>");
+ if(url_regexp.indexIn(content) > 1)
+ {
+ QString url = qPrintable(url_regexp.cap(1));
+ qDebug("LyricsWindow: url=%s", qPrintable(url));
+ if(url.endsWith("action=edit"))
+ ui.textEdit->setHtml("<b>"+tr("Not found")+"</b>");
+ else
+ m_http->get(url);
+ }
+ else
+ ui.textEdit->setHtml("<b>"+tr("Error")+"</b>");
+ }
else
- ui.textEdit->setHtml(QString::fromUtf8(m_http->readAll().constData()));
+ {
+ QRegExp caption_regexp("<h1 class=\\\"firstHeading\\\">([^<]*)</h1>");
+ caption_regexp.indexIn(content);
+ QString text = "<h2>" + caption_regexp.cap(1) + "</h2>";
+ text.replace(":", " - ");
+ int lyric_begin = content.indexOf("<div class='lyricbox' >");
+ if(lyric_begin > 0)
+ {
+ int lyric_end = content.indexOf("</div>", lyric_begin);
+ if(lyric_end > 0)
+ {
+ text.append(content.mid(lyric_begin, lyric_end - lyric_begin-6));
+ ui.textEdit->setHtml(text);
+ }
+ else
+ ui.textEdit->setHtml("<b>"+tr("Error")+"</b>");
+ }
+ else
+ ui.textEdit->setHtml("<b>"+tr("Error")+"</b>");
+ }
+ m_parse_url = FALSE;
}
void LyricsWindow::showState(int state)
@@ -91,4 +133,5 @@ void LyricsWindow::on_searchPushButton_clicked()
setWindowTitle(QString(tr("Lyrics: %1 - %2")).arg(ui.artistLineEdit->text()).arg(ui.titleLineEdit->text()));
m_http->get("/api.php?func=getSong&artist=" + QUrl::toPercentEncoding(ui.artistLineEdit->text())
+"&song=" + QUrl::toPercentEncoding(ui.titleLineEdit->text()) +"&fmt=html");
+ m_parse_url = TRUE;
}