1
0
mirror of https://github.com/strawberrymusicplayer/strawberry synced 2024-12-12 00:35:31 +01:00

Fix minor code issues in tidal

This commit is contained in:
Jonas Kvinge 2019-06-18 23:39:16 +02:00
parent dabd6f8284
commit dbd2edf442
7 changed files with 26 additions and 24 deletions

View File

@ -85,11 +85,9 @@ QNetworkReply *TidalCoverProvider::CreateRequest(const QString &ressource_name,
<< Param("sessionId", service_->session_id()) << Param("sessionId", service_->session_id())
<< Param("countryCode", service_->country_code()); << Param("countryCode", service_->country_code());
QStringList query_items;
QUrlQuery url_query; QUrlQuery url_query;
for (const Param& param : parameters) { for (const Param& param : parameters) {
EncodedParam encoded_param(QUrl::toPercentEncoding(param.first), QUrl::toPercentEncoding(param.second)); EncodedParam encoded_param(QUrl::toPercentEncoding(param.first), QUrl::toPercentEncoding(param.second));
query_items << QString(encoded_param.first + "=" + encoded_param.second);
url_query.addQueryItem(encoded_param.first, encoded_param.second); url_query.addQueryItem(encoded_param.first, encoded_param.second);
} }

View File

@ -63,11 +63,9 @@ QNetworkReply *TidalBaseRequest::CreateRequest(const QString &ressource_name, co
ParamList params = ParamList() << params_provided ParamList params = ParamList() << params_provided
<< Param("countryCode", country_code()); << Param("countryCode", country_code());
QStringList query_items;
QUrlQuery url_query; QUrlQuery url_query;
for (const Param& param : params) { for (const Param& param : params) {
EncodedParam encoded_param(QUrl::toPercentEncoding(param.first), QUrl::toPercentEncoding(param.second)); EncodedParam encoded_param(QUrl::toPercentEncoding(param.first), QUrl::toPercentEncoding(param.second));
query_items << QString(encoded_param.first + "=" + encoded_param.second);
url_query.addQueryItem(encoded_param.first, encoded_param.second); url_query.addQueryItem(encoded_param.first, encoded_param.second);
} }
@ -97,8 +95,14 @@ QByteArray TidalBaseRequest::GetReplyData(QNetworkReply *reply, QString &error,
QByteArray data; QByteArray data;
if (reply->error() == QNetworkReply::NoError) { if (reply->error() == QNetworkReply::NoError) {
int http_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
if (http_code == 200) {
data = reply->readAll(); data = reply->readAll();
} }
else {
error = Error(QString("Received HTTP code %1").arg(http_code));
}
}
else { else {
if (reply->error() < 200) { if (reply->error() < 200) {
// This is a network error, there is nothing more to do. // This is a network error, there is nothing more to do.

View File

@ -132,11 +132,9 @@ void TidalFavoriteRequest::AddFavorites(const FavoriteType type, const SongList
ParamList params = ParamList() << Param("countryCode", country_code()) ParamList params = ParamList() << Param("countryCode", country_code())
<< Param(text, ids); << Param(text, ids);
QStringList query_items;
QUrlQuery url_query; QUrlQuery url_query;
for (const Param& param : params) { for (const Param& param : params) {
EncodedParam encoded_param(QUrl::toPercentEncoding(param.first), QUrl::toPercentEncoding(param.second)); EncodedParam encoded_param(QUrl::toPercentEncoding(param.first), QUrl::toPercentEncoding(param.second));
query_items << QString(encoded_param.first + "=" + encoded_param.second);
url_query.addQueryItem(encoded_param.first, encoded_param.second); url_query.addQueryItem(encoded_param.first, encoded_param.second);
} }
@ -236,11 +234,9 @@ void TidalFavoriteRequest::RemoveFavorites(const FavoriteType type, const int id
ParamList params = ParamList() << Param("countryCode", country_code()); ParamList params = ParamList() << Param("countryCode", country_code());
QStringList query_items;
QUrlQuery url_query; QUrlQuery url_query;
for (const Param& param : params) { for (const Param& param : params) {
EncodedParam encoded_param(QUrl::toPercentEncoding(param.first), QUrl::toPercentEncoding(param.second)); EncodedParam encoded_param(QUrl::toPercentEncoding(param.first), QUrl::toPercentEncoding(param.second));
query_items << QString(encoded_param.first + "=" + encoded_param.second);
url_query.addQueryItem(encoded_param.first, encoded_param.second); url_query.addQueryItem(encoded_param.first, encoded_param.second);
} }

View File

@ -172,7 +172,7 @@ void TidalRequest::FlushArtistsRequests() {
if (type_ == QueryType_SearchArtists) { if (type_ == QueryType_SearchArtists) {
reply = CreateRequest("search/artists", parameters); reply = CreateRequest("search/artists", parameters);
} }
NewClosure(reply, SIGNAL(finished()), this, SLOT(ArtistsReplyReceived(QNetworkReply*, int, int)), reply, request.limit, request.offset); NewClosure(reply, SIGNAL(finished()), this, SLOT(ArtistsReplyReceived(QNetworkReply*, const int, const int)), reply, request.limit, request.offset);
} }
@ -214,7 +214,7 @@ void TidalRequest::FlushAlbumsRequests() {
if (type_ == QueryType_SearchAlbums) { if (type_ == QueryType_SearchAlbums) {
reply = CreateRequest("search/albums", parameters); reply = CreateRequest("search/albums", parameters);
} }
NewClosure(reply, SIGNAL(finished()), this, SLOT(AlbumsReplyReceived(QNetworkReply*, int, int)), reply, request.limit, request.offset); NewClosure(reply, SIGNAL(finished()), this, SLOT(AlbumsReplyReceived(QNetworkReply*, const int, const int)), reply, request.limit, request.offset);
} }
@ -256,7 +256,7 @@ void TidalRequest::FlushSongsRequests() {
if (type_ == QueryType_SearchSongs) { if (type_ == QueryType_SearchSongs) {
reply = CreateRequest("search/tracks", parameters); reply = CreateRequest("search/tracks", parameters);
} }
NewClosure(reply, SIGNAL(finished()), this, SLOT(SongsReplyReceived(QNetworkReply*, int, int)), reply, request.limit, request.offset); NewClosure(reply, SIGNAL(finished()), this, SLOT(SongsReplyReceived(QNetworkReply*, const int, const int)), reply, request.limit, request.offset);
} }
@ -469,7 +469,7 @@ void TidalRequest::FlushArtistAlbumsRequests() {
ParamList parameters; ParamList parameters;
if (request.offset > 0) parameters << Param("offset", QString::number(request.offset)); if (request.offset > 0) parameters << Param("offset", QString::number(request.offset));
QNetworkReply *reply = CreateRequest(QString("artists/%1/albums").arg(request.artist_id), parameters); QNetworkReply *reply = CreateRequest(QString("artists/%1/albums").arg(request.artist_id), parameters);
NewClosure(reply, SIGNAL(finished()), this, SLOT(ArtistAlbumsReplyReceived(QNetworkReply*, int, int)), reply, request.artist_id, request.offset); NewClosure(reply, SIGNAL(finished()), this, SLOT(ArtistAlbumsReplyReceived(QNetworkReply*, const int, const int)), reply, request.artist_id, request.offset);
} }
@ -712,13 +712,13 @@ void TidalRequest::FlushAlbumSongsRequests() {
ParamList parameters; ParamList parameters;
if (request.offset > 0) parameters << Param("offset", QString::number(request.offset)); if (request.offset > 0) parameters << Param("offset", QString::number(request.offset));
QNetworkReply *reply = CreateRequest(QString("albums/%1/tracks").arg(request.album_id), parameters); QNetworkReply *reply = CreateRequest(QString("albums/%1/tracks").arg(request.album_id), parameters);
NewClosure(reply, SIGNAL(finished()), this, SLOT(AlbumSongsReplyReceived(QNetworkReply*, int, int, int, QString)), reply, request.artist_id, request.album_id, request.offset, request.album_artist); NewClosure(reply, SIGNAL(finished()), this, SLOT(AlbumSongsReplyReceived(QNetworkReply*, const int, const int, const int, const QString&)), reply, request.artist_id, request.album_id, request.offset, request.album_artist);
} }
} }
void TidalRequest::AlbumSongsReplyReceived(QNetworkReply *reply, const int artist_id, const int album_id, const int offset_requested, const QString album_artist) { void TidalRequest::AlbumSongsReplyReceived(QNetworkReply *reply, const int artist_id, const int album_id, const int offset_requested, const QString &album_artist) {
--album_songs_requests_active_; --album_songs_requests_active_;
++album_songs_received_; ++album_songs_received_;
@ -729,7 +729,7 @@ void TidalRequest::AlbumSongsReplyReceived(QNetworkReply *reply, const int artis
} }
void TidalRequest::SongsReceived(QNetworkReply *reply, const int artist_id, const int album_id, const int limit_requested, const int offset_requested, const bool auto_login, const QString album_artist) { void TidalRequest::SongsReceived(QNetworkReply *reply, const int artist_id, const int album_id, const int limit_requested, const int offset_requested, const bool auto_login, const QString &album_artist) {
QString error; QString error;
QByteArray data = GetReplyData(reply, error, auto_login); QByteArray data = GetReplyData(reply, error, auto_login);
@ -1033,13 +1033,13 @@ void TidalRequest::FlushAlbumCoverRequests() {
QNetworkRequest req(request.url); QNetworkRequest req(request.url);
QNetworkReply *reply = network_->get(req); QNetworkReply *reply = network_->get(req);
album_cover_replies_ << reply; album_cover_replies_ << reply;
NewClosure(reply, SIGNAL(finished()), this, SLOT(AlbumCoverReceived(QNetworkReply*, int, QUrl)), reply, request.album_id, request.url); NewClosure(reply, SIGNAL(finished()), this, SLOT(AlbumCoverReceived(QNetworkReply*, const int, const QUrl&)), reply, request.album_id, request.url);
} }
} }
void TidalRequest::AlbumCoverReceived(QNetworkReply *reply, const int album_id, const QUrl url) { void TidalRequest::AlbumCoverReceived(QNetworkReply *reply, const int album_id, const QUrl &url) {
if (album_cover_replies_.contains(reply)) { if (album_cover_replies_.contains(reply)) {
album_cover_replies_.removeAll(reply); album_cover_replies_.removeAll(reply);

View File

@ -81,11 +81,11 @@ class TidalRequest : public TidalBaseRequest {
void AlbumsReceived(QNetworkReply *reply, const int artist_id_requested, const int limit_requested, const int offset_requested, const bool auto_login); void AlbumsReceived(QNetworkReply *reply, const int artist_id_requested, const int limit_requested, const int offset_requested, const bool auto_login);
void SongsReplyReceived(QNetworkReply *reply, const int limit_requested, const int offset_requested); void SongsReplyReceived(QNetworkReply *reply, const int limit_requested, const int offset_requested);
void SongsReceived(QNetworkReply *reply, const int artist_id, const int album_id, const int limit_requested, const int offset_requested, const bool auto_login = false, const QString album_artist = QString()); void SongsReceived(QNetworkReply *reply, const int artist_id, const int album_id, const int limit_requested, const int offset_requested, const bool auto_login = false, const QString &album_artist = QString());
void ArtistAlbumsReplyReceived(QNetworkReply *reply, const int artist_id, const int offset_requested); void ArtistAlbumsReplyReceived(QNetworkReply *reply, const int artist_id, const int offset_requested);
void AlbumSongsReplyReceived(QNetworkReply *reply, const int artist_id, const int album_id, const int offset_requested, const QString album_artist); void AlbumSongsReplyReceived(QNetworkReply *reply, const int artist_id, const int album_id, const int offset_requested, const QString &album_artist);
void AlbumCoverReceived(QNetworkReply *reply, const int album_id, const QUrl url); void AlbumCoverReceived(QNetworkReply *reply, const int album_id, const QUrl &url);
private: private:
typedef QPair<QString, QString> Param; typedef QPair<QString, QString> Param;

View File

@ -366,6 +366,12 @@ void TidalService::AccessTokenRequestFinished(QNetworkReply *reply) {
} }
} }
int http_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
if (http_code != 200) {
LoginError(QString("Received HTTP code %1").arg(http_code));
return;
}
QByteArray data(reply->readAll()); QByteArray data(reply->readAll());
QJsonParseError json_error; QJsonParseError json_error;
QJsonDocument json_doc = QJsonDocument::fromJson(data, &json_error); QJsonDocument json_doc = QJsonDocument::fromJson(data, &json_error);
@ -459,11 +465,9 @@ void TidalService::SendLogin(const QString &username, const QString &password, c
<< Param("password", password) << Param("password", password)
<< Param("clientVersion", "2.2.1--7"); << Param("clientVersion", "2.2.1--7");
QStringList query_items;
QUrlQuery url_query; QUrlQuery url_query;
for (const Param &param : params) { for (const Param &param : params) {
EncodedParam encoded_param(QUrl::toPercentEncoding(param.first), QUrl::toPercentEncoding(param.second)); EncodedParam encoded_param(QUrl::toPercentEncoding(param.first), QUrl::toPercentEncoding(param.second));
query_items << QString(encoded_param.first + "=" + encoded_param.second);
url_query.addQueryItem(encoded_param.first, encoded_param.second); url_query.addQueryItem(encoded_param.first, encoded_param.second);
} }

View File

@ -271,7 +271,7 @@ void TidalStreamURLRequest::StreamURLReceived() {
if (urls.isEmpty()) { if (urls.isEmpty()) {
error = Error("Missing stream urls.", json_obj); error = Error("Missing stream urls.", json_obj);
emit StreamURLFinished(original_url_, original_url_, filetype); emit StreamURLFinished(original_url_, original_url_, filetype, error);
return; return;
} }