2019-06-17 23:54:24 +02:00
|
|
|
/*
|
|
|
|
* Strawberry Music Player
|
2021-03-20 21:14:47 +01:00
|
|
|
* Copyright 2019-2021, Jonas Kvinge <jonas@jkvinge.net>
|
2019-06-17 23:54:24 +02:00
|
|
|
*
|
|
|
|
* Strawberry is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Strawberry is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SUBSONICREQUEST_H
|
|
|
|
#define SUBSONICREQUEST_H
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <QtGlobal>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QPair>
|
2020-02-09 02:29:35 +01:00
|
|
|
#include <QSet>
|
2019-06-17 23:54:24 +02:00
|
|
|
#include <QList>
|
|
|
|
#include <QHash>
|
2020-02-09 02:29:35 +01:00
|
|
|
#include <QMap>
|
2019-06-17 23:54:24 +02:00
|
|
|
#include <QMultiMap>
|
|
|
|
#include <QQueue>
|
2020-02-09 02:29:35 +01:00
|
|
|
#include <QVariant>
|
2019-06-17 23:54:24 +02:00
|
|
|
#include <QString>
|
2019-07-07 21:14:24 +02:00
|
|
|
#include <QStringList>
|
2019-06-17 23:54:24 +02:00
|
|
|
#include <QUrl>
|
|
|
|
#include <QJsonObject>
|
|
|
|
|
|
|
|
#include "core/song.h"
|
|
|
|
#include "subsonicbaserequest.h"
|
|
|
|
|
2022-02-06 00:58:50 +01:00
|
|
|
class QNetworkAccessManager;
|
2020-02-09 02:29:35 +01:00
|
|
|
class QNetworkReply;
|
2019-07-07 21:14:24 +02:00
|
|
|
class Application;
|
2019-06-17 23:54:24 +02:00
|
|
|
class SubsonicService;
|
|
|
|
class SubsonicUrlHandler;
|
2021-09-05 21:47:00 +02:00
|
|
|
class NetworkTimeouts;
|
2019-06-17 23:54:24 +02:00
|
|
|
|
|
|
|
class SubsonicRequest : public SubsonicBaseRequest {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2021-07-01 02:01:38 +02:00
|
|
|
explicit SubsonicRequest(SubsonicService *service, SubsonicUrlHandler *url_handler, Application *app, QObject *parent = nullptr);
|
2020-06-15 21:55:05 +02:00
|
|
|
~SubsonicRequest() override;
|
2019-06-17 23:54:24 +02:00
|
|
|
|
|
|
|
void ReloadSettings();
|
|
|
|
|
|
|
|
void GetAlbums();
|
|
|
|
void Reset();
|
|
|
|
|
2022-03-22 21:09:05 +01:00
|
|
|
private:
|
2019-06-17 23:54:24 +02:00
|
|
|
struct Request {
|
2020-05-12 15:55:13 +02:00
|
|
|
explicit Request() : offset(0), size(0) {}
|
|
|
|
QString artist_id;
|
2020-01-20 17:45:40 +01:00
|
|
|
QString album_id;
|
2020-05-12 15:55:13 +02:00
|
|
|
QString song_id;
|
|
|
|
int offset;
|
|
|
|
int size;
|
2019-06-17 23:54:24 +02:00
|
|
|
QString album_artist;
|
|
|
|
};
|
|
|
|
struct AlbumCoverRequest {
|
2020-05-12 15:55:13 +02:00
|
|
|
QString artist_id;
|
|
|
|
QString album_id;
|
2022-01-30 02:30:51 +01:00
|
|
|
QString cover_id;
|
2019-06-17 23:54:24 +02:00
|
|
|
QUrl url;
|
|
|
|
QString filename;
|
|
|
|
};
|
|
|
|
|
2022-01-30 02:30:51 +01:00
|
|
|
signals:
|
|
|
|
void Results(SongMap songs, QString error);
|
|
|
|
void UpdateStatus(QString text);
|
|
|
|
void ProgressSetMaximum(int max);
|
|
|
|
void UpdateProgress(int max);
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void AlbumsReplyReceived(QNetworkReply *reply, const int offset_requested, const int size_requested);
|
|
|
|
void AlbumSongsReplyReceived(QNetworkReply *reply, const QString &artist_id, const QString &album_id, const QString &album_artist);
|
|
|
|
void AlbumCoverReceived(QNetworkReply *reply, const AlbumCoverRequest &request);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2021-07-30 21:17:44 +02:00
|
|
|
void AddAlbumsRequest(const int offset = 0, const int size = 500);
|
2019-06-17 23:54:24 +02:00
|
|
|
void FlushAlbumsRequests();
|
|
|
|
|
2021-07-30 21:17:44 +02:00
|
|
|
void AlbumsFinishCheck(const int offset = 0, const int size = 0, const int albums_received = 0);
|
2019-06-17 23:54:24 +02:00
|
|
|
void SongsFinishCheck();
|
|
|
|
|
2020-04-13 03:39:51 +02:00
|
|
|
void AddAlbumSongsRequest(const QString &artist_id, const QString &album_id, const QString &album_artist, const int offset = 0);
|
2019-06-17 23:54:24 +02:00
|
|
|
void FlushAlbumSongsRequests();
|
|
|
|
|
2020-10-11 00:07:38 +02:00
|
|
|
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);
|
2019-06-17 23:54:24 +02:00
|
|
|
|
|
|
|
void GetAlbumCovers();
|
2021-07-01 02:01:38 +02:00
|
|
|
void AddAlbumCoverRequest(const Song &song);
|
2019-06-17 23:54:24 +02:00
|
|
|
void FlushAlbumCoverRequests();
|
|
|
|
void AlbumCoverFinishCheck();
|
|
|
|
|
|
|
|
void FinishCheck();
|
2021-06-22 13:41:38 +02:00
|
|
|
static void Warn(const QString &error, const QVariant &debug = QVariant());
|
2020-06-15 21:55:05 +02:00
|
|
|
void Error(const QString &error, const QVariant &debug = QVariant()) override;
|
2019-06-17 23:54:24 +02:00
|
|
|
|
|
|
|
static const int kMaxConcurrentAlbumsRequests;
|
|
|
|
static const int kMaxConcurrentArtistAlbumsRequests;
|
|
|
|
static const int kMaxConcurrentAlbumSongsRequests;
|
|
|
|
static const int kMaxConcurrentAlbumCoverRequests;
|
|
|
|
|
|
|
|
SubsonicService *service_;
|
|
|
|
SubsonicUrlHandler *url_handler_;
|
2019-07-07 21:14:24 +02:00
|
|
|
Application *app_;
|
2022-02-06 00:58:50 +01:00
|
|
|
QNetworkAccessManager *network_;
|
2021-09-05 21:47:00 +02:00
|
|
|
NetworkTimeouts *timeouts_;
|
2019-06-17 23:54:24 +02:00
|
|
|
|
|
|
|
bool finished_;
|
|
|
|
|
|
|
|
QQueue<Request> albums_requests_queue_;
|
|
|
|
QQueue<Request> album_songs_requests_queue_;
|
|
|
|
QQueue<AlbumCoverRequest> album_cover_requests_queue_;
|
|
|
|
|
2020-01-20 17:45:40 +01:00
|
|
|
QHash<QString, Request> album_songs_requests_pending_;
|
2022-01-30 02:30:51 +01:00
|
|
|
QMultiMap<QString, QString> album_covers_requests_sent_;
|
2019-06-17 23:54:24 +02:00
|
|
|
|
|
|
|
int albums_requests_active_;
|
|
|
|
|
|
|
|
int album_songs_requests_active_;
|
|
|
|
int album_songs_requested_;
|
|
|
|
int album_songs_received_;
|
|
|
|
|
|
|
|
int album_covers_requests_active_;
|
|
|
|
int album_covers_requested_;
|
|
|
|
int album_covers_received_;
|
|
|
|
|
2021-09-19 15:41:36 +02:00
|
|
|
SongMap songs_;
|
2022-01-30 02:30:51 +01:00
|
|
|
QMap<QString, QUrl> cover_urls_;
|
2019-07-07 21:14:24 +02:00
|
|
|
QStringList errors_;
|
2019-06-17 23:54:24 +02:00
|
|
|
bool no_results_;
|
2019-08-05 18:38:27 +02:00
|
|
|
QList<QNetworkReply*> replies_;
|
2019-06-17 23:54:24 +02:00
|
|
|
QList<QNetworkReply*> album_cover_replies_;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SUBSONICREQUEST_H
|