Refactor Tidal, Spotify, Qobuz, Subsonic and cover providers

Use common HTTP, Json and OAuthenticator class
This commit is contained in:
Jonas Kvinge
2025-03-08 23:11:07 +01:00
parent 7de8a44709
commit cd516c37b9
81 changed files with 2429 additions and 3968 deletions

View File

@@ -1,6 +1,6 @@
/*
* Strawberry Music Player
* Copyright 2019-2021, Jonas Kvinge <jonas@jkvinge.net>
* Copyright 2019-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
@@ -20,6 +20,7 @@
#include "config.h"
#include <utility>
#include <memory>
#include <QtGlobal>
#include <QObject>
@@ -46,6 +47,7 @@
#include "constants/subsonicsettings.h"
using namespace Qt::Literals::StringLiterals;
using std::make_shared;
SubsonicBaseRequest::SubsonicBaseRequest(SubsonicService *service, QObject *parent)
: QObject(parent),
@@ -98,20 +100,20 @@ QUrl SubsonicBaseRequest::CreateUrl(const QUrl &server_url, const SubsonicSettin
QNetworkReply *SubsonicBaseRequest::CreateGetRequest(const QString &ressource_name, const ParamList &params_provided) const {
QUrl url = CreateUrl(server_url(), auth_method(), username(), password(), ressource_name, params_provided);
QNetworkRequest req(url);
const QUrl url = CreateUrl(server_url(), auth_method(), username(), password(), ressource_name, params_provided);
QNetworkRequest network_request(url);
if (url.scheme() == "https"_L1 && !verify_certificate()) {
QSslConfiguration sslconfig = QSslConfiguration::defaultConfiguration();
sslconfig.setPeerVerifyMode(QSslSocket::VerifyNone);
req.setSslConfiguration(sslconfig);
network_request.setSslConfiguration(sslconfig);
}
req.setHeader(QNetworkRequest::ContentTypeHeader, u"application/x-www-form-urlencoded"_s);
req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
req.setAttribute(QNetworkRequest::Http2AllowedAttribute, http2());
network_request.setHeader(QNetworkRequest::ContentTypeHeader, u"application/x-www-form-urlencoded"_s);
network_request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
network_request.setAttribute(QNetworkRequest::Http2AllowedAttribute, http2());
QNetworkReply *reply = network_->get(req);
QNetworkReply *reply = network_->get(network_request);
QObject::connect(reply, &QNetworkReply::sslErrors, this, &SubsonicBaseRequest::HandleSSLErrors);
//qLog(Debug) << "Subsonic: Sending request" << url;
@@ -128,103 +130,58 @@ void SubsonicBaseRequest::HandleSSLErrors(const QList<QSslError> &ssl_errors) {
}
QByteArray SubsonicBaseRequest::GetReplyData(QNetworkReply *reply) {
JsonBaseRequest::JsonObjectResult SubsonicBaseRequest::ParseJsonObject(QNetworkReply *reply) {
QByteArray data;
if (reply->error() == QNetworkReply::NoError && reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 200) {
data = reply->readAll();
if (reply->error() != QNetworkReply::NoError && reply->error() < 200) {
return JsonObjectResult(ErrorCode::NetworkError, QStringLiteral("%1 (%2)").arg(reply->errorString()).arg(reply->error()));
}
else {
if (reply->error() != QNetworkReply::NoError && reply->error() < 200) {
// This is a network error, there is nothing more to do.
Error(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.isEmpty() && json_object.contains("error"_L1) && json_object["error"_L1].isObject()) {
const QJsonObject object_error = json_object["error"_L1].toObject();
if (!object_error.isEmpty() && object_error.contains("code"_L1) && object_error.contains("message"_L1)) {
const int code = object_error["code"_L1].toInt();
const QString message = object_error["message"_L1].toString();
result.error_code = ErrorCode::APIError;
result.error_message = QStringLiteral("%s (%s)").arg(message, code);
}
}
else {
result.json_object = json_document.object();
}
}
else {
// See if there is Json data containing "error" - then use that instead.
data = reply->readAll();
QString error;
QJsonParseError parse_error;
QJsonDocument json_doc = QJsonDocument::fromJson(data, &parse_error);
if (parse_error.error == QJsonParseError::NoError && !json_doc.isEmpty() && json_doc.isObject()) {
QJsonObject json_obj = json_doc.object();
if (!json_obj.isEmpty() && json_obj.contains("error"_L1)) {
QJsonValue json_error = json_obj["error"_L1];
if (json_error.isObject()) {
json_obj = json_error.toObject();
if (!json_obj.isEmpty() && json_obj.contains("code"_L1) && json_obj.contains("message"_L1)) {
int code = json_obj["code"_L1].toInt();
QString message = json_obj["message"_L1].toString();
error = QStringLiteral("%1 (%2)").arg(message).arg(code);
}
}
}
}
if (error.isEmpty()) {
if (reply->error() != QNetworkReply::NoError) {
error = QStringLiteral("%1 (%2)").arg(reply->errorString()).arg(reply->error());
}
else {
error = QStringLiteral("Received HTTP code %1").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
}
}
Error(error);
result.error_code = ErrorCode::ParseError;
result.error_message = json_parse_error.errorString();
}
}
return data;
}
QJsonObject SubsonicBaseRequest::ExtractJsonObj(QByteArray &data) {
QJsonParseError json_error;
QJsonDocument json_doc = QJsonDocument::fromJson(data, &json_error);
if (json_error.error != QJsonParseError::NoError) {
Error(u"Reply from server missing Json data."_s, data);
return QJsonObject();
}
if (json_doc.isEmpty()) {
Error(u"Received empty Json document."_s, data);
return QJsonObject();
}
if (!json_doc.isObject()) {
Error(u"Json document is not an object."_s, json_doc);
return QJsonObject();
}
QJsonObject json_obj = json_doc.object();
if (json_obj.isEmpty()) {
Error(u"Received empty Json object."_s, json_doc);
return QJsonObject();
}
if (!json_obj.contains("subsonic-response"_L1)) {
Error(u"Json reply is missing subsonic-response."_s, json_obj);
return QJsonObject();
}
QJsonValue json_response = json_obj["subsonic-response"_L1];
if (!json_response.isObject()) {
Error(u"Json response is not an object."_s, json_response);
return QJsonObject();
}
json_obj = json_response.toObject();
return json_obj;
}
QString SubsonicBaseRequest::ErrorsToHTML(const QStringList &errors) {
QString error_html;
for (const QString &error : errors) {
error_html += error + "<br />"_L1;
}
return error_html;
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);
}
}
if (reply->error() == QNetworkReply::AuthenticationRequiredError) {
//service_->ClearSession();
}
return result;
}

View File

@@ -1,6 +1,6 @@
/*
* Strawberry Music Player
* Copyright 2019-2021, Jonas Kvinge <jonas@jkvinge.net>
* Copyright 2019-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
@@ -35,8 +35,9 @@
#include <QJsonObject>
#include "includes/scoped_ptr.h"
#include "subsonicservice.h"
#include "constants/subsonicsettings.h"
#include "core/jsonbaserequest.h"
#include "subsonicservice.h"
class QNetworkAccessManager;
class QNetworkReply;
@@ -47,6 +48,9 @@ class SubsonicBaseRequest : public QObject {
public:
explicit SubsonicBaseRequest(SubsonicService *service, QObject *parent = nullptr);
using JsonObjectResult = JsonBaseRequest::JsonObjectResult;
using ErrorCode = JsonBaseRequest::ErrorCode;
protected:
using Param = QPair<QString, QString>;
using ParamList = QList<Param>;
@@ -56,11 +60,9 @@ class SubsonicBaseRequest : public QObject {
protected:
QNetworkReply *CreateGetRequest(const QString &ressource_name, const ParamList &params_provided) const;
QByteArray GetReplyData(QNetworkReply *reply);
QJsonObject ExtractJsonObj(QByteArray &data);
JsonObjectResult ParseJsonObject(QNetworkReply *reply);
virtual void Error(const QString &error, const QVariant &debug = QVariant()) = 0;
static QString ErrorsToHTML(const QStringList &errors);
QUrl server_url() const { return service_->server_url(); }
QString username() const { return service_->username(); }

View File

@@ -1,6 +1,6 @@
/*
* Strawberry Music Player
* Copyright 2019-2021, Jonas Kvinge <jonas@jkvinge.net>
* Copyright 2019-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
@@ -42,6 +42,7 @@
#include "core/logging.h"
#include "core/song.h"
#include "core/networktimeouts.h"
#include "utilities/strutils.h"
#include "utilities/imageutils.h"
#include "constants/timeconstants.h"
#include "subsonicservice.h"
@@ -144,7 +145,7 @@ void SubsonicRequest::FlushAlbumsRequests() {
while (!albums_requests_queue_.isEmpty() && albums_requests_active_ < kMaxConcurrentAlbumsRequests) {
Request request = albums_requests_queue_.dequeue();
const Request request = albums_requests_queue_.dequeue();
++albums_requests_active_;
ParamList params = ParamList() << Param(u"type"_s, u"alphabeticalByName"_s);
@@ -169,85 +170,57 @@ void SubsonicRequest::AlbumsReplyReceived(QNetworkReply *reply, const int offset
--albums_requests_active_;
QByteArray data = GetReplyData(reply);
int albums_received = 0;
const QScopeGuard finish_check = qScopeGuard([this, offset_requested, size_requested, &albums_received]() { AlbumsFinishCheck(offset_requested, size_requested, albums_received); });
if (finished_) return;
if (data.isEmpty()) {
AlbumsFinishCheck(offset_requested, size_requested);
const JsonObjectResult json_object_result = ParseJsonObject(reply);
if (!json_object_result.success()) {
Error(json_object_result.error_message);
return;
}
QJsonObject json_obj = ExtractJsonObj(data);
if (json_obj.isEmpty()) {
AlbumsFinishCheck(offset_requested, size_requested);
QJsonObject json_object = json_object_result.json_object;
if (json_object.isEmpty()) {
return;
}
if (json_obj.contains("error"_L1)) {
QJsonValue json_error = json_obj["error"_L1];
if (!json_error.isObject()) {
Error(u"Json error is not an object."_s, json_obj);
AlbumsFinishCheck(offset_requested, size_requested);
return;
}
json_obj = json_error.toObject();
if (!json_obj.isEmpty() && json_obj.contains("code"_L1) && json_obj.contains("message"_L1)) {
int code = json_obj["code"_L1].toInt();
QString message = json_obj["message"_L1].toString();
Error(QStringLiteral("%1 (%2)").arg(message).arg(code));
AlbumsFinishCheck(offset_requested, size_requested);
}
else {
Error(u"Json error object is missing code or message."_s, json_obj);
AlbumsFinishCheck(offset_requested, size_requested);
}
return;
}
if (!json_obj.contains("albumList"_L1) && !json_obj.contains("albumList2"_L1)) {
Error(u"Json reply is missing albumList."_s, json_obj);
AlbumsFinishCheck(offset_requested, size_requested);
if (!json_object.contains("albumList"_L1) && !json_object.contains("albumList2"_L1)) {
Error(u"Json reply is missing albumList."_s, json_object);
return;
}
QJsonValue value_albumlist;
if (json_obj.contains("albumList"_L1)) value_albumlist = json_obj["albumList"_L1];
else if (json_obj.contains("albumList2"_L1)) value_albumlist = json_obj["albumList2"_L1];
if (json_object.contains("albumList"_L1)) value_albumlist = json_object["albumList"_L1];
else if (json_object.contains("albumList2"_L1)) value_albumlist = json_object["albumList2"_L1];
if (!value_albumlist.isObject()) {
Error(u"Json album list is not an object."_s, value_albumlist);
AlbumsFinishCheck(offset_requested, size_requested);
}
json_obj = value_albumlist.toObject();
if (json_obj.isEmpty()) {
json_object = value_albumlist.toObject();
if (json_object.isEmpty()) {
if (offset_requested == 0) no_results_ = true;
AlbumsFinishCheck(offset_requested, size_requested);
return;
}
if (!json_obj.contains("album"_L1)) {
Error(u"Json album list does not contain album array."_s, json_obj);
AlbumsFinishCheck(offset_requested, size_requested);
if (!json_object.contains("album"_L1)) {
Error(u"Json album list does not contain album array."_s, json_object);
}
QJsonValue json_album = json_obj["album"_L1];
const QJsonValue json_album = json_object["album"_L1];
if (json_album.isNull()) {
if (offset_requested == 0) no_results_ = true;
AlbumsFinishCheck(offset_requested, size_requested);
return;
}
if (!json_album.isArray()) {
Error(u"Json album is not an array."_s, json_album);
AlbumsFinishCheck(offset_requested, size_requested);
}
const QJsonArray array_albums = json_album.toArray();
if (array_albums.isEmpty()) {
if (offset_requested == 0) no_results_ = true;
AlbumsFinishCheck(offset_requested, size_requested);
return;
}
int albums_received = 0;
for (const QJsonValue &value_album : array_albums) {
++albums_received;
@@ -256,27 +229,27 @@ void SubsonicRequest::AlbumsReplyReceived(QNetworkReply *reply, const int offset
Error(u"Invalid Json reply, album is not an object."_s);
continue;
}
QJsonObject obj_album = value_album.toObject();
const QJsonObject object_album = value_album.toObject();
if (!obj_album.contains("id"_L1) || !obj_album.contains("artist"_L1)) {
Error(u"Invalid Json reply, album object in array is missing ID or artist."_s, obj_album);
if (!object_album.contains("id"_L1) || !object_album.contains("artist"_L1)) {
Error(u"Invalid Json reply, album object in array is missing ID or artist."_s, object_album);
continue;
}
if (!obj_album.contains("album"_L1) && !obj_album.contains("name"_L1)) {
Error(u"Invalid Json reply, album object in array is missing album or name."_s, obj_album);
if (!object_album.contains("album"_L1) && !object_album.contains("name"_L1)) {
Error(u"Invalid Json reply, album object in array is missing album or name."_s, object_album);
continue;
}
QString album_id = obj_album["id"_L1].toString();
QString album_id = object_album["id"_L1].toString();
if (album_id.isEmpty()) {
album_id = QString::number(obj_album["id"_L1].toInt());
album_id = QString::number(object_album["id"_L1].toInt());
}
QString artist = obj_album["artist"_L1].toString();
const QString artist = object_album["artist"_L1].toString();
QString album;
if (obj_album.contains("album"_L1)) album = obj_album["album"_L1].toString();
else if (obj_album.contains("name"_L1)) album = obj_album["name"_L1].toString();
if (object_album.contains("album"_L1)) album = object_album["album"_L1].toString();
else if (object_album.contains("name"_L1)) album = object_album["name"_L1].toString();
if (album_songs_requests_pending_.contains(album_id)) continue;
@@ -287,8 +260,6 @@ void SubsonicRequest::AlbumsReplyReceived(QNetworkReply *reply, const int offset
}
AlbumsFinishCheck(offset_requested, size_requested, albums_received);
}
void SubsonicRequest::AlbumsFinishCheck(const int offset, const int size, const int albums_received) {
@@ -340,14 +311,12 @@ void SubsonicRequest::AddAlbumSongsRequest(const QString &artist_id, const QStri
void SubsonicRequest::FlushAlbumSongsRequests() {
while (!album_songs_requests_queue_.isEmpty() && album_songs_requests_active_ < kMaxConcurrentAlbumSongsRequests) {
Request request = album_songs_requests_queue_.dequeue();
const Request request = album_songs_requests_queue_.dequeue();
++album_songs_requests_active_;
QNetworkReply *reply = CreateGetRequest(u"getAlbum"_s, ParamList() << Param(u"id"_s, request.album_id));
replies_ << reply;
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, request]() { AlbumSongsReplyReceived(reply, request.artist_id, request.album_id, request.album_artist); });
timeouts_->AddReply(reply);
}
}
@@ -364,72 +333,47 @@ void SubsonicRequest::AlbumSongsReplyReceived(QNetworkReply *reply, const QStrin
Q_EMIT UpdateProgress(album_songs_received_);
QByteArray data = GetReplyData(reply);
const QScopeGuard finish_check = qScopeGuard([this]() { SongsFinishCheck(); });
if (finished_) return;
if (data.isEmpty()) {
SongsFinishCheck();
const JsonObjectResult json_object_result = ParseJsonObject(reply);
if (!json_object_result.success()) {
Error(json_object_result.error_message);
return;
}
QJsonObject json_obj = ExtractJsonObj(data);
if (json_obj.isEmpty()) {
SongsFinishCheck();
const QJsonObject &json_object = json_object_result.json_object;
if (json_object.isEmpty()) {
return;
}
if (json_obj.contains("error"_L1)) {
QJsonValue json_error = json_obj["error"_L1];
if (!json_error.isObject()) {
Error(u"Json error is not an object."_s, json_obj);
SongsFinishCheck();
return;
}
json_obj = json_error.toObject();
if (!json_obj.isEmpty() && json_obj.contains("code"_L1) && json_obj.contains("message"_L1)) {
int code = json_obj["code"_L1].toInt();
QString message = json_obj["message"_L1].toString();
Error(QStringLiteral("%1 (%2)").arg(message).arg(code));
SongsFinishCheck();
}
else {
Error(u"Json error object missing code or message."_s, json_obj);
SongsFinishCheck();
}
if (!json_object.contains("album"_L1)) {
Error(u"Json reply is missing albumList."_s, json_object);
return;
}
if (!json_obj.contains("album"_L1)) {
Error(u"Json reply is missing albumList."_s, json_obj);
SongsFinishCheck();
return;
}
QJsonValue value_album = json_obj["album"_L1];
const QJsonValue value_album = json_object["album"_L1];
if (!value_album.isObject()) {
Error(u"Json album is not an object."_s, value_album);
SongsFinishCheck();
return;
}
QJsonObject obj_album = value_album.toObject();
const QJsonObject object_album = value_album.toObject();
if (!obj_album.contains("song"_L1)) {
Error(u"Json album object does not contain song array."_s, json_obj);
SongsFinishCheck();
if (!object_album.contains("song"_L1)) {
Error(u"Json album object does not contain song array."_s, object_album);
return;
}
QJsonValue json_song = obj_album["song"_L1];
if (!json_song.isArray()) {
Error(u"Json song is not an array."_s, obj_album);
SongsFinishCheck();
const QJsonValue value_songs = object_album["song"_L1];
if (!value_songs.isArray()) {
Error(u"Json song is not an array."_s, object_album);
return;
}
const QJsonArray array_songs = json_song.toArray();
const QJsonArray array_songs = value_songs.toArray();
qint64 created = 0;
if (obj_album.contains("created"_L1)) {
created = QDateTime::fromString(obj_album["created"_L1].toString(), Qt::ISODate).toSecsSinceEpoch();
if (object_album.contains("created"_L1)) {
created = QDateTime::fromString(object_album["created"_L1].toString(), Qt::ISODate).toSecsSinceEpoch();
}
bool compilation = false;
@@ -441,10 +385,10 @@ void SubsonicRequest::AlbumSongsReplyReceived(QNetworkReply *reply, const QStrin
Error(u"Invalid Json reply, track is not a object."_s);
continue;
}
QJsonObject obj_song = value_song.toObject();
const QJsonObject object_song = value_song.toObject();
Song song(Song::Source::Subsonic);
ParseSong(song, obj_song, artist_id, album_id, album_artist, created);
ParseSong(song, object_song, artist_id, album_id, album_artist, created);
if (!song.is_valid()) continue;
if (song.disc() >= 2) multidisc = true;
if (song.is_compilation()) compilation = true;
@@ -459,8 +403,6 @@ void SubsonicRequest::AlbumSongsReplyReceived(QNetworkReply *reply, const QStrin
songs_.insert(song.song_id(), song);
}
SongsFinishCheck();
}
void SubsonicRequest::SongsFinishCheck() {
@@ -485,137 +427,137 @@ void SubsonicRequest::SongsFinishCheck() {
}
QString SubsonicRequest::ParseSong(Song &song, const QJsonObject &json_obj, const QString &artist_id_requested, const QString &album_id_requested, const QString &album_artist, const qint64 album_created) {
QString SubsonicRequest::ParseSong(Song &song, const QJsonObject &json_object, const QString &artist_id_requested, const QString &album_id_requested, const QString &album_artist, const qint64 album_created) {
Q_UNUSED(artist_id_requested);
Q_UNUSED(album_id_requested);
if (
!json_obj.contains("id"_L1) ||
!json_obj.contains("title"_L1) ||
!json_obj.contains("size"_L1) ||
!json_obj.contains("suffix"_L1) ||
!json_obj.contains("duration"_L1) ||
!json_obj.contains("type"_L1)
!json_object.contains("id"_L1) ||
!json_object.contains("title"_L1) ||
!json_object.contains("size"_L1) ||
!json_object.contains("suffix"_L1) ||
!json_object.contains("duration"_L1) ||
!json_object.contains("type"_L1)
) {
Error(u"Invalid Json reply, song is missing one or more values."_s, json_obj);
Error(u"Invalid Json reply, song is missing one or more values."_s, json_object);
return QString();
}
QString song_id;
if (json_obj["id"_L1].type() == QJsonValue::String) {
song_id = json_obj["id"_L1].toString();
if (json_object["id"_L1].type() == QJsonValue::String) {
song_id = json_object["id"_L1].toString();
}
else {
song_id = QString::number(json_obj["id"_L1].toInt());
song_id = QString::number(json_object["id"_L1].toInt());
}
QString album_id;
if (json_obj.contains("albumId"_L1)) {
if (json_obj["albumId"_L1].type() == QJsonValue::String) {
album_id = json_obj["albumId"_L1].toString();
if (json_object.contains("albumId"_L1)) {
if (json_object["albumId"_L1].type() == QJsonValue::String) {
album_id = json_object["albumId"_L1].toString();
}
else {
album_id = QString::number(json_obj["albumId"_L1].toInt());
album_id = QString::number(json_object["albumId"_L1].toInt());
}
}
QString artist_id;
if (json_obj.contains("artistId"_L1)) {
if (json_obj["artistId"_L1].type() == QJsonValue::String) {
artist_id = json_obj["artistId"_L1].toString();
if (json_object.contains("artistId"_L1)) {
if (json_object["artistId"_L1].type() == QJsonValue::String) {
artist_id = json_object["artistId"_L1].toString();
}
else {
artist_id = QString::number(json_obj["artistId"_L1].toInt());
artist_id = QString::number(json_object["artistId"_L1].toInt());
}
}
QString title = json_obj["title"_L1].toString();
QString title = json_object["title"_L1].toString();
QString album;
if (json_obj.contains("album"_L1)) {
album = json_obj["album"_L1].toString();
if (json_object.contains("album"_L1)) {
album = json_object["album"_L1].toString();
}
QString artist;
if (json_obj.contains("artist"_L1)) {
artist = json_obj["artist"_L1].toString();
if (json_object.contains("artist"_L1)) {
artist = json_object["artist"_L1].toString();
}
int size = 0;
if (json_obj["size"_L1].type() == QJsonValue::String) {
size = json_obj["size"_L1].toString().toInt();
if (json_object["size"_L1].type() == QJsonValue::String) {
size = json_object["size"_L1].toString().toInt();
}
else {
size = json_obj["size"_L1].toInt();
size = json_object["size"_L1].toInt();
}
qint64 duration = 0;
if (json_obj["duration"_L1].type() == QJsonValue::String) {
duration = json_obj["duration"_L1].toString().toInt() * kNsecPerSec;
if (json_object["duration"_L1].type() == QJsonValue::String) {
duration = json_object["duration"_L1].toString().toInt() * kNsecPerSec;
}
else {
duration = json_obj["duration"_L1].toInt() * kNsecPerSec;
duration = json_object["duration"_L1].toInt() * kNsecPerSec;
}
int bitrate = 0;
if (json_obj.contains("bitRate"_L1)) {
if (json_obj["bitRate"_L1].type() == QJsonValue::String) {
bitrate = json_obj["bitRate"_L1].toString().toInt();
if (json_object.contains("bitRate"_L1)) {
if (json_object["bitRate"_L1].type() == QJsonValue::String) {
bitrate = json_object["bitRate"_L1].toString().toInt();
}
else {
bitrate = json_obj["bitRate"_L1].toInt();
bitrate = json_object["bitRate"_L1].toInt();
}
}
QString mimetype;
if (json_obj.contains("contentType"_L1)) {
mimetype = json_obj["contentType"_L1].toString();
if (json_object.contains("contentType"_L1)) {
mimetype = json_object["contentType"_L1].toString();
}
int year = 0;
if (json_obj.contains("year"_L1)) {
if (json_obj["year"_L1].type() == QJsonValue::String) {
year = json_obj["year"_L1].toString().toInt();
if (json_object.contains("year"_L1)) {
if (json_object["year"_L1].type() == QJsonValue::String) {
year = json_object["year"_L1].toString().toInt();
}
else {
year = json_obj["year"_L1].toInt();
year = json_object["year"_L1].toInt();
}
}
int disc = 0;
if (json_obj.contains("discNumber"_L1)) {
if (json_obj["discNumber"_L1].type() == QJsonValue::String) {
disc = json_obj["discNumber"_L1].toString().toInt();
if (json_object.contains("discNumber"_L1)) {
if (json_object["discNumber"_L1].type() == QJsonValue::String) {
disc = json_object["discNumber"_L1].toString().toInt();
}
else {
disc = json_obj["discNumber"_L1].toInt();
disc = json_object["discNumber"_L1].toInt();
}
}
int track = 0;
if (json_obj.contains("track"_L1)) {
if (json_obj["track"_L1].type() == QJsonValue::String) {
track = json_obj["track"_L1].toString().toInt();
if (json_object.contains("track"_L1)) {
if (json_object["track"_L1].type() == QJsonValue::String) {
track = json_object["track"_L1].toString().toInt();
}
else {
track = json_obj["track"_L1].toInt();
track = json_object["track"_L1].toInt();
}
}
QString genre;
if (json_obj.contains("genre"_L1)) genre = json_obj["genre"_L1].toString();
if (json_object.contains("genre"_L1)) genre = json_object["genre"_L1].toString();
QString cover_id;
if (use_album_id_for_album_covers()) {
cover_id = album_id;
}
else {
if (json_obj.contains("coverArt"_L1)) {
if (json_obj["coverArt"_L1].type() == QJsonValue::String) {
cover_id = json_obj["coverArt"_L1].toString();
if (json_object.contains("coverArt"_L1)) {
if (json_object["coverArt"_L1].type() == QJsonValue::String) {
cover_id = json_object["coverArt"_L1].toString();
}
else {
cover_id = QString::number(json_obj["coverArt"_L1].toInt());
cover_id = QString::number(json_object["coverArt"_L1].toInt());
}
}
else {
@@ -624,8 +566,8 @@ QString SubsonicRequest::ParseSong(Song &song, const QJsonObject &json_obj, cons
}
qint64 created = 0;
if (json_obj.contains("created"_L1)) {
created = QDateTime::fromString(json_obj["created"_L1].toString(), Qt::ISODate).toSecsSinceEpoch();
if (json_object.contains("created"_L1)) {
created = QDateTime::fromString(json_object["created"_L1].toString(), Qt::ISODate).toSecsSinceEpoch();
}
else {
created = album_created;
@@ -745,20 +687,20 @@ void SubsonicRequest::FlushAlbumCoverRequests() {
while (!album_cover_requests_queue_.isEmpty() && album_covers_requests_active_ < kMaxConcurrentAlbumCoverRequests) {
AlbumCoverRequest request = album_cover_requests_queue_.dequeue();
const AlbumCoverRequest request = album_cover_requests_queue_.dequeue();
++album_covers_requests_active_;
QNetworkRequest req(request.url);
req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
req.setAttribute(QNetworkRequest::Http2AllowedAttribute, http2());
QNetworkRequest network_request(request.url);
network_request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
network_request.setAttribute(QNetworkRequest::Http2AllowedAttribute, http2());
if (!verify_certificate()) {
QSslConfiguration sslconfig = QSslConfiguration::defaultConfiguration();
sslconfig.setPeerVerifyMode(QSslSocket::VerifyNone);
req.setSslConfiguration(sslconfig);
network_request.setSslConfiguration(sslconfig);
}
QNetworkReply *reply = network_->get(req);
QNetworkReply *reply = network_->get(network_request);
album_cover_replies_ << reply;
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, request]() { AlbumCoverReceived(reply, request); });
timeouts_->AddReply(reply);
@@ -816,7 +758,7 @@ void SubsonicRequest::AlbumCoverReceived(QNetworkReply *reply, const AlbumCoverR
return;
}
QByteArray data = reply->readAll();
const QByteArray data = reply->readAll();
if (data.isEmpty()) {
Error(QStringLiteral("Received empty image data for %1").arg(request.url.toString()));
if (album_covers_requests_sent_.contains(request.cover_id)) album_covers_requests_sent_.remove(request.cover_id);
@@ -888,7 +830,7 @@ void SubsonicRequest::FinishCheck() {
Q_EMIT Results(songs_, tr("Unknown error"));
}
else {
Q_EMIT Results(songs_, ErrorsToHTML(errors_));
Q_EMIT Results(songs_, Utilities::StringListToHTML(errors_));
}
}

View File

@@ -1,6 +1,6 @@
/*
* Strawberry Music Player
* Copyright 2019-2021, Jonas Kvinge <jonas@jkvinge.net>
* Copyright 2019-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
@@ -98,7 +98,7 @@ class SubsonicRequest : public SubsonicBaseRequest {
void AddAlbumSongsRequest(const QString &artist_id, const QString &album_id, const QString &album_artist, const int offset = 0);
void FlushAlbumSongsRequests();
QString ParseSong(Song &song, const QJsonObject &json_obj, const QString &artist_id_requested = QString(), const QString &album_id_requested = QString(), const QString &album_artist = QString(), const qint64 album_created = 0);
QString ParseSong(Song &song, const QJsonObject &json_object, const QString &artist_id_requested = QString(), const QString &album_id_requested = QString(), const QString &album_artist = QString(), const qint64 album_created = 0);
void GetAlbumCovers();
void AddAlbumCoverRequest(const Song &song);

View File

@@ -1,6 +1,6 @@
/*
* Strawberry Music Player
* Copyright 2019-2021, Jonas Kvinge <jonas@jkvinge.net>
* Copyright 2019-2025, Jonas Kvinge <jonas@jkvinge.net>
* Copyright 2020-2021, Pascal Below <spezifisch@below.fr>
*
* Strawberry is free software: you can redistribute it and/or modify
@@ -98,41 +98,19 @@ void SubsonicScrobbleRequest::ScrobbleReplyReceived(QNetworkReply *reply) {
// "subsonic-response" is empty on success, but some keys like status, version, or type might be present.
// Therefore, we can only check for errors.
QByteArray data = GetReplyData(reply);
if (data.isEmpty()) {
const JsonObjectResult json_object_result = ParseJsonObject(reply);
if (!json_object_result.success()) {
Error(json_object_result.error_message);
FinishCheck();
return;
}
QJsonObject json_obj = ExtractJsonObj(data);
if (json_obj.isEmpty()) {
const QJsonObject &json_object = json_object_result.json_object;
if (json_object.isEmpty()) {
FinishCheck();
return;
}
if (json_obj.contains("error"_L1)) {
QJsonValue json_error = json_obj["error"_L1];
if (!json_error.isObject()) {
Error(u"Json error is not an object."_s, json_obj);
FinishCheck();
return;
}
json_obj = json_error.toObject();
if (!json_obj.isEmpty() && json_obj.contains("code"_L1) && json_obj.contains("message"_L1)) {
int code = json_obj["code"_L1].toInt();
QString message = json_obj["message"_L1].toString();
Error(QStringLiteral("%1 (%2)").arg(message).arg(code));
FinishCheck();
}
else {
Error(u"Json error object is missing code or message."_s, json_obj);
FinishCheck();
return;
}
return;
}
FinishCheck();
}

View File

@@ -1,6 +1,6 @@
/*
* Strawberry Music Player
* Copyright 2019-2021, Jonas Kvinge <jonas@jkvinge.net>
* Copyright 2019-2025, Jonas Kvinge <jonas@jkvinge.net>
* Copyright 2020-2021, Pascal Below <spezifisch@below.fr>
*
* Strawberry is free software: you can redistribute it and/or modify

View File

@@ -1,6 +1,6 @@
/*
* Strawberry Music Player
* Copyright 2019-2021, Jonas Kvinge <jonas@jkvinge.net>
* Copyright 2019-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
@@ -184,20 +184,20 @@ void SubsonicService::SendPingWithCredentials(QUrl url, const QString &username,
url.setQuery(url_query);
QNetworkRequest req(url);
QNetworkRequest network_request(url);
if (url.scheme() == "https"_L1 && !verify_certificate_) {
QSslConfiguration sslconfig = QSslConfiguration::defaultConfiguration();
sslconfig.setPeerVerifyMode(QSslSocket::VerifyNone);
req.setSslConfiguration(sslconfig);
network_request.setSslConfiguration(sslconfig);
}
req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
req.setHeader(QNetworkRequest::ContentTypeHeader, u"application/x-www-form-urlencoded"_s);
req.setAttribute(QNetworkRequest::Http2AllowedAttribute, http2_);
network_request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
network_request.setHeader(QNetworkRequest::ContentTypeHeader, u"application/x-www-form-urlencoded"_s);
network_request.setAttribute(QNetworkRequest::Http2AllowedAttribute, http2_);
errors_.clear();
QNetworkReply *reply = network_->get(req);
QNetworkReply *reply = network_->get(network_request);
replies_ << reply;
QObject::connect(reply, &QNetworkReply::sslErrors, this, &SubsonicService::HandlePingSSLErrors);
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, url, username, password, auth_method]() { HandlePingReply(reply, url, username, password, auth_method); });

View File

@@ -1,6 +1,6 @@
/*
* Strawberry Music Player
* Copyright 2019-2021, Jonas Kvinge <jonas@jkvinge.net>
* Copyright 2019-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
@@ -38,10 +38,10 @@
#include "includes/scoped_ptr.h"
#include "includes/shared_ptr.h"
#include "core/song.h"
#include "collection/collectionmodel.h"
#include "streaming/streamingservice.h"
#include "constants/subsonicsettings.h"
#include "core/song.h"
#include "streaming/streamingservice.h"
#include "collection/collectionmodel.h"
class QNetworkReply;

View File

@@ -1,6 +1,6 @@
/*
* Strawberry Music Player
* Copyright 2019-2021, Jonas Kvinge <jonas@jkvinge.net>
* Copyright 2019-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
@@ -19,7 +19,6 @@
#include "config.h"
#include <QtGlobal>
#include <QUrl>
#include <QUrlQuery>

View File

@@ -1,6 +1,6 @@
/*
* Strawberry Music Player
* Copyright 2019-2021, Jonas Kvinge <jonas@jkvinge.net>
* Copyright 2019-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
@@ -22,9 +22,6 @@
#include "config.h"
#include <QObject>
#include <QPair>
#include <QList>
#include <QString>
#include <QUrl>