Download lyrics from MPD server via HTTP
This commit is contained in:
committed by
craig.p.drummond
parent
568aa4946e
commit
ceeaad08a1
@@ -94,6 +94,8 @@
|
||||
had this)
|
||||
55. Hack-around size of QComboBox in page classes so that height is same as
|
||||
buttons. (QGtkStyle only)
|
||||
56. Support reading of lyrics from HTTP server - specify a HTTP url as MPD
|
||||
music path.
|
||||
|
||||
0.9.2
|
||||
-----
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "utils.h"
|
||||
#include "action.h"
|
||||
#include "actioncollection.h"
|
||||
#include "networkaccessmanager.h"
|
||||
#include <QFuture>
|
||||
#include <QFutureWatcher>
|
||||
#include <QSettings>
|
||||
@@ -72,6 +73,7 @@ LyricsPage::LyricsPage(QWidget *p)
|
||||
// , reader(new UltimateLyricsReader(this))
|
||||
, currentRequest(0)
|
||||
, mode(Mode_Display)
|
||||
, job(0)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
@@ -294,29 +296,31 @@ void LyricsPage::update(const Song &s, bool force)
|
||||
songFile=u.hasQueryItem("file") ? u.queryItemValue("file") : QString();
|
||||
}
|
||||
|
||||
#ifdef TAGLIB_FOUND
|
||||
QString tagLyrics=Tags::readLyrics(MPDConnection::self()->getDetails().dir+songFile);
|
||||
|
||||
if (!tagLyrics.isEmpty()) {
|
||||
text->setText(tagLyrics);
|
||||
setMode(Mode_Display);
|
||||
controls->setVisible(false);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Check for MPD file...
|
||||
QString mpdLyrics=Utils::changeExtension(MPDConnection::self()->getDetails().dir+songFile, constExtension);
|
||||
|
||||
// if (force && QFile::exists(mpdLyrics)) {
|
||||
// QFile::remove(mpdLyrics);
|
||||
// }
|
||||
|
||||
// Stop here if we found lyrics in the cache dir.
|
||||
if (setLyricsFromFile(mpdLyrics)) {
|
||||
lyricsFile=mpdLyrics;
|
||||
setMode(Mode_Display);
|
||||
if (MPDConnection::self()->getDetails().dir.startsWith(QLatin1String("http:/"))) {
|
||||
QUrl url(mpdLyrics);
|
||||
job=NetworkAccessManager::self()->get(url);
|
||||
job->setProperty("file", songFile);
|
||||
connect(job, SIGNAL(finished()), SLOT(downloadFinished()));
|
||||
return;
|
||||
} else {
|
||||
#ifdef TAGLIB_FOUND
|
||||
QString tagLyrics=Tags::readLyrics(MPDConnection::self()->getDetails().dir+songFile);
|
||||
|
||||
if (!tagLyrics.isEmpty()) {
|
||||
text->setText(tagLyrics);
|
||||
setMode(Mode_Display);
|
||||
controls->setVisible(false);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
// Stop here if we found lyrics in the cache dir.
|
||||
if (setLyricsFromFile(mpdLyrics)) {
|
||||
lyricsFile=mpdLyrics;
|
||||
setMode(Mode_Display);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,6 +347,26 @@ void LyricsPage::update(const Song &s, bool force)
|
||||
}
|
||||
}
|
||||
|
||||
void LyricsPage::downloadFinished()
|
||||
{
|
||||
QNetworkReply *reply=qobject_cast<QNetworkReply *>(sender());
|
||||
if (reply) {
|
||||
reply->deleteLater();
|
||||
if (QNetworkReply::NoError==reply->error()) {
|
||||
QString file=reply->property("file").toString();
|
||||
if (!file.isEmpty() && file==currentSong.file) {
|
||||
QTextStream str(reply);
|
||||
QString lyrics=str.readAll();
|
||||
if (!lyrics.isEmpty()) {
|
||||
text->setText(lyrics);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
getLyrics();
|
||||
}
|
||||
|
||||
void LyricsPage::resultReady(int id, const QString &lyrics)
|
||||
{
|
||||
if (id != currentRequest)
|
||||
|
||||
@@ -35,6 +35,7 @@ class UltimateLyricsProvider;
|
||||
class UltimateLyricsProvider;
|
||||
class QImage;
|
||||
class Action;
|
||||
class QNetworkReply;
|
||||
|
||||
class LyricsPage : public QWidget, public Ui::LyricsPage
|
||||
{
|
||||
@@ -67,6 +68,7 @@ public Q_SLOTS:
|
||||
void setImage(const QImage &img) { text->setImage(img); }
|
||||
|
||||
protected Q_SLOTS:
|
||||
void downloadFinished();
|
||||
void resultReady(int id, const QString &lyrics);
|
||||
void update();
|
||||
void search();
|
||||
@@ -111,6 +113,7 @@ private:
|
||||
Mode mode;
|
||||
QString lyricsFile;
|
||||
QString preEdit;
|
||||
QNetworkReply *job;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user