Queue tidal requests
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -29,6 +29,7 @@
|
||||
#include <QHash>
|
||||
#include <QMap>
|
||||
#include <QMultiMap>
|
||||
#include <QQueue>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QNetworkReply>
|
||||
@@ -71,41 +72,100 @@ class TidalRequest : public TidalBaseRequest {
|
||||
void UpdateProgress(int max);
|
||||
void StreamURLFinished(const QUrl original_url, const QUrl url, const Song::FileType, QString error = QString());
|
||||
|
||||
public slots:
|
||||
void GetArtists(const int offset = 0);
|
||||
void GetAlbums(const int offset = 0);
|
||||
void GetSongs(const int offset = 0);
|
||||
|
||||
private slots:
|
||||
void LoginComplete(bool success, QString error = QString());
|
||||
void ArtistsReceived(QNetworkReply *reply, const int limit_requested = 0, const int offset_requested = 0);
|
||||
void AlbumsReceived(QNetworkReply *reply, const int artist_id = 0, const int limit_requested = 0, const int offset_requested = 0);
|
||||
void SongsReceived(QNetworkReply *reply, const int album_id);
|
||||
|
||||
void ArtistsReplyReceived(QNetworkReply *reply, const int limit_requested, const int offset_requested);
|
||||
|
||||
void AlbumsReplyReceived(QNetworkReply *reply, const int limit_requested, const int offset_requested);
|
||||
void AlbumsReceived(QNetworkReply *reply, const int artist_id, 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 QString album_artist = QString());
|
||||
|
||||
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 AlbumCoverReceived(QNetworkReply *reply, const int album_id, const QUrl url);
|
||||
|
||||
private:
|
||||
typedef QPair<QString, QString> Param;
|
||||
typedef QList<Param> ParamList;
|
||||
|
||||
struct Request {
|
||||
//Request(const int artist_id = 0, const int limit = 0, const int offset = 0) :
|
||||
//artist_id_(artist_id), limit_(limit), offset_(offset) {}
|
||||
int artist_id = 0;
|
||||
int album_id = 0;
|
||||
int song_id = 0;
|
||||
int offset = 0;
|
||||
int limit = 0;
|
||||
QString album_artist;
|
||||
};
|
||||
struct AlbumCoverRequest {
|
||||
int artist_id = 0;
|
||||
int album_id = 0;
|
||||
QUrl url;
|
||||
};
|
||||
|
||||
#if 0
|
||||
struct AlbumSongsRequest {
|
||||
AlbumSongsRequest(const int artist_id = 0, const int album_id = 0, const QString &album_artist = QString()) :
|
||||
artist_id_(artist_id), album_id_(album_id), album_artist_(album_artist) {}
|
||||
int artist_id_;
|
||||
int album_id_;
|
||||
QString album_artist_;
|
||||
};
|
||||
#endif
|
||||
|
||||
const bool IsQuery() { return (type_ == QueryType_Artists || type_ == QueryType_Albums || type_ == QueryType_Songs); }
|
||||
const bool IsSearch() { return (type_ == QueryType_SearchArtists || type_ == QueryType_SearchAlbums || type_ == QueryType_SearchSongs); }
|
||||
|
||||
void SendSearch();
|
||||
void ArtistsSearch(const int offset = 0);
|
||||
void AlbumsSearch(const int offset = 0);
|
||||
void SongsSearch(const int offset = 0);
|
||||
void GetArtists();
|
||||
void GetAlbums();
|
||||
void GetSongs();
|
||||
|
||||
void ArtistsSearch();
|
||||
void AlbumsSearch();
|
||||
void SongsSearch();
|
||||
|
||||
void AddArtistsRequest(const int offset = 0, const int limit = 0);
|
||||
void AddArtistsSearchRequest(const int offset = 0);
|
||||
void FlushArtistsRequests();
|
||||
void AddAlbumsRequest(const int offset = 0, const int limit = 0);
|
||||
void AddAlbumsSearchRequest(const int offset = 0);
|
||||
void FlushAlbumsRequests();
|
||||
void AddSongsRequest(const int offset = 0, const int limit = 0);
|
||||
void AddSongsSearchRequest(const int offset = 0);
|
||||
void FlushSongsRequests();
|
||||
|
||||
void ArtistsFinishCheck(const int limit = 0, const int offset = 0, const int artists_received = 0);
|
||||
void AlbumsFinishCheck(const int artist_id, const int limit = 0, const int offset = 0, const int albums_total = 0, const int albums_received = 0);
|
||||
void GetArtistAlbums(const int artist_id, const int offset = 0);
|
||||
void GetAlbumSongs(const int album_id);
|
||||
int ParseSong(Song &song, const int album_id_requested, const QJsonValue &value, QString album_artist = QString());
|
||||
void SongsFinishCheck(const int artist_id, const int album_id, const int limit, const int offset, const int songs_total, const int songs_received, const QString &album_artist);
|
||||
|
||||
void AddArtistAlbumsRequest(const int artist_id, const int offset = 0);
|
||||
void FlushArtistAlbumsRequests();
|
||||
|
||||
void AddAlbumSongsRequest(const int artist_id, const int album_id, const QString &album_artist, const int offset = 0);
|
||||
void FlushAlbumSongsRequests();
|
||||
|
||||
int ParseSong(Song &song, const QJsonObject &json_obj, const int artist_id_requested = 0, const int album_id_requested = 0, const QString &album_artist = QString());
|
||||
|
||||
void GetAlbumCovers();
|
||||
void GetAlbumCover(Song &song);
|
||||
void AddAlbumCoverRequest(Song &song);
|
||||
void FlushAlbumCoverRequests();
|
||||
void AlbumCoverFinishCheck();
|
||||
|
||||
void FinishCheck();
|
||||
QString LoginError(QString error, QVariant debug = QVariant());
|
||||
void Warn(QString error, QVariant debug = QVariant());
|
||||
QString Error(QString error, QVariant debug = QVariant());
|
||||
|
||||
static const char *kResourcesUrl;
|
||||
static const int kMaxConcurrentArtistsRequests;
|
||||
static const int kMaxConcurrentAlbumsRequests;
|
||||
static const int kMaxConcurrentSongsRequests;
|
||||
static const int kMaxConcurrentArtistAlbumsRequests;
|
||||
static const int kMaxConcurrentAlbumSongsRequests;
|
||||
static const int kMaxConcurrentAlbumCoverRequests;
|
||||
|
||||
TidalService *service_;
|
||||
TidalUrlHandler *url_handler_;
|
||||
@@ -115,20 +175,38 @@ class TidalRequest : public TidalBaseRequest {
|
||||
|
||||
int search_id_;
|
||||
QString search_text_;
|
||||
QList<int> artist_albums_queue_;
|
||||
QList<int> artist_albums_requests_;
|
||||
QHash<int, QString> album_songs_requests_;
|
||||
QMultiMap<int, Song*> album_covers_requests_;
|
||||
|
||||
QQueue<Request> artists_requests_queue_;
|
||||
QQueue<Request> albums_requests_queue_;
|
||||
QQueue<Request> songs_requests_queue_;
|
||||
|
||||
QQueue<Request> artist_albums_requests_queue_;
|
||||
QQueue<Request> album_songs_requests_queue_;
|
||||
QQueue<AlbumCoverRequest> album_cover_requests_queue_;
|
||||
|
||||
QList<int> artist_albums_requests_pending_;
|
||||
QHash<int, Request> album_songs_requests_pending_;
|
||||
QMultiMap<int, Song*> album_covers_requests_sent_;
|
||||
|
||||
int artists_requests_active_;
|
||||
int artists_total_;
|
||||
int artists_chunk_requested_;
|
||||
int artists_chunk_received_;
|
||||
int artists_received_;
|
||||
int artist_albums_chunk_requested_;
|
||||
int artist_albums_chunk_received_;
|
||||
|
||||
int albums_requests_active_;
|
||||
int songs_requests_active_;
|
||||
|
||||
int artist_albums_requests_active_;
|
||||
int artist_albums_requested_;
|
||||
int artist_albums_received_;
|
||||
|
||||
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_;
|
||||
|
||||
SongList songs_;
|
||||
QString errors_;
|
||||
bool need_login_;
|
||||
|
||||
@@ -365,65 +365,125 @@ void TidalService::TryLogin() {
|
||||
|
||||
}
|
||||
|
||||
void TidalService::ResetArtistsRequest() {
|
||||
|
||||
if (artists_request_.get()) {
|
||||
disconnect(artists_request_.get(), 0, nullptr, 0);
|
||||
disconnect(this, 0, artists_request_.get(), 0);
|
||||
artists_request_.reset();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TidalService::GetArtists() {
|
||||
|
||||
ResetArtistsRequest();
|
||||
|
||||
artists_request_.reset(new TidalRequest(this, url_handler_, network_, TidalBaseRequest::QueryType_Artists, this));
|
||||
|
||||
connect(artists_request_.get(), SIGNAL(ErrorSignal(QString)), SIGNAL(ArtistsError(QString)));
|
||||
connect(artists_request_.get(), SIGNAL(ErrorSignal(QString)), SLOT(ArtistsErrorReceived(QString)));
|
||||
connect(artists_request_.get(), SIGNAL(Results(SongList)), SLOT(ArtistsResultsReceived(SongList)));
|
||||
connect(artists_request_.get(), SIGNAL(UpdateStatus(QString)), SIGNAL(ArtistsUpdateStatus(QString)));
|
||||
connect(artists_request_.get(), SIGNAL(ProgressSetMaximum(int)), SIGNAL(ArtistsProgressSetMaximum(int)));
|
||||
connect(artists_request_.get(), SIGNAL(UpdateProgress(int)), SIGNAL(ArtistsUpdateProgress(int)));
|
||||
connect(artists_request_.get(), SIGNAL(Results(SongList)), SIGNAL(ArtistsResults(SongList)));
|
||||
connect(this, SIGNAL(LoginComplete(bool, QString)), artists_request_.get(), SLOT(LoginComplete(bool, QString)));
|
||||
|
||||
artists_request_->Process();
|
||||
|
||||
}
|
||||
|
||||
void TidalService::UpdateArtists(SongList songs) {
|
||||
void TidalService::ArtistsResultsReceived(SongList songs) {
|
||||
|
||||
artists_collection_backend_->DeleteAll();
|
||||
artists_collection_backend_->AddOrUpdateSongs(songs);
|
||||
artists_collection_model_->Reset();
|
||||
emit ArtistsResults(songs);
|
||||
ResetArtistsRequest();
|
||||
|
||||
}
|
||||
|
||||
void TidalService::ArtistsErrorReceived(QString error) {
|
||||
|
||||
emit ArtistsError(error);
|
||||
ResetArtistsRequest();
|
||||
|
||||
}
|
||||
|
||||
void TidalService::ResetAlbumsRequest() {
|
||||
|
||||
if (albums_request_.get()) {
|
||||
disconnect(albums_request_.get(), 0, nullptr, 0);
|
||||
disconnect(this, 0, albums_request_.get(), 0);
|
||||
albums_request_.reset();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TidalService::GetAlbums() {
|
||||
|
||||
ResetAlbumsRequest();
|
||||
albums_request_.reset(new TidalRequest(this, url_handler_, network_, TidalBaseRequest::QueryType_Albums, this));
|
||||
connect(albums_request_.get(), SIGNAL(ErrorSignal(QString)), SIGNAL(AlbumsError(QString)));
|
||||
connect(albums_request_.get(), SIGNAL(ErrorSignal(QString)), SLOT(AlbumsErrorReceived(QString)));
|
||||
connect(albums_request_.get(), SIGNAL(Results(SongList)), SLOT(AlbumsResultsReceived(SongList)));
|
||||
connect(albums_request_.get(), SIGNAL(UpdateStatus(QString)), SIGNAL(AlbumsUpdateStatus(QString)));
|
||||
connect(albums_request_.get(), SIGNAL(ProgressSetMaximum(int)), SIGNAL(AlbumsProgressSetMaximum(int)));
|
||||
connect(albums_request_.get(), SIGNAL(UpdateProgress(int)), SIGNAL(AlbumsUpdateProgress(int)));
|
||||
connect(albums_request_.get(), SIGNAL(Results(SongList)), SIGNAL(AlbumsResults(SongList)));
|
||||
connect(this, SIGNAL(LoginComplete(bool, QString)), albums_request_.get(), SLOT(LoginComplete(bool, QString)));
|
||||
|
||||
albums_request_->Process();
|
||||
|
||||
}
|
||||
|
||||
void TidalService::UpdateAlbums(SongList songs) {
|
||||
void TidalService::AlbumsResultsReceived(SongList songs) {
|
||||
|
||||
albums_collection_backend_->DeleteAll();
|
||||
albums_collection_backend_->AddOrUpdateSongs(songs);
|
||||
albums_collection_model_->Reset();
|
||||
emit AlbumsResults(songs);
|
||||
ResetAlbumsRequest();
|
||||
|
||||
}
|
||||
|
||||
void TidalService::AlbumsErrorReceived(QString error) {
|
||||
|
||||
emit AlbumsError(error);
|
||||
ResetAlbumsRequest();
|
||||
|
||||
}
|
||||
|
||||
void TidalService::ResetSongsRequest() {
|
||||
|
||||
if (songs_request_.get()) {
|
||||
disconnect(songs_request_.get(), 0, nullptr, 0);
|
||||
disconnect(this, 0, songs_request_.get(), 0);
|
||||
songs_request_.reset();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TidalService::GetSongs() {
|
||||
|
||||
ResetSongsRequest();
|
||||
songs_request_.reset(new TidalRequest(this, url_handler_, network_, TidalBaseRequest::QueryType_Songs, this));
|
||||
connect(songs_request_.get(), SIGNAL(ErrorSignal(QString)), SIGNAL(SongsError(QString)));
|
||||
connect(songs_request_.get(), SIGNAL(ErrorSignal(QString)), SLOT(SongsErrorReceived(QString)));
|
||||
connect(songs_request_.get(), SIGNAL(Results(SongList)), SLOT(SongsResultsReceived(SongList)));
|
||||
connect(songs_request_.get(), SIGNAL(UpdateStatus(QString)), SIGNAL(SongsUpdateStatus(QString)));
|
||||
connect(songs_request_.get(), SIGNAL(ProgressSetMaximum(int)), SIGNAL(SongsProgressSetMaximum(int)));
|
||||
connect(songs_request_.get(), SIGNAL(UpdateProgress(int)), SIGNAL(SongsUpdateProgress(int)));
|
||||
connect(songs_request_.get(), SIGNAL(Results(SongList)), SIGNAL(SongsResults(SongList)));
|
||||
connect(this, SIGNAL(LoginComplete(bool, QString)), songs_request_.get(), SLOT(LoginComplete(bool, QString)));
|
||||
|
||||
songs_request_->Process();
|
||||
|
||||
}
|
||||
|
||||
void TidalService::SongsResultsReceived(SongList songs) {
|
||||
|
||||
emit SongsResults(songs);
|
||||
ResetSongsRequest();
|
||||
|
||||
}
|
||||
|
||||
void TidalService::SongsErrorReceived(QString error) {
|
||||
|
||||
emit SongsError(error);
|
||||
ResetSongsRequest();
|
||||
|
||||
}
|
||||
|
||||
int TidalService::Search(const QString &text, InternetSearch::SearchType type) {
|
||||
|
||||
pending_search_id_ = next_pending_search_id_;
|
||||
|
||||
@@ -118,14 +118,21 @@ class TidalService : public InternetService {
|
||||
void GetArtists();
|
||||
void GetAlbums();
|
||||
void GetSongs();
|
||||
void ResetArtistsRequest();
|
||||
void ResetAlbumsRequest();
|
||||
void ResetSongsRequest();
|
||||
|
||||
private slots:
|
||||
void SendLogin();
|
||||
void HandleAuthReply(QNetworkReply *reply);
|
||||
void ResetLoginAttempts();
|
||||
void StartSearch();
|
||||
void UpdateArtists(SongList songs);
|
||||
void UpdateAlbums(SongList songs);
|
||||
void ArtistsResultsReceived(SongList songs);
|
||||
void ArtistsErrorReceived(QString error);
|
||||
void AlbumsResultsReceived(SongList songs);
|
||||
void AlbumsErrorReceived(QString error);
|
||||
void SongsResultsReceived(SongList songs);
|
||||
void SongsErrorReceived(QString error);
|
||||
|
||||
private:
|
||||
typedef QPair<QString, QString> Param;
|
||||
|
||||
Reference in New Issue
Block a user