Lyrics: Refactor
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2020-2022, Jonas Kvinge <jonas@jkvinge.net>
|
||||
* Copyright 2020-2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -56,17 +56,6 @@ constexpr char kApiKey[] = "Y2FhMDRlN2Y4OWE5OTIxYmZlOGMzOWQzOGI3ZGU4MjE=";
|
||||
|
||||
MusixmatchLyricsProvider::MusixmatchLyricsProvider(const SharedPtr<NetworkAccessManager> network, QObject *parent) : JsonLyricsProvider(u"Musixmatch"_s, true, false, network, parent), use_api_(true) {}
|
||||
|
||||
MusixmatchLyricsProvider::~MusixmatchLyricsProvider() {
|
||||
|
||||
while (!replies_.isEmpty()) {
|
||||
QNetworkReply *reply = replies_.takeFirst();
|
||||
QObject::disconnect(reply, nullptr, this, nullptr);
|
||||
reply->abort();
|
||||
reply->deleteLater();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MusixmatchLyricsProvider::StartSearch(const int id, const LyricsSearchRequest &request) {
|
||||
|
||||
Q_ASSERT(QThread::currentThread() != qApp->thread());
|
||||
@@ -87,18 +76,13 @@ void MusixmatchLyricsProvider::StartSearch(const int id, const LyricsSearchReque
|
||||
|
||||
bool MusixmatchLyricsProvider::SendSearchRequest(LyricsSearchContextPtr search) {
|
||||
|
||||
const QUrl url(QLatin1String(kApiUrl) + "/track.search"_L1);
|
||||
QUrlQuery url_query;
|
||||
url_query.addQueryItem(u"apikey"_s, QString::fromLatin1(QByteArray::fromBase64(kApiKey)));
|
||||
url_query.addQueryItem(u"q_artist"_s, QString::fromLatin1(QUrl::toPercentEncoding(search->request.artist)));
|
||||
url_query.addQueryItem(u"q_track"_s, QString::fromLatin1(QUrl::toPercentEncoding(search->request.title)));
|
||||
url_query.addQueryItem(u"f_has_lyrics"_s, u"1"_s);
|
||||
|
||||
QUrl url(QString::fromLatin1(kApiUrl) + u"/track.search"_s);
|
||||
url.setQuery(url_query);
|
||||
QNetworkRequest req(url);
|
||||
req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
|
||||
QNetworkReply *reply = network_->get(req);
|
||||
replies_ << reply;
|
||||
QNetworkReply *reply = CreateGetRequest(url, url_query);
|
||||
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, search]() { HandleSearchReply(reply, search); });
|
||||
|
||||
qLog(Debug) << "MusixmatchLyrics: Sending request for" << url;
|
||||
@@ -107,71 +91,121 @@ bool MusixmatchLyricsProvider::SendSearchRequest(LyricsSearchContextPtr search)
|
||||
|
||||
}
|
||||
|
||||
MusixmatchLyricsProvider::JsonObjectResult MusixmatchLyricsProvider::ParseJsonObject(QNetworkReply *reply) {
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError && reply->error() < 200) {
|
||||
return JsonObjectResult(ErrorCode::NetworkError, QStringLiteral("%1 (%2)").arg(reply->errorString()).arg(reply->error()));
|
||||
}
|
||||
|
||||
JsonObjectResult result(ErrorCode::Success);
|
||||
result.network_error = reply->error();
|
||||
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).isValid()) {
|
||||
result.http_status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
}
|
||||
|
||||
const QByteArray data = reply->readAll();
|
||||
if (!data.isEmpty()) {
|
||||
QJsonParseError json_parse_error;
|
||||
const QJsonDocument json_document = QJsonDocument::fromJson(data, &json_parse_error);
|
||||
if (json_parse_error.error == QJsonParseError::NoError) {
|
||||
const QJsonObject json_object = json_document.object();
|
||||
if (json_object.contains("errors"_L1) && json_object["errors"_L1].isArray()) {
|
||||
const QJsonArray array_errors = json_object["errors"_L1].toArray();
|
||||
for (const auto &value : array_errors) {
|
||||
if (!value.isObject()) continue;
|
||||
const QJsonObject object_error = value.toObject();
|
||||
if (!object_error.contains("category"_L1) || !object_error.contains("code"_L1) || !object_error.contains("detail"_L1)) {
|
||||
continue;
|
||||
}
|
||||
const QString category = object_error["category"_L1].toString();
|
||||
const QString code = object_error["code"_L1].toString();
|
||||
const QString detail = object_error["detail"_L1].toString();
|
||||
result.error_code = ErrorCode::APIError;
|
||||
result.error_message = QStringLiteral("%1 (%2) (%3)").arg(category, code, detail);
|
||||
}
|
||||
}
|
||||
else {
|
||||
result.json_object = json_document.object();
|
||||
}
|
||||
}
|
||||
else {
|
||||
result.error_code = ErrorCode::ParseError;
|
||||
result.error_message = json_parse_error.errorString();
|
||||
}
|
||||
}
|
||||
|
||||
if (result.error_code != ErrorCode::APIError) {
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
result.error_code = ErrorCode::NetworkError;
|
||||
result.error_message = QStringLiteral("%1 (%2)").arg(reply->errorString()).arg(reply->error());
|
||||
}
|
||||
else if (result.http_status_code != 200) {
|
||||
result.error_code = ErrorCode::HttpError;
|
||||
result.error_message = QStringLiteral("Received HTTP code %1").arg(result.http_status_code);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
void MusixmatchLyricsProvider::HandleSearchReply(QNetworkReply *reply, LyricsSearchContextPtr search) {
|
||||
|
||||
Q_ASSERT(QThread::currentThread() != qApp->thread());
|
||||
|
||||
const QScopeGuard end_search = qScopeGuard([this, search]() { EndSearch(search); });
|
||||
|
||||
if (!replies_.contains(reply)) return;
|
||||
replies_.removeAll(reply);
|
||||
QObject::disconnect(reply, nullptr, this, nullptr);
|
||||
reply->deleteLater();
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
if (reply->error() == 401 || reply->error() == 402) {
|
||||
Error(QStringLiteral("Error %1 (%2) using API, switching to URL based lookup.").arg(reply->errorString()).arg(reply->error()));
|
||||
use_api_ = false;
|
||||
CreateLyricsRequest(search);
|
||||
return;
|
||||
}
|
||||
Error(QStringLiteral("%1 (%2)").arg(reply->errorString()).arg(reply->error()));
|
||||
EndSearch(search);
|
||||
if (reply->error() == 401 || reply->error() == 402) {
|
||||
Error(QStringLiteral("Error %1 (%2) using API, switching to URL based lookup.").arg(reply->errorString()).arg(reply->error()));
|
||||
use_api_ = false;
|
||||
CreateLyricsRequest(search);
|
||||
return;
|
||||
}
|
||||
|
||||
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() != 200) {
|
||||
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 401 || reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 402) {
|
||||
Error(QStringLiteral("Received HTTP code %1 using API, switching to URL based lookup.").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt()));
|
||||
use_api_ = false;
|
||||
CreateLyricsRequest(search);
|
||||
return;
|
||||
}
|
||||
Error(QStringLiteral("Received HTTP code %1").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt()));
|
||||
EndSearch(search);
|
||||
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).isValid() && (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 401 || reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 402)) {
|
||||
Error(QStringLiteral("Received HTTP code %1 using API, switching to URL based lookup.").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt()));
|
||||
use_api_ = false;
|
||||
CreateLyricsRequest(search);
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray data = reply->readAll();
|
||||
QJsonObject json_obj = ExtractJsonObj(data);
|
||||
if (json_obj.isEmpty()) {
|
||||
EndSearch(search);
|
||||
const JsonObjectResult json_object_result = ParseJsonObject(reply);
|
||||
if (!json_object_result.success()) {
|
||||
Error(json_object_result.error_message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json_obj.contains("message"_L1)) {
|
||||
Error(u"Json reply is missing message object."_s, json_obj);
|
||||
EndSearch(search);
|
||||
const QJsonObject &json_object = json_object_result.json_object;
|
||||
if (json_object.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (!json_obj["message"_L1].isObject()) {
|
||||
Error(u"Json reply message is not an object."_s, json_obj);
|
||||
EndSearch(search);
|
||||
return;
|
||||
}
|
||||
QJsonObject obj_message = json_obj["message"_L1].toObject();
|
||||
|
||||
if (!obj_message.contains("header"_L1)) {
|
||||
Error(u"Json reply message object is missing header."_s, obj_message);
|
||||
EndSearch(search);
|
||||
if (!json_object.contains("message"_L1)) {
|
||||
Error(u"Json reply is missing message object."_s, json_object);
|
||||
return;
|
||||
}
|
||||
if (!obj_message["header"_L1].isObject()) {
|
||||
Error(u"Json reply message header is not an object."_s, obj_message);
|
||||
EndSearch(search);
|
||||
if (!json_object["message"_L1].isObject()) {
|
||||
Error(u"Json reply message is not an object."_s, json_object);
|
||||
return;
|
||||
}
|
||||
QJsonObject obj_header = obj_message["header"_L1].toObject();
|
||||
const QJsonObject object_message = json_object["message"_L1].toObject();
|
||||
|
||||
int status_code = obj_header["status_code"_L1].toInt();
|
||||
if (!object_message.contains("header"_L1)) {
|
||||
Error(u"Json reply message object is missing header."_s, object_message);
|
||||
return;
|
||||
}
|
||||
if (!object_message["header"_L1].isObject()) {
|
||||
Error(u"Json reply message header is not an object."_s, object_message);
|
||||
return;
|
||||
}
|
||||
const QJsonObject object_header = object_message["header"_L1].toObject();
|
||||
|
||||
const int status_code = object_header["status_code"_L1].toInt();
|
||||
if (status_code != 200) {
|
||||
Error(QStringLiteral("Received status code %1, switching to URL based lookup.").arg(status_code));
|
||||
use_api_ = false;
|
||||
@@ -179,53 +213,49 @@ void MusixmatchLyricsProvider::HandleSearchReply(QNetworkReply *reply, LyricsSea
|
||||
return;
|
||||
}
|
||||
|
||||
if (!obj_message.contains("body"_L1)) {
|
||||
Error(u"Json reply is missing body."_s, json_obj);
|
||||
EndSearch(search);
|
||||
if (!object_message.contains("body"_L1)) {
|
||||
Error(u"Json reply is missing body."_s, json_object);
|
||||
return;
|
||||
}
|
||||
if (!obj_message["body"_L1].isObject()) {
|
||||
Error(u"Json body is not an object."_s, json_obj);
|
||||
EndSearch(search);
|
||||
if (!object_message["body"_L1].isObject()) {
|
||||
Error(u"Json body is not an object."_s, json_object);
|
||||
return;
|
||||
}
|
||||
QJsonObject obj_body = obj_message["body"_L1].toObject();
|
||||
const QJsonObject object_body = object_message["body"_L1].toObject();
|
||||
|
||||
if (!obj_body.contains("track_list"_L1)) {
|
||||
Error(u"Json response is missing body."_s, obj_body);
|
||||
EndSearch(search);
|
||||
if (!object_body.contains("track_list"_L1)) {
|
||||
Error(u"Json response is missing body."_s, object_body);
|
||||
return;
|
||||
}
|
||||
if (!obj_body["track_list"_L1].isArray()) {
|
||||
Error(u"Json hits is not an array."_s, obj_body);
|
||||
EndSearch(search);
|
||||
if (!object_body["track_list"_L1].isArray()) {
|
||||
Error(u"Json hits is not an array."_s, object_body);
|
||||
return;
|
||||
}
|
||||
const QJsonArray array_tracklist = obj_body["track_list"_L1].toArray();
|
||||
const QJsonArray array_tracklist = object_body["track_list"_L1].toArray();
|
||||
|
||||
for (const QJsonValue &value_track : array_tracklist) {
|
||||
if (!value_track.isObject()) {
|
||||
continue;
|
||||
}
|
||||
QJsonObject obj_track = value_track.toObject();
|
||||
QJsonObject object_track = value_track.toObject();
|
||||
|
||||
if (!obj_track.contains("track"_L1) || !obj_track["track"_L1].isObject()) {
|
||||
if (!object_track.contains("track"_L1) || !object_track["track"_L1].isObject()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
obj_track = obj_track["track"_L1].toObject();
|
||||
if (!obj_track.contains("artist_name"_L1) ||
|
||||
!obj_track.contains("album_name"_L1) ||
|
||||
!obj_track.contains("track_name"_L1) ||
|
||||
!obj_track.contains("track_share_url"_L1)) {
|
||||
Error(u"Missing one or more values in result object"_s, obj_track);
|
||||
object_track = object_track["track"_L1].toObject();
|
||||
if (!object_track.contains("artist_name"_L1) ||
|
||||
!object_track.contains("album_name"_L1) ||
|
||||
!object_track.contains("track_name"_L1) ||
|
||||
!object_track.contains("track_share_url"_L1)) {
|
||||
Error(u"Missing one or more values in result object"_s, object_track);
|
||||
continue;
|
||||
}
|
||||
|
||||
QString artist_name = obj_track["artist_name"_L1].toString();
|
||||
QString album_name = obj_track["album_name"_L1].toString();
|
||||
QString track_name = obj_track["track_name"_L1].toString();
|
||||
QUrl track_share_url(obj_track["track_share_url"_L1].toString());
|
||||
const QString artist_name = object_track["artist_name"_L1].toString();
|
||||
const QString album_name = object_track["album_name"_L1].toString();
|
||||
const QString track_name = object_track["track_name"_L1].toString();
|
||||
const QUrl track_share_url(object_track["track_share_url"_L1].toString());
|
||||
|
||||
// Ignore results where both the artist, album and title don't match.
|
||||
if (use_api_ &&
|
||||
@@ -243,27 +273,22 @@ void MusixmatchLyricsProvider::HandleSearchReply(QNetworkReply *reply, LyricsSea
|
||||
|
||||
}
|
||||
|
||||
if (search->requests_lyrics_.isEmpty()) {
|
||||
EndSearch(search);
|
||||
}
|
||||
else {
|
||||
for (const QUrl &url : std::as_const(search->requests_lyrics_)) {
|
||||
SendLyricsRequest(search, url);
|
||||
}
|
||||
for (const QUrl &url : std::as_const(search->requests_lyrics_)) {
|
||||
SendLyricsRequest(search, url);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool MusixmatchLyricsProvider::CreateLyricsRequest(LyricsSearchContextPtr search) {
|
||||
|
||||
QString artist_stripped = StringFixup(search->request.artist);
|
||||
QString title_stripped = StringFixup(search->request.title);
|
||||
const QString artist_stripped = StringFixup(search->request.artist);
|
||||
const QString title_stripped = StringFixup(search->request.title);
|
||||
if (artist_stripped.isEmpty() || title_stripped.isEmpty()) {
|
||||
EndSearch(search);
|
||||
return false;
|
||||
}
|
||||
|
||||
QUrl url(QStringLiteral("https://www.musixmatch.com/lyrics/%1/%2").arg(artist_stripped, title_stripped));
|
||||
const QUrl url(QStringLiteral("https://www.musixmatch.com/lyrics/%1/%2").arg(artist_stripped, title_stripped));
|
||||
search->requests_lyrics_.append(url);
|
||||
return SendLyricsRequest(search, url);
|
||||
|
||||
@@ -271,14 +296,11 @@ bool MusixmatchLyricsProvider::CreateLyricsRequest(LyricsSearchContextPtr search
|
||||
|
||||
bool MusixmatchLyricsProvider::SendLyricsRequest(LyricsSearchContextPtr search, const QUrl &url) {
|
||||
|
||||
QNetworkRequest req(url);
|
||||
req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
|
||||
QNetworkReply *reply = network_->get(req);
|
||||
replies_ << reply;
|
||||
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, search, url]() { HandleLyricsReply(reply, search, url); });
|
||||
|
||||
qLog(Debug) << "MusixmatchLyrics: Sending request for" << url;
|
||||
|
||||
QNetworkReply *reply = CreateGetRequest(url);
|
||||
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, search, url]() { HandleLyricsReply(reply, search, url); });
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
@@ -287,30 +309,20 @@ void MusixmatchLyricsProvider::HandleLyricsReply(QNetworkReply *reply, LyricsSea
|
||||
|
||||
Q_ASSERT(QThread::currentThread() != qApp->thread());
|
||||
|
||||
const QScopeGuard end_search = qScopeGuard([this, search, url]() { EndSearch(search, url); });
|
||||
|
||||
if (!replies_.contains(reply)) return;
|
||||
replies_.removeAll(reply);
|
||||
QObject::disconnect(reply, nullptr, this, nullptr);
|
||||
reply->deleteLater();
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
Error(QStringLiteral("%1 (%2)").arg(reply->errorString()).arg(reply->error()));
|
||||
EndSearch(search, url);
|
||||
return;
|
||||
}
|
||||
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() != 200) {
|
||||
Error(QStringLiteral("Received HTTP code %1").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt()));
|
||||
EndSearch(search, url);
|
||||
const ReplyDataResult reply_data_result = GetReplyData(reply);
|
||||
if (!reply_data_result.success()) {
|
||||
Error(reply_data_result.error_message);
|
||||
return;
|
||||
}
|
||||
|
||||
const QByteArray data = reply->readAll();
|
||||
if (data.isEmpty()) {
|
||||
Error(u"Empty reply received from server."_s);
|
||||
EndSearch(search, url);
|
||||
return;
|
||||
}
|
||||
|
||||
const QString content = QString::fromUtf8(data);
|
||||
const QString content = QString::fromUtf8(reply_data_result.data);
|
||||
const QString data_begin = "<script id=\"__NEXT_DATA__\" type=\"application/json\">"_L1;
|
||||
const QString data_end = "</script>"_L1;
|
||||
qint64 begin_idx = content.indexOf(data_begin);
|
||||
@@ -324,75 +336,64 @@ void MusixmatchLyricsProvider::HandleLyricsReply(QNetworkReply *reply, LyricsSea
|
||||
}
|
||||
|
||||
if (content_json.isEmpty()) {
|
||||
EndSearch(search, url);
|
||||
return;
|
||||
}
|
||||
|
||||
static const QRegularExpression regex_html_tag(u"<[^>]*>"_s);
|
||||
if (content_json.contains(regex_html_tag)) { // Make sure it's not HTML code.
|
||||
EndSearch(search, url);
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonObject obj_data = ExtractJsonObj(content_json.toUtf8());
|
||||
if (obj_data.isEmpty()) {
|
||||
EndSearch(search, url);
|
||||
QJsonObject object_data = GetJsonObject(content_json.toUtf8()).json_object;
|
||||
if (object_data.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!obj_data.contains("props"_L1) || !obj_data["props"_L1].isObject()) {
|
||||
Error(u"Json reply is missing props."_s, obj_data);
|
||||
EndSearch(search, url);
|
||||
if (!object_data.contains("props"_L1) || !object_data["props"_L1].isObject()) {
|
||||
Error(u"Json reply is missing props."_s, object_data);
|
||||
return;
|
||||
}
|
||||
obj_data = obj_data["props"_L1].toObject();
|
||||
object_data = object_data["props"_L1].toObject();
|
||||
|
||||
if (!obj_data.contains("pageProps"_L1) || !obj_data["pageProps"_L1].isObject()) {
|
||||
Error(u"Json props is missing pageProps."_s, obj_data);
|
||||
EndSearch(search, url);
|
||||
if (!object_data.contains("pageProps"_L1) || !object_data["pageProps"_L1].isObject()) {
|
||||
Error(u"Json props is missing pageProps."_s, object_data);
|
||||
return;
|
||||
}
|
||||
obj_data = obj_data["pageProps"_L1].toObject();
|
||||
object_data = object_data["pageProps"_L1].toObject();
|
||||
|
||||
if (!obj_data.contains("data"_L1) || !obj_data["data"_L1].isObject()) {
|
||||
Error(u"Json pageProps is missing data."_s, obj_data);
|
||||
EndSearch(search, url);
|
||||
if (!object_data.contains("data"_L1) || !object_data["data"_L1].isObject()) {
|
||||
Error(u"Json pageProps is missing data."_s, object_data);
|
||||
return;
|
||||
}
|
||||
obj_data = obj_data["data"_L1].toObject();
|
||||
object_data = object_data["data"_L1].toObject();
|
||||
|
||||
|
||||
if (!obj_data.contains("trackInfo"_L1) || !obj_data["trackInfo"_L1].isObject()) {
|
||||
Error(u"Json data is missing trackInfo."_s, obj_data);
|
||||
EndSearch(search, url);
|
||||
if (!object_data.contains("trackInfo"_L1) || !object_data["trackInfo"_L1].isObject()) {
|
||||
Error(u"Json data is missing trackInfo."_s, object_data);
|
||||
return;
|
||||
}
|
||||
obj_data = obj_data["trackInfo"_L1].toObject();
|
||||
object_data = object_data["trackInfo"_L1].toObject();
|
||||
|
||||
if (!obj_data.contains("data"_L1) || !obj_data["data"_L1].isObject()) {
|
||||
Error(u"Json trackInfo reply is missing data."_s, obj_data);
|
||||
EndSearch(search, url);
|
||||
if (!object_data.contains("data"_L1) || !object_data["data"_L1].isObject()) {
|
||||
Error(u"Json trackInfo reply is missing data."_s, object_data);
|
||||
return;
|
||||
}
|
||||
obj_data = obj_data["data"_L1].toObject();
|
||||
object_data = object_data["data"_L1].toObject();
|
||||
|
||||
if (!obj_data.contains("track"_L1) || !obj_data["track"_L1].isObject()) {
|
||||
Error(u"Json data is missing track."_s, obj_data);
|
||||
EndSearch(search, url);
|
||||
if (!object_data.contains("track"_L1) || !object_data["track"_L1].isObject()) {
|
||||
Error(u"Json data is missing track."_s, object_data);
|
||||
return;
|
||||
}
|
||||
|
||||
const QJsonObject obj_track = obj_data["track"_L1].toObject();
|
||||
const QJsonObject obj_track = object_data["track"_L1].toObject();
|
||||
|
||||
if (!obj_track.contains("hasLyrics"_L1) || !obj_track["hasLyrics"_L1].isBool()) {
|
||||
Error(u"Json track is missing hasLyrics."_s, obj_track);
|
||||
EndSearch(search, url);
|
||||
return;
|
||||
}
|
||||
|
||||
const bool has_lyrics = obj_track["hasLyrics"_L1].toBool();
|
||||
if (!has_lyrics) {
|
||||
EndSearch(search, url);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -407,32 +408,28 @@ void MusixmatchLyricsProvider::HandleLyricsReply(QNetworkReply *reply, LyricsSea
|
||||
result.title = obj_track["name"_L1].toString();
|
||||
}
|
||||
|
||||
if (!obj_data.contains("lyrics"_L1) || !obj_data["lyrics"_L1].isObject()) {
|
||||
Error(u"Json data is missing lyrics."_s, obj_data);
|
||||
EndSearch(search, url);
|
||||
if (!object_data.contains("lyrics"_L1) || !object_data["lyrics"_L1].isObject()) {
|
||||
Error(u"Json data is missing lyrics."_s, object_data);
|
||||
return;
|
||||
}
|
||||
QJsonObject obj_lyrics = obj_data["lyrics"_L1].toObject();
|
||||
const QJsonObject object_lyrics = object_data["lyrics"_L1].toObject();
|
||||
|
||||
if (!obj_lyrics.contains("body"_L1) || !obj_lyrics["body"_L1].isString()) {
|
||||
Error(u"Json lyrics reply is missing body."_s, obj_lyrics);
|
||||
EndSearch(search, url);
|
||||
if (!object_lyrics.contains("body"_L1) || !object_lyrics["body"_L1].isString()) {
|
||||
Error(u"Json lyrics reply is missing body."_s, object_lyrics);
|
||||
return;
|
||||
}
|
||||
result.lyrics = obj_lyrics["body"_L1].toString();
|
||||
result.lyrics = object_lyrics["body"_L1].toString();
|
||||
|
||||
if (!result.lyrics.isEmpty()) {
|
||||
result.lyrics = Utilities::DecodeHtmlEntities(result.lyrics);
|
||||
search->results.append(result);
|
||||
}
|
||||
|
||||
EndSearch(search, url);
|
||||
|
||||
}
|
||||
|
||||
void MusixmatchLyricsProvider::EndSearch(LyricsSearchContextPtr search, const QUrl &url) {
|
||||
|
||||
if (search->requests_lyrics_.contains(url)) {
|
||||
if (!url.isEmpty() && search->requests_lyrics_.contains(url)) {
|
||||
search->requests_lyrics_.removeAll(url);
|
||||
}
|
||||
|
||||
@@ -448,10 +445,3 @@ void MusixmatchLyricsProvider::EndSearch(LyricsSearchContextPtr search, const QU
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MusixmatchLyricsProvider::Error(const QString &error, const QVariant &debug) {
|
||||
|
||||
qLog(Error) << "MusixmatchLyrics:" << error;
|
||||
if (debug.isValid()) qLog(Debug) << debug;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user