Improve lyrics providers
This commit is contained in:
parent
9014781336
commit
e62fb964ff
@ -68,11 +68,13 @@ bool APISeedsLyricsProvider::StartSearch(const QString &artist, const QString &a
|
||||
url_query.addQueryItem(encoded_arg.first, encoded_arg.second);
|
||||
}
|
||||
|
||||
QUrl url(QString("%1/%2/%3").arg(kUrlSearch).arg(artist).arg(title));
|
||||
QUrl url(QString("%1/%2/%3").arg(kUrlSearch).arg(QString::fromLatin1(QUrl::toPercentEncoding(artist))).arg(QString::fromLatin1(QUrl::toPercentEncoding(title))));
|
||||
url.setQuery(url_query);
|
||||
QNetworkReply *reply = network_->get(QNetworkRequest(url));
|
||||
NewClosure(reply, SIGNAL(finished()), this, SLOT(HandleSearchReply(QNetworkReply*, quint64, QString, QString)), reply, id, artist, title);
|
||||
|
||||
|
||||
//qLog(Debug) << "APISeedsLyrics: Sending request for" << url;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
@ -107,6 +109,8 @@ void APISeedsLyricsProvider::HandleSearchReply(QNetworkReply *reply, quint64 id,
|
||||
if (result.artist.toLower() == artist.toLower()) result.score += 1.0;
|
||||
if (result.title.toLower() == title.toLower()) result.score += 1.0;
|
||||
|
||||
//qLog(Debug) << "APISeedsLyrics:" << result.artist << result.title << result.lyrics;
|
||||
|
||||
results << result;
|
||||
|
||||
emit SearchFinished(id, results);
|
||||
@ -155,7 +159,7 @@ QJsonObject APISeedsLyricsProvider::ExtractResult(QNetworkReply *reply, quint64
|
||||
|
||||
QJsonObject json_obj = ExtractJsonObj(reply, id);
|
||||
if (json_obj.isEmpty()) return QJsonObject();
|
||||
|
||||
|
||||
if (json_obj.contains("error")) {
|
||||
Error(id, json_obj["error"].toString(), json_obj);
|
||||
return QJsonObject();
|
||||
|
@ -49,6 +49,7 @@
|
||||
|
||||
const char *AuddLyricsProvider::kUrlSearch = "https://api.audd.io/findLyrics/";
|
||||
const char *AuddLyricsProvider::kAPITokenB64 = "ZjA0NjQ4YjgyNDM3ZTc1MjY3YjJlZDI5ZDBlMzQxZjk=";
|
||||
const int AuddLyricsProvider::kMaxLength = 6000;
|
||||
|
||||
AuddLyricsProvider::AuddLyricsProvider(QObject *parent) : LyricsProvider("AudD", parent), network_(new NetworkAccessManager(this)) {}
|
||||
|
||||
@ -78,6 +79,8 @@ bool AuddLyricsProvider::StartSearch(const QString &artist, const QString &album
|
||||
QNetworkReply *reply = network_->get(QNetworkRequest(url));
|
||||
NewClosure(reply, SIGNAL(finished()), this, SLOT(HandleSearchReply(QNetworkReply*, quint64, QString, QString)), reply, id, artist, title);
|
||||
|
||||
//qLog(Debug) << "AudDLyrics: Sending request for" << url;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
@ -97,7 +100,7 @@ void AuddLyricsProvider::HandleSearchReply(QNetworkReply *reply, quint64 id, con
|
||||
LyricsSearchResults results;
|
||||
for (const QJsonValue &value : json_result) {
|
||||
if (!value.isObject()) {
|
||||
qLog(Error) << "AuddLyrics: Invalid Json reply, result is not an object.";
|
||||
qLog(Error) << "AudDLyrics: Invalid Json reply, result is not an object.";
|
||||
qLog(Debug) << value;
|
||||
continue;
|
||||
}
|
||||
@ -109,7 +112,7 @@ void AuddLyricsProvider::HandleSearchReply(QNetworkReply *reply, quint64 id, con
|
||||
!json_obj.contains("artist") ||
|
||||
!json_obj.contains("lyrics")
|
||||
) {
|
||||
qLog(Error) << "AuddLyrics: Invalid Json reply, result is missing data.";
|
||||
qLog(Error) << "AudDLyrics: Invalid Json reply, result is missing data.";
|
||||
qLog(Debug) << value;
|
||||
continue;
|
||||
}
|
||||
@ -117,9 +120,12 @@ void AuddLyricsProvider::HandleSearchReply(QNetworkReply *reply, quint64 id, con
|
||||
result.artist = json_obj["artist"].toString();
|
||||
result.title = json_obj["title"].toString();
|
||||
result.lyrics = json_obj["lyrics"].toString();
|
||||
if (result.lyrics.length() > kMaxLength) continue;
|
||||
if (result.lyrics == "error") continue;
|
||||
result.score = 0.0;
|
||||
if (result.artist.toLower() == artist.toLower()) result.score += 1.0;
|
||||
if (result.title.toLower() == title.toLower()) result.score += 1.0;
|
||||
//qLog(Debug) << "AudDLyrics:" << result.artist << result.title << result.lyrics.length();
|
||||
|
||||
results << result;
|
||||
}
|
||||
@ -208,7 +214,7 @@ QJsonArray AuddLyricsProvider::ExtractResult(QNetworkReply *reply, quint64 id) {
|
||||
}
|
||||
|
||||
void AuddLyricsProvider::Error(quint64 id, QString error, QVariant debug) {
|
||||
qLog(Error) << "AuddLyrics:" << error;
|
||||
qLog(Error) << "AudDLyrics:" << error;
|
||||
if (debug.isValid()) qLog(Debug) << debug;
|
||||
LyricsSearchResults results;
|
||||
emit SearchFinished(id, results);
|
||||
|
@ -49,6 +49,7 @@ class AuddLyricsProvider : public LyricsProvider {
|
||||
private:
|
||||
static const char *kUrlSearch;
|
||||
static const char *kAPITokenB64;
|
||||
static const int kMaxLength;
|
||||
QNetworkAccessManager *network_;
|
||||
void Error(quint64 id, QString error, QVariant debug = QVariant());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user