|
|
|
|
@@ -37,16 +37,16 @@
|
|
|
|
|
#include "utilities/strutils.h"
|
|
|
|
|
#include "lyricssearchrequest.h"
|
|
|
|
|
#include "lyricssearchresult.h"
|
|
|
|
|
#include "stands4lyricsprovider.h"
|
|
|
|
|
#include "lyricscomlyricsprovider.h"
|
|
|
|
|
|
|
|
|
|
const char *Stands4LyricsProvider::kApiUrl = "https://www.abbreviations.com/services/v2/lyrics.php";
|
|
|
|
|
const char *Stands4LyricsProvider::kLyricsUrl = "https://www.lyrics.com/lyrics/";
|
|
|
|
|
const char *Stands4LyricsProvider::kUID = "11363";
|
|
|
|
|
const char *Stands4LyricsProvider::kTokenB64 = "b3FOYmxhV1ZKRGxIMnV4OA==";
|
|
|
|
|
const char *LyricsComLyricsProvider::kApiUrl = "https://www.abbreviations.com/services/v2/lyrics.php";
|
|
|
|
|
const char *LyricsComLyricsProvider::kLyricsUrl = "https://www.lyrics.com/lyrics/";
|
|
|
|
|
const char *LyricsComLyricsProvider::kUID = "11363";
|
|
|
|
|
const char *LyricsComLyricsProvider::kTokenB64 = "b3FOYmxhV1ZKRGxIMnV4OA==";
|
|
|
|
|
|
|
|
|
|
Stands4LyricsProvider::Stands4LyricsProvider(NetworkAccessManager *network, QObject *parent) : JsonLyricsProvider("Stands4Lyrics", true, false, network, parent), use_api_(true) {}
|
|
|
|
|
LyricsComLyricsProvider::LyricsComLyricsProvider(NetworkAccessManager *network, QObject *parent) : JsonLyricsProvider("Lyrics.com", true, false, network, parent), use_api_(true) {}
|
|
|
|
|
|
|
|
|
|
Stands4LyricsProvider::~Stands4LyricsProvider() {
|
|
|
|
|
LyricsComLyricsProvider::~LyricsComLyricsProvider() {
|
|
|
|
|
|
|
|
|
|
while (!replies_.isEmpty()) {
|
|
|
|
|
QNetworkReply *reply = replies_.takeFirst();
|
|
|
|
|
@@ -57,7 +57,7 @@ Stands4LyricsProvider::~Stands4LyricsProvider() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Stands4LyricsProvider::StartSearch(const int id, const LyricsSearchRequest &request) {
|
|
|
|
|
bool LyricsComLyricsProvider::StartSearch(const int id, const LyricsSearchRequest &request) {
|
|
|
|
|
|
|
|
|
|
if (use_api_) {
|
|
|
|
|
SendSearchRequest(id, request);
|
|
|
|
|
@@ -70,7 +70,7 @@ bool Stands4LyricsProvider::StartSearch(const int id, const LyricsSearchRequest
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Stands4LyricsProvider::SendSearchRequest(const int id, const LyricsSearchRequest &request) {
|
|
|
|
|
void LyricsComLyricsProvider::SendSearchRequest(const int id, const LyricsSearchRequest &request) {
|
|
|
|
|
|
|
|
|
|
QUrlQuery url_query;
|
|
|
|
|
url_query.addQueryItem(QUrl::toPercentEncoding("uid"), QUrl::toPercentEncoding(kUID));
|
|
|
|
|
@@ -89,9 +89,9 @@ void Stands4LyricsProvider::SendSearchRequest(const int id, const LyricsSearchRe
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Stands4LyricsProvider::CancelSearch(const int id) { Q_UNUSED(id); }
|
|
|
|
|
void LyricsComLyricsProvider::CancelSearch(const int id) { Q_UNUSED(id); }
|
|
|
|
|
|
|
|
|
|
void Stands4LyricsProvider::HandleSearchReply(QNetworkReply *reply, const int id, const LyricsSearchRequest &request) {
|
|
|
|
|
void LyricsComLyricsProvider::HandleSearchReply(QNetworkReply *reply, const int id, const LyricsSearchRequest &request) {
|
|
|
|
|
|
|
|
|
|
if (!replies_.contains(reply)) return;
|
|
|
|
|
replies_.removeAll(reply);
|
|
|
|
|
@@ -108,54 +108,54 @@ void Stands4LyricsProvider::HandleSearchReply(QNetworkReply *reply, const int id
|
|
|
|
|
QJsonDocument json_doc = QJsonDocument::fromJson(data, &json_error);
|
|
|
|
|
|
|
|
|
|
if (json_error.error != QJsonParseError::NoError) {
|
|
|
|
|
qLog(Error) << "Stands4Lyrics: Failed to parse json data" << json_error.errorString();
|
|
|
|
|
qLog(Error) << "Lyrics.com: Failed to parse json data" << json_error.errorString();
|
|
|
|
|
emit SearchFinished(id);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (json_doc.isEmpty()) {
|
|
|
|
|
qLog(Debug) << "Stands4Lyrics: No lyrics for" << request.artist << request.album << request.title;
|
|
|
|
|
qLog(Debug) << "Lyrics.com: No lyrics for" << request.artist << request.album << request.title;
|
|
|
|
|
emit SearchFinished(id);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!json_doc.isObject()) {
|
|
|
|
|
qLog(Error) << "Stands4Lyrics: Json document is not an object.";
|
|
|
|
|
qLog(Error) << "Lyrics.com: Json document is not an object.";
|
|
|
|
|
emit SearchFinished(id);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QJsonObject json_obj = json_doc.object();
|
|
|
|
|
if (json_obj.isEmpty()) {
|
|
|
|
|
qLog(Debug) << "Stands4Lyrics: No lyrics for" << request.artist << request.album << request.title;
|
|
|
|
|
qLog(Debug) << "Lyrics.com: No lyrics for" << request.artist << request.album << request.title;
|
|
|
|
|
emit SearchFinished(id);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (json_obj.contains("error")) {
|
|
|
|
|
const QString error = json_obj["error"].toString();
|
|
|
|
|
qLog(Error) << "Stands4Lyrics: Received error:" << error << "switching to URL based lookup.";
|
|
|
|
|
qLog(Error) << "Lyrics.com: Received error:" << error << "switching to URL based lookup.";
|
|
|
|
|
use_api_ = false;
|
|
|
|
|
CreateLyricsRequest(id, request);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!json_obj.contains("result") || !json_obj["result"].isArray()) {
|
|
|
|
|
qLog(Error) << "Stands4Lyrics: Json reply is missing result.";
|
|
|
|
|
qLog(Error) << "Lyrics.com: Json reply is missing result.";
|
|
|
|
|
emit SearchFinished(id);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QJsonArray json_result = json_obj["result"].toArray();
|
|
|
|
|
if (json_result.isEmpty()) {
|
|
|
|
|
qLog(Debug) << "Stands4Lyrics: No lyrics for" << request.artist << request.album << request.title;
|
|
|
|
|
qLog(Debug) << "Lyrics.com: No lyrics for" << request.artist << request.album << request.title;
|
|
|
|
|
emit SearchFinished(id);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const QJsonValueRef value : json_result) {
|
|
|
|
|
if (!value.isObject()) {
|
|
|
|
|
qLog(Error) << "Stands4Lyrics: Invalid Json reply, result is not an object.";
|
|
|
|
|
qLog(Error) << "Lyrics.com: Invalid Json reply, result is not an object.";
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
QJsonObject obj = value.toObject();
|
|
|
|
|
@@ -165,7 +165,7 @@ void Stands4LyricsProvider::HandleSearchReply(QNetworkReply *reply, const int id
|
|
|
|
|
!obj.contains("album") ||
|
|
|
|
|
!obj.contains("song-link")
|
|
|
|
|
) {
|
|
|
|
|
qLog(Error) << "Stands4Lyrics: Invalid Json reply, result is missing data.";
|
|
|
|
|
qLog(Error) << "Lyrics.com: Invalid Json reply, result is missing data.";
|
|
|
|
|
qLog(Debug) << value;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
@@ -198,18 +198,18 @@ void Stands4LyricsProvider::HandleSearchReply(QNetworkReply *reply, const int id
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qLog(Debug) << "Stands4Lyrics: No lyrics for" << request.artist << request.album << request.title;
|
|
|
|
|
qLog(Debug) << "Lyrics.com: No lyrics for" << request.artist << request.album << request.title;
|
|
|
|
|
emit SearchFinished(id);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Stands4LyricsProvider::CreateLyricsRequest(const int id, const LyricsSearchRequest &request) {
|
|
|
|
|
void LyricsComLyricsProvider::CreateLyricsRequest(const int id, const LyricsSearchRequest &request) {
|
|
|
|
|
|
|
|
|
|
SendLyricsRequest(id, request, request.artist, request.album, request.title);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Stands4LyricsProvider::SendLyricsRequest(const int id, const LyricsSearchRequest &request, const QString &result_artist, const QString &result_album, const QString &result_title, QUrl url) {
|
|
|
|
|
void LyricsComLyricsProvider::SendLyricsRequest(const int id, const LyricsSearchRequest &request, const QString &result_artist, const QString &result_album, const QString &result_title, QUrl url) {
|
|
|
|
|
|
|
|
|
|
if (url.isEmpty() || !url.isValid()) {
|
|
|
|
|
url.setUrl(kLyricsUrl + StringFixup(result_artist) + "/" + StringFixup(result_title) + ".html");
|
|
|
|
|
@@ -223,7 +223,7 @@ void Stands4LyricsProvider::SendLyricsRequest(const int id, const LyricsSearchRe
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Stands4LyricsProvider::HandleLyricsReply(QNetworkReply *reply, const int id, const LyricsSearchRequest &request, const QString &result_artist, const QString &result_album, const QString &result_title) {
|
|
|
|
|
void LyricsComLyricsProvider::HandleLyricsReply(QNetworkReply *reply, const int id, const LyricsSearchRequest &request, const QString &result_artist, const QString &result_album, const QString &result_title) {
|
|
|
|
|
|
|
|
|
|
if (!replies_.contains(reply)) return;
|
|
|
|
|
replies_.removeAll(reply);
|
|
|
|
|
@@ -243,19 +243,19 @@ void Stands4LyricsProvider::HandleLyricsReply(QNetworkReply *reply, const int id
|
|
|
|
|
|
|
|
|
|
const QByteArray data = reply->readAll();
|
|
|
|
|
if (data.isEmpty()) {
|
|
|
|
|
qLog(Error) << "Stands4Lyrics: Empty reply received from server.";
|
|
|
|
|
qLog(Error) << "Lyrics.com: Empty reply received from server.";
|
|
|
|
|
emit SearchFinished(id);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString lyrics = ParseLyricsFromHTML(QString::fromUtf8(data), QRegularExpression("<div[^>]*>"), QRegularExpression("<\\/div>"), QRegularExpression("<div id=\"lyrics\"[^>]+>"), false);
|
|
|
|
|
if (lyrics.isEmpty() || lyrics.contains("Click to search for the Lyrics on Lyrics.com", Qt::CaseInsensitive)) {
|
|
|
|
|
qLog(Debug) << "Stands4Lyrics: No lyrics for" << request.artist << request.album << request.title;
|
|
|
|
|
qLog(Debug) << "Lyrics.com: No lyrics for" << request.artist << request.album << request.title;
|
|
|
|
|
emit SearchFinished(id);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qLog(Debug) << "Stands4Lyrics: Got lyrics for" << request.artist << request.album << request.title;
|
|
|
|
|
qLog(Debug) << "Lyrics.com: Got lyrics for" << request.artist << request.album << request.title;
|
|
|
|
|
|
|
|
|
|
LyricsSearchResult result(lyrics);
|
|
|
|
|
result.artist = result_artist;
|
|
|
|
|
@@ -265,7 +265,7 @@ void Stands4LyricsProvider::HandleLyricsReply(QNetworkReply *reply, const int id
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString Stands4LyricsProvider::StringFixup(QString string) {
|
|
|
|
|
QString LyricsComLyricsProvider::StringFixup(QString string) {
|
|
|
|
|
|
|
|
|
|
return string.replace('/', '-')
|
|
|
|
|
.replace('\'', '-')
|
|
|
|
|
@@ -277,9 +277,9 @@ QString Stands4LyricsProvider::StringFixup(QString string) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Stands4LyricsProvider::Error(const QString &error, const QVariant &debug) {
|
|
|
|
|
void LyricsComLyricsProvider::Error(const QString &error, const QVariant &debug) {
|
|
|
|
|
|
|
|
|
|
qLog(Error) << "Stands4Lyrics:" << error;
|
|
|
|
|
qLog(Error) << "Lyrics.com:" << error;
|
|
|
|
|
if (debug.isValid()) qLog(Debug) << debug;
|
|
|
|
|
|
|
|
|
|
}
|