Commit 2c1c09eb authored by Andrea Scarpino's avatar Andrea Scarpino

LyricsWiki API has been officially dropped

parent 64d8bd85
......@@ -52,9 +52,9 @@ LyricsWikiAPI::~LyricsWikiAPI()
delete network;
}
void LyricsWikiAPI::getLyricBypassApi(const QString &artist, const QString &song)
void LyricsWikiAPI::getLyric(const QString &artist, const QString &song)
{
qDebug() << "Requesting lyric bypassing APIs for artist" << artist << ", song" << song;
qDebug() << "Requesting lyric for artist" << artist << ", song" << song;
QUrl url(QStringLiteral("http://lyrics.wikia.com"));
......@@ -74,29 +74,6 @@ void LyricsWikiAPI::getLyricBypassApi(const QString &artist, const QString &song
lyric->setSong(song);
lyrics.insert(reply, lyric);
connect(reply, &QNetworkReply::finished, this, &LyricsWikiAPI::onGetLyricPageResult);
}
void LyricsWikiAPI::getLyric(const QString &artist, const QString &song)
{
qDebug() << "Requesting lyric for artist" << artist << ", song" << song;
QUrl url(API_URL);
QString artNoSpaces(artist);
artNoSpaces.replace(QChar::Space, QChar::fromLatin1('_'));
QString songNoSpaces(song);
songNoSpaces.replace(QChar::Space, QChar::fromLatin1('_'));
QUrlQuery query;
query.addQueryItem(QStringLiteral("func"), QStringLiteral("getSong"));
query.addQueryItem(QStringLiteral("artist"), artNoSpaces);
query.addQueryItem(QStringLiteral("song"), songNoSpaces);
query.addQueryItem(QStringLiteral("fmt"), QStringLiteral("realjson"));
url.setQuery(query);
QNetworkRequest req(url);
QNetworkReply* reply = network->get(req);
connect(reply, &QNetworkReply::finished, this, &LyricsWikiAPI::onGetLyricResult);
}
......@@ -104,44 +81,6 @@ void LyricsWikiAPI::onGetLyricResult()
{
QNetworkReply* reply = qobject_cast<QNetworkReply*>(QObject::sender());
bool err = true;
if (reply->error() != QNetworkReply::NoError) {
qCritical() << "Cannot fetch lyric";
} else {
QJsonDocument json = QJsonDocument::fromJson(reply->readAll());
if (!json.isNull()) {
qDebug() << "Got lyric JSON";
QJsonObject jsonObj = json.object();
if (jsonObj.value("lyrics").toString().compare(QStringLiteral("Not found")) != 0) {
Lyric* lyric = new Lyric();
lyric->setArtist(jsonObj.value("artist").toString());
lyric->setSong(jsonObj.value("song").toString());
const QUrl url(jsonObj.value("url").toString());
getLyricText(url, lyric);
err = false;
} else {
qDebug() << "No lyric found";
}
} else {
qCritical() << "Got an invalid JSON!";
}
}
if (err) {
Q_EMIT lyricFetched(0, !err);
}
reply->deleteLater();
}
void LyricsWikiAPI::onGetLyricPageResult()
{
QNetworkReply* reply = qobject_cast<QNetworkReply*>(QObject::sender());
bool found = false;
Lyric* lyric = 0;
......@@ -179,13 +118,3 @@ void LyricsWikiAPI::onGetLyricPageResult()
reply->deleteLater();
}
void LyricsWikiAPI::getLyricText(const QUrl &url, Lyric *lyric)
{
qDebug() << "Requesting lyric page" << url.url();
QNetworkRequest req(url);
QNetworkReply* reply = network->get(req);
lyrics.insert(reply, lyric);
connect(reply, &QNetworkReply::finished, this, &LyricsWikiAPI::onGetLyricPageResult);
}
......@@ -42,15 +42,12 @@ public:
virtual ~LyricsWikiAPI();
void getLyric(const QString &artist, const QString &song);
void getLyricBypassApi(const QString &artist, const QString &song);
Q_SIGNALS:
void lyricFetched(Lyric *lyric, const bool &found);
private:
void onGetLyricResult();
void onGetLyricPageResult();
void getLyricText(const QUrl &url, Lyric *lyric);
QNetworkAccessManager *network;
QMap<QNetworkReply*, Lyric*> lyrics;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment