Minor changes to Qobuz cover provider (and fix compile)
This commit is contained in:
@@ -57,18 +57,18 @@ bool QobuzCoverProvider::StartSearch(const QString &artist, const QString &album
|
|||||||
typedef QPair<QString, QString> Param;
|
typedef QPair<QString, QString> Param;
|
||||||
typedef QList<Param> ParamList;
|
typedef QList<Param> ParamList;
|
||||||
|
|
||||||
QString request;
|
QString resource;
|
||||||
QString search;
|
QString query;
|
||||||
if (album.isEmpty()) {
|
if (album.isEmpty()) {
|
||||||
request = "track/search";
|
resource = "track/search";
|
||||||
search = artist + " " + title;
|
query = artist + " " + title;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
request = "album/search";
|
resource = "album/search";
|
||||||
search = artist + " " + album;
|
query = artist + " " + album;
|
||||||
}
|
}
|
||||||
|
|
||||||
ParamList params = ParamList() << Param("query", search)
|
ParamList params = ParamList() << Param("query", query)
|
||||||
<< Param("limit", QString::number(kLimit))
|
<< Param("limit", QString::number(kLimit))
|
||||||
<< Param("app_id", QString::fromUtf8(QByteArray::fromBase64(kAppID)));
|
<< Param("app_id", QString::fromUtf8(QByteArray::fromBase64(kAppID)));
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ bool QobuzCoverProvider::StartSearch(const QString &artist, const QString &album
|
|||||||
url_query.addQueryItem(QUrl::toPercentEncoding(param.first), QUrl::toPercentEncoding(param.second));
|
url_query.addQueryItem(QUrl::toPercentEncoding(param.first), QUrl::toPercentEncoding(param.second));
|
||||||
}
|
}
|
||||||
|
|
||||||
QUrl url(kApiUrl + QString("/") + request);
|
QUrl url(kApiUrl + QString("/") + resource);
|
||||||
url.setQuery(url_query);
|
url.setQuery(url_query);
|
||||||
|
|
||||||
QNetworkRequest req(url);
|
QNetworkRequest req(url);
|
||||||
@@ -89,13 +89,11 @@ bool QobuzCoverProvider::StartSearch(const QString &artist, const QString &album
|
|||||||
QNetworkReply *reply = network_->get(req);
|
QNetworkReply *reply = network_->get(req);
|
||||||
connect(reply, &QNetworkReply::finished, [=] { this->HandleSearchReply(reply, id); });
|
connect(reply, &QNetworkReply::finished, [=] { this->HandleSearchReply(reply, id); });
|
||||||
|
|
||||||
qLog(Debug) << "Qobuz: Sending request" << url;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QobuzCoverProvider::CancelSearch(int id) { Q_UNUSED(id); }
|
void QobuzCoverProvider::CancelSearch(const int id) { Q_UNUSED(id); }
|
||||||
|
|
||||||
QByteArray QobuzCoverProvider::GetReplyData(QNetworkReply *reply) {
|
QByteArray QobuzCoverProvider::GetReplyData(QNetworkReply *reply) {
|
||||||
|
|
||||||
@@ -189,12 +187,12 @@ void QobuzCoverProvider::HandleSearchReply(QNetworkReply *reply, const int id) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonValue json_type;
|
QJsonValue value_type;
|
||||||
if (json_obj.contains("albums")) {
|
if (json_obj.contains("albums")) {
|
||||||
json_type = json_obj["albums"];
|
value_type = json_obj["albums"];
|
||||||
}
|
}
|
||||||
else if (json_obj.contains("tracks")) {
|
else if (json_obj.contains("tracks")) {
|
||||||
json_type = json_obj["tracks"];
|
value_type = json_obj["tracks"];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Error("Json reply is missing albums and tracks object.", json_obj);
|
Error("Json reply is missing albums and tracks object.", json_obj);
|
||||||
@@ -202,74 +200,74 @@ void QobuzCoverProvider::HandleSearchReply(QNetworkReply *reply, const int id) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!json_type.isObject()) {
|
if (!value_type.isObject()) {
|
||||||
Error("Json albums or tracks is not a object.", json_type);
|
Error("Json albums or tracks is not a object.", value_type);
|
||||||
emit SearchFinished(id, results);
|
emit SearchFinished(id, results);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QJsonObject obj_type = json_type.toObject();
|
QJsonObject obj_type = value_type.toObject();
|
||||||
|
|
||||||
if (!obj_type.contains("items")) {
|
if (!obj_type.contains("items")) {
|
||||||
Error("Json albums or tracks object does not contain items.", obj_type);
|
Error("Json albums or tracks object does not contain items.", obj_type);
|
||||||
emit SearchFinished(id, results);
|
emit SearchFinished(id, results);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QJsonValue json_items = obj_type["items"];
|
QJsonValue value_items = obj_type["items"];
|
||||||
|
|
||||||
if (!json_items.isArray()) {
|
if (!value_items.isArray()) {
|
||||||
Error("Json albums or track object items is not a array.", json_items);
|
Error("Json albums or track object items is not a array.", value_items);
|
||||||
emit SearchFinished(id, results);
|
emit SearchFinished(id, results);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QJsonArray json_array = json_items.toArray();
|
QJsonArray array_items = value_items.toArray();
|
||||||
|
|
||||||
for (const QJsonValue &value : json_array) {
|
for (const QJsonValue &value : array_items) {
|
||||||
|
|
||||||
if (!value.isObject()) {
|
if (!value.isObject()) {
|
||||||
Error("Invalid Json reply, value in items is not a object.", value);
|
Error("Invalid Json reply, value in items is not a object.", value);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
json_obj = value.toObject();
|
QJsonObject item_obj = value.toObject();
|
||||||
|
|
||||||
QJsonObject obj_album;
|
QJsonObject obj_album;
|
||||||
if (json_obj.contains("album")) {
|
if (item_obj.contains("album")) {
|
||||||
if (!json_obj["album"].isObject()) {
|
if (!item_obj["album"].isObject()) {
|
||||||
Error("Invalid Json reply, items album is not a object.", json_obj);
|
Error("Invalid Json reply, items album is not a object.", item_obj);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
obj_album = json_obj["album"].toObject();
|
obj_album = item_obj["album"].toObject();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
obj_album = json_obj;
|
obj_album = item_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!obj_album.contains("artist") || !obj_album.contains("image") || !obj_album.contains("title")) {
|
if (!obj_album.contains("artist") || !obj_album.contains("image") || !obj_album.contains("title")) {
|
||||||
Error("Invalid Json reply, item is missing artist, title or image.", json_obj);
|
Error("Invalid Json reply, item is missing artist, title or image.", item_obj);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString album = obj_album["title"].toString();
|
QString album = obj_album["title"].toString();
|
||||||
|
|
||||||
// Artist
|
// Artist
|
||||||
QJsonValue json_artist = obj_album["artist"];
|
QJsonValue value_artist = obj_album["artist"];
|
||||||
if (!json_artist.isObject()) {
|
if (!value_artist.isObject()) {
|
||||||
Error("Invalid Json reply, items (album) artist is not a object.", json_artist);
|
Error("Invalid Json reply, items (album) artist is not a object.", value_artist);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
QJsonObject obj_artist = json_artist.toObject();
|
QJsonObject obj_artist = value_artist.toObject();
|
||||||
if (!obj_artist.contains("name")) {
|
if (!obj_artist.contains("name")) {
|
||||||
Error("Invalid Json reply, items (album) artist is missing name.", obj_artist);
|
Error("Invalid Json reply, items (album) artist is missing name.", obj_artist);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
QString artist = json_artist["name"].toString();
|
QString artist = obj_artist["name"].toString();
|
||||||
|
|
||||||
// Image
|
// Image
|
||||||
QJsonValue json_image = obj_album["image"];
|
QJsonValue value_image = obj_album["image"];
|
||||||
if (!json_image.isObject()) {
|
if (!value_image.isObject()) {
|
||||||
Error("Invalid Json reply, items (album) image is not a object.", json_image);
|
Error("Invalid Json reply, items (album) image is not a object.", value_image);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
QJsonObject obj_image = json_image.toObject();
|
QJsonObject obj_image = value_image.toObject();
|
||||||
if (!obj_image.contains("large")) {
|
if (!obj_image.contains("large")) {
|
||||||
Error("Invalid Json reply, items (album) image is missing large.", obj_image);
|
Error("Invalid Json reply, items (album) image is missing large.", obj_image);
|
||||||
continue;
|
continue;
|
||||||
@@ -285,8 +283,6 @@ void QobuzCoverProvider::HandleSearchReply(QNetworkReply *reply, const int id) {
|
|||||||
cover_result.image_url = cover_url;
|
cover_result.image_url = cover_url;
|
||||||
results << cover_result;
|
results << cover_result;
|
||||||
|
|
||||||
qLog(Debug) << artist << album << cover_url;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
emit SearchFinished(id, results);
|
emit SearchFinished(id, results);
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class QobuzCoverProvider : public CoverProvider {
|
|||||||
public:
|
public:
|
||||||
explicit QobuzCoverProvider(Application *app, QObject *parent = nullptr);
|
explicit QobuzCoverProvider(Application *app, QObject *parent = nullptr);
|
||||||
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id);
|
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id);
|
||||||
void CancelSearch(int id);
|
void CancelSearch(const int id);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void HandleSearchReply(QNetworkReply *reply, const int id);
|
void HandleSearchReply(QNetworkReply *reply, const int id);
|
||||||
|
|||||||
Reference in New Issue
Block a user