Improve Tidal and Qobuz request

This commit is contained in:
Jonas Kvinge 2022-10-31 06:12:02 +01:00
parent 7c0c9fccdb
commit 157de12bdf
14 changed files with 861 additions and 615 deletions

View File

@ -46,7 +46,7 @@
#include "jsoncoverprovider.h"
#include "qobuzcoverprovider.h"
const int QobuzCoverProvider::kLimit = 10;
constexpr int QobuzCoverProvider::kLimit = 10;
QobuzCoverProvider::QobuzCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent)
: JsonCoverProvider("Qobuz", true, true, 2.0, true, true, app, network, parent),
@ -93,7 +93,7 @@ bool QobuzCoverProvider::StartSearch(const QString &artist, const QString &album
url_query.addQueryItem(QUrl::toPercentEncoding(param.first), QUrl::toPercentEncoding(param.second));
}
QUrl url(QobuzService::kApiUrl + QString("/") + resource);
QUrl url(QString(QobuzService::kApiUrl) + QString("/") + resource);
url.setQuery(url_query);
QNetworkRequest req(url);

View File

@ -44,7 +44,7 @@
#include "jsoncoverprovider.h"
#include "tidalcoverprovider.h"
const int TidalCoverProvider::kLimit = 10;
constexpr int TidalCoverProvider::kLimit = 10;
TidalCoverProvider::TidalCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent)
: JsonCoverProvider("Tidal", true, true, 2.5, true, true, app, network, parent),
@ -91,7 +91,7 @@ bool TidalCoverProvider::StartSearch(const QString &artist, const QString &album
url_query.addQueryItem(QUrl::toPercentEncoding(param.first), QUrl::toPercentEncoding(param.second));
}
QUrl url(TidalService::kApiUrl + QString("/") + resource);
QUrl url(QString(TidalService::kApiUrl) + QString("/") + resource);
url.setQuery(url_query);
QNetworkRequest req(url);
req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);

View File

@ -54,9 +54,9 @@ class InternetService : public QObject {
virtual bool has_initial_load_settings() const { return false; }
virtual void InitialLoadSettings() {}
virtual void ReloadSettings() {}
virtual QIcon Icon() { return Song::IconForSource(source_); }
virtual bool oauth() { return false; }
virtual bool authenticated() { return false; }
virtual QIcon Icon() const { return Song::IconForSource(source_); }
virtual bool oauth() const { return false; }
virtual bool authenticated() const { return false; }
virtual int Search(const QString &query, InternetSearchView::SearchType type) { Q_UNUSED(query); Q_UNUSED(type); return 0; }
virtual void CancelSearch() {}

View File

@ -60,7 +60,7 @@ QNetworkReply *QobuzBaseRequest::CreateRequest(const QString &ressource_name, co
url_query.addQueryItem(QUrl::toPercentEncoding(param.first), QUrl::toPercentEncoding(param.second));
}
QUrl url(QobuzService::kApiUrl + QString("/") + ressource_name);
QUrl url(QString(QobuzService::kApiUrl) + QString("/") + ressource_name);
url.setQuery(url_query);
QNetworkRequest req(url);
req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);

File diff suppressed because it is too large Load Diff

View File

@ -41,6 +41,7 @@
#include "qobuzbaserequest.h"
class QNetworkReply;
class QTimer;
class Application;
class NetworkAccessManager;
class QobuzService;
@ -52,19 +53,55 @@ class QobuzRequest : public QobuzBaseRequest {
public:
explicit QobuzRequest(QobuzService *service, QobuzUrlHandler *url_handler, Application *app, NetworkAccessManager *network, QueryType type, QObject *parent = nullptr);
~QobuzRequest();
~QobuzRequest() override;
void ReloadSettings();
void Process();
void Search(const int query_id, const QString &search_text);
private:
struct Artist {
QString artist_id;
QString artist;
};
struct Album {
Album() : album_explicit(false) {}
QString album_id;
QString album;
QUrl cover_url;
bool album_explicit;
};
struct Request {
Request() : offset(0), limit(0) {}
int offset;
int limit;
};
struct ArtistAlbumsRequest {
ArtistAlbumsRequest() : offset(0), limit(0) {}
Artist artist;
int offset;
int limit;
};
struct AlbumSongsRequest {
AlbumSongsRequest() : offset(0), limit(0) {}
Artist artist;
Album album;
int offset;
int limit;
};
struct AlbumCoverRequest {
QString artist_id;
QString album_id;
QUrl url;
QString filename;
};
signals:
void LoginSuccess();
void LoginFailure(QString failure_reason);
void Results(int id, SongMap songs, QString error);
void UpdateStatus(int id, QString text);
void ProgressSetMaximum(int id, int max);
void UpdateProgress(int id, int max);
void StreamURLFinished(QUrl original_url, QUrl url, Song::FileType, QString error = QString());
@ -72,35 +109,23 @@ class QobuzRequest : public QobuzBaseRequest {
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 QString &artist_id_requested, const int limit_requested, const int offset_requested);
void AlbumsReceived(QNetworkReply *reply, const Artist &artist_requested, 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 QString &artist_id_requested, const QString &album_id_requested, const int limit_requested, const int offset_requested, const QString &album_artist_requested = QString(), const QString &album_requested = QString());
void SongsReceived(QNetworkReply *reply, const Artist &artist_requested, const Album &album_requested, const int limit_requested, const int offset_requested);
void ArtistAlbumsReplyReceived(QNetworkReply *reply, const QString &artist_id, const int offset_requested);
void AlbumSongsReplyReceived(QNetworkReply *reply, const QString &artist_id, const QString &album_id, const int offset_requested, const QString &album_artist, const QString &album);
void ArtistAlbumsReplyReceived(QNetworkReply *reply, const Artist &artist, const int offset_requested);
void AlbumSongsReplyReceived(QNetworkReply *reply, const Artist &artist, const Album &album, const int offset_requested);
void AlbumCoverReceived(QNetworkReply *reply, const QUrl &cover_url, const QString &filename);
private:
struct Request {
Request() : offset(0), limit(0) {}
QString artist_id;
QString album_id;
QString song_id;
int offset;
int limit;
QString album_artist;
QString album;
};
struct AlbumCoverRequest {
QUrl url;
QString filename;
};
bool IsQuery() { return (type_ == QueryType_Artists || type_ == QueryType_Albums || type_ == QueryType_Songs); }
bool IsSearch() { return (type_ == QueryType_SearchArtists || type_ == QueryType_SearchAlbums || type_ == QueryType_SearchSongs); }
void StartRequests();
void FlushRequests();
void GetArtists();
void GetAlbums();
void GetSongs();
@ -120,24 +145,27 @@ class QobuzRequest : public QobuzBaseRequest {
void FlushSongsRequests();
void ArtistsFinishCheck(const int limit = 0, const int offset = 0, const int artists_received = 0);
void AlbumsFinishCheck(const QString &artist_id, const int limit = 0, const int offset = 0, const int albums_total = 0, const int albums_received = 0);
void SongsFinishCheck(const QString &artist_id, const QString &album_id, const int limit, const int offset, const int songs_total, const int songs_received, const QString &album_artist, const QString &album);
void AlbumsFinishCheck(const Artist &artist, const int limit = 0, const int offset = 0, const int albums_total = 0, const int albums_received = 0);
void SongsFinishCheck(const Artist &artist, const Album &album, const int limit = 0, const int offset = 0, const int songs_total = 0, const int songs_received = 0);
void AddArtistAlbumsRequest(const QString &artist_id, const int offset = 0);
void AddArtistAlbumsRequest(const Artist &artist, const int offset = 0);
void FlushArtistAlbumsRequests();
void AddAlbumSongsRequest(const QString &artist_id, const QString &album_id, const QString &album_artist, const QString &album, const int offset = 0);
void AddAlbumSongsRequest(const Artist &artist, const Album &album, const int offset = 0);
void FlushAlbumSongsRequests();
QString ParseSong(Song &song, const QJsonObject &json_obj, QString artist_id, QString album_id, QString album_artist, QString album, QUrl cover_url);
void ParseSong(Song &song, const QJsonObject &json_obj, const Artist &album_artist, const Album &album);
QString AlbumCoverFileName(const Song &song);
void GetAlbumCoversCheck();
void GetAlbumCovers();
void AddAlbumCoverRequest(const Song &song);
void FlushAlbumCoverRequests();
void AlbumCoverFinishCheck();
int GetProgress(const int count, const int total);
void FinishCheck();
static void Warn(const QString &error, const QVariant &debug = QVariant());
void Error(const QString &error, const QVariant &debug = QVariant()) override;
@ -148,13 +176,15 @@ class QobuzRequest : public QobuzBaseRequest {
static const int kMaxConcurrentArtistAlbumsRequests;
static const int kMaxConcurrentAlbumSongsRequests;
static const int kMaxConcurrentAlbumCoverRequests;
static const int kFlushRequestsDelay;
QobuzService *service_;
QobuzUrlHandler *url_handler_;
Application *app_;
NetworkAccessManager *network_;
QTimer *timer_flush_requests_;
QueryType type_;
const QueryType type_;
int query_id_;
QString search_text_;
@ -164,32 +194,47 @@ class QobuzRequest : public QobuzBaseRequest {
QQueue<Request> albums_requests_queue_;
QQueue<Request> songs_requests_queue_;
QQueue<Request> artist_albums_requests_queue_;
QQueue<Request> album_songs_requests_queue_;
QQueue<ArtistAlbumsRequest> artist_albums_requests_queue_;
QQueue<AlbumSongsRequest> album_songs_requests_queue_;
QQueue<AlbumCoverRequest> album_cover_requests_queue_;
QList<QString> artist_albums_requests_pending_;
QHash<QString, Request> album_songs_requests_pending_;
QHash<QString, ArtistAlbumsRequest> artist_albums_requests_pending_;
QHash<QString, AlbumSongsRequest> album_songs_requests_pending_;
QMultiMap<QUrl, QString> album_covers_requests_sent_;
int artists_requests_total_;
int artists_requests_active_;
int artists_requests_received_;
int artists_total_;
int artists_received_;
int albums_requests_total_;
int albums_requests_active_;
int songs_requests_active_;
int albums_requests_received_;
int albums_total_;
int albums_received_;
int songs_requests_total_;
int songs_requests_active_;
int songs_requests_received_;
int songs_total_;
int songs_received_;
int artist_albums_requests_total_;
int artist_albums_requests_active_;
int artist_albums_requested_;
int artist_albums_requests_received_;
int artist_albums_total_;
int artist_albums_received_;
int album_songs_requests_active_;
int album_songs_requested_;
int album_songs_requests_received_;
int album_songs_requests_total_;
int album_songs_total_;
int album_songs_received_;
int album_covers_requests_total_;
int album_covers_requests_active_;
int album_covers_requested_;
int album_covers_received_;
int album_covers_requests_received_;
SongMap songs_;
QStringList errors_;

View File

@ -57,19 +57,19 @@
#include "settings/settingsdialog.h"
#include "settings/qobuzsettingspage.h"
const Song::Source QobuzService::kSource = Song::Source_Qobuz;
const char *QobuzService::kAuthUrl = "https://www.qobuz.com/api.json/0.2/user/login";
const char *QobuzService::kApiUrl = "https://www.qobuz.com/api.json/0.2";
const int QobuzService::kLoginAttempts = 2;
const int QobuzService::kTimeResetLoginAttempts = 60000;
constexpr Song::Source QobuzService::kSource = Song::Source_Qobuz;
constexpr char QobuzService::kAuthUrl[] = "https://www.qobuz.com/api.json/0.2/user/login";
constexpr char QobuzService::kApiUrl[] = "https://www.qobuz.com/api.json/0.2";
constexpr int QobuzService::kLoginAttempts = 2;
constexpr int QobuzService::kTimeResetLoginAttempts = 60000;
const char *QobuzService::kArtistsSongsTable = "qobuz_artists_songs";
const char *QobuzService::kAlbumsSongsTable = "qobuz_albums_songs";
const char *QobuzService::kSongsTable = "qobuz_songs";
constexpr char QobuzService::kArtistsSongsTable[] = "qobuz_artists_songs";
constexpr char QobuzService::kAlbumsSongsTable[] = "qobuz_albums_songs";
constexpr char QobuzService::kSongsTable[] = "qobuz_songs";
const char *QobuzService::kArtistsSongsFtsTable = "qobuz_artists_songs_fts";
const char *QobuzService::kAlbumsSongsFtsTable = "qobuz_albums_songs_fts";
const char *QobuzService::kSongsFtsTable = "qobuz_songs_fts";
constexpr char QobuzService::kArtistsSongsFtsTable[] = "qobuz_artists_songs_fts";
constexpr char QobuzService::kAlbumsSongsFtsTable[] = "qobuz_albums_songs_fts";
constexpr char QobuzService::kSongsFtsTable[] = "qobuz_songs_fts";
QobuzService::QobuzService(Application *app, QObject *parent)
: InternetService(Song::Source_Qobuz, "Qobuz", "qobuz", QobuzSettingsPage::kSettingsGroup, SettingsDialog::Page_Qobuz, app, parent),
@ -536,7 +536,6 @@ void QobuzService::GetArtists() {
artists_request_.reset(new QobuzRequest(this, url_handler_, app_, network_, QobuzBaseRequest::QueryType_Artists), [](QobuzRequest *request) { request->deleteLater(); });
QObject::connect(artists_request_.get(), &QobuzRequest::Results, this, &QobuzService::ArtistsResultsReceived);
QObject::connect(artists_request_.get(), &QobuzRequest::UpdateStatus, this, &QobuzService::ArtistsUpdateStatusReceived);
QObject::connect(artists_request_.get(), &QobuzRequest::ProgressSetMaximum, this, &QobuzService::ArtistsProgressSetMaximumReceived);
QObject::connect(artists_request_.get(), &QobuzRequest::UpdateProgress, this, &QobuzService::ArtistsUpdateProgressReceived);
artists_request_->Process();
@ -556,11 +555,6 @@ void QobuzService::ArtistsUpdateStatusReceived(const int id, const QString &text
emit ArtistsUpdateStatus(text);
}
void QobuzService::ArtistsProgressSetMaximumReceived(const int id, const int max) {
Q_UNUSED(id);
emit ArtistsProgressSetMaximum(max);
}
void QobuzService::ArtistsUpdateProgressReceived(const int id, const int progress) {
Q_UNUSED(id);
emit ArtistsUpdateProgress(progress);
@ -592,7 +586,6 @@ void QobuzService::GetAlbums() {
albums_request_.reset(new QobuzRequest(this, url_handler_, app_, network_, QobuzBaseRequest::QueryType_Albums), [](QobuzRequest *request) { request->deleteLater(); });
QObject::connect(albums_request_.get(), &QobuzRequest::Results, this, &QobuzService::AlbumsResultsReceived);
QObject::connect(albums_request_.get(), &QobuzRequest::UpdateStatus, this, &QobuzService::AlbumsUpdateStatusReceived);
QObject::connect(albums_request_.get(), &QobuzRequest::ProgressSetMaximum, this, &QobuzService::AlbumsProgressSetMaximumReceived);
QObject::connect(albums_request_.get(), &QobuzRequest::UpdateProgress, this, &QobuzService::AlbumsUpdateProgressReceived);
albums_request_->Process();
@ -612,11 +605,6 @@ void QobuzService::AlbumsUpdateStatusReceived(const int id, const QString &text)
emit AlbumsUpdateStatus(text);
}
void QobuzService::AlbumsProgressSetMaximumReceived(const int id, const int max) {
Q_UNUSED(id);
emit AlbumsProgressSetMaximum(max);
}
void QobuzService::AlbumsUpdateProgressReceived(const int id, const int progress) {
Q_UNUSED(id);
emit AlbumsUpdateProgress(progress);
@ -648,7 +636,6 @@ void QobuzService::GetSongs() {
songs_request_.reset(new QobuzRequest(this, url_handler_, app_, network_, QobuzBaseRequest::QueryType_Songs), [](QobuzRequest *request) { request->deleteLater(); });
QObject::connect(songs_request_.get(), &QobuzRequest::Results, this, &QobuzService::SongsResultsReceived);
QObject::connect(songs_request_.get(), &QobuzRequest::UpdateStatus, this, &QobuzService::SongsUpdateStatusReceived);
QObject::connect(songs_request_.get(), &QobuzRequest::ProgressSetMaximum, this, &QobuzService::SongsProgressSetMaximumReceived);
QObject::connect(songs_request_.get(), &QobuzRequest::UpdateProgress, this, &QobuzService::SongsUpdateProgressReceived);
songs_request_->Process();
@ -668,11 +655,6 @@ void QobuzService::SongsUpdateStatusReceived(const int id, const QString &text)
emit SongsUpdateStatus(text);
}
void QobuzService::SongsProgressSetMaximumReceived(const int id, const int max) {
Q_UNUSED(id);
emit SongsProgressSetMaximum(max);
}
void QobuzService::SongsUpdateProgressReceived(const int id, const int progress) {
Q_UNUSED(id);
emit SongsUpdateProgress(progress);
@ -734,7 +716,6 @@ void QobuzService::SendSearch() {
QObject::connect(search_request_.get(), &QobuzRequest::Results, this, &QobuzService::SearchResultsReceived);
QObject::connect(search_request_.get(), &QobuzRequest::UpdateStatus, this, &QobuzService::SearchUpdateStatus);
QObject::connect(search_request_.get(), &QobuzRequest::ProgressSetMaximum, this, &QobuzService::SearchProgressSetMaximum);
QObject::connect(search_request_.get(), &QobuzRequest::UpdateProgress, this, &QobuzService::SearchUpdateProgress);
search_request_->Search(search_id_, search_text_);

View File

@ -61,7 +61,7 @@ class QobuzService : public InternetService {
~QobuzService();
static const Song::Source kSource;
static const char *kApiUrl;
static const char kApiUrl[];
void Exit() override;
void ReloadSettings() override;
@ -72,26 +72,26 @@ class QobuzService : public InternetService {
int max_login_attempts() { return kLoginAttempts; }
Application *app() { return app_; }
QString app_id() { return app_id_; }
QString app_secret() { return app_secret_; }
QString username() { return username_; }
QString password() { return password_; }
int format() { return format_; }
int search_delay() { return search_delay_; }
int artistssearchlimit() { return artistssearchlimit_; }
int albumssearchlimit() { return albumssearchlimit_; }
int songssearchlimit() { return songssearchlimit_; }
bool download_album_covers() { return download_album_covers_; }
Application *app() const { return app_; }
QString app_id() const { return app_id_; }
QString app_secret() const { return app_secret_; }
QString username() const { return username_; }
QString password() const { return password_; }
int format() const { return format_; }
int search_delay() const { return search_delay_; }
int artistssearchlimit() const { return artistssearchlimit_; }
int albumssearchlimit() const { return albumssearchlimit_; }
int songssearchlimit() const { return songssearchlimit_; }
bool download_album_covers() const { return download_album_covers_; }
QString user_auth_token() { return user_auth_token_; }
qint64 user_id() { return user_id_; }
QString device_id() { return device_id_; }
qint64 credential_id() { return credential_id_; }
QString user_auth_token() const { return user_auth_token_; }
qint64 user_id() const { return user_id_; }
QString device_id() const { return device_id_; }
qint64 credential_id() const { return credential_id_; }
bool authenticated() override { return (!app_id_.isEmpty() && !app_secret_.isEmpty() && !user_auth_token_.isEmpty()); }
bool login_sent() { return login_sent_; }
bool login_attempts() { return login_attempts_; }
bool authenticated() const override { return (!app_id_.isEmpty() && !app_secret_.isEmpty() && !user_auth_token_.isEmpty()); }
bool login_sent() const { return login_sent_; }
bool login_attempts() const { return login_attempts_; }
uint GetStreamURL(const QUrl &url, QString &error);
@ -132,9 +132,6 @@ class QobuzService : public InternetService {
void ArtistsUpdateStatusReceived(const int id, const QString &text);
void AlbumsUpdateStatusReceived(const int id, const QString &text);
void SongsUpdateStatusReceived(const int id, const QString &text);
void ArtistsProgressSetMaximumReceived(const int id, const int max);
void AlbumsProgressSetMaximumReceived(const int id, const int max);
void SongsProgressSetMaximumReceived(const int id, const int max);
void ArtistsUpdateProgressReceived(const int id, const int progress);
void AlbumsUpdateProgressReceived(const int id, const int progress);
void SongsUpdateProgressReceived(const int id, const int progress);
@ -149,18 +146,18 @@ class QobuzService : public InternetService {
void SendSearch();
void LoginError(const QString &error = QString(), const QVariant &debug = QVariant());
static const char *kAuthUrl;
static const char kAuthUrl[];
static const int kLoginAttempts;
static const int kTimeResetLoginAttempts;
static const char *kArtistsSongsTable;
static const char *kAlbumsSongsTable;
static const char *kSongsTable;
static const char kArtistsSongsTable[];
static const char kAlbumsSongsTable[];
static const char kSongsTable[];
static const char *kArtistsSongsFtsTable;
static const char *kAlbumsSongsFtsTable;
static const char *kSongsFtsTable;
static const char kArtistsSongsFtsTable[];
static const char kAlbumsSongsFtsTable[];
static const char kSongsFtsTable[];
Application *app_;
NetworkAccessManager *network_;

View File

@ -54,7 +54,7 @@ QNetworkReply *TidalBaseRequest::CreateRequest(const QString &ressource_name, co
url_query.addQueryItem(QUrl::toPercentEncoding(param.first), QUrl::toPercentEncoding(param.second));
}
QUrl url(TidalService::kApiUrl + QString("/") + ressource_name);
QUrl url(QString(TidalService::kApiUrl) + QString("/") + ressource_name);
url.setQuery(url_query);
QNetworkRequest req(url);
req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);

View File

@ -141,7 +141,7 @@ void TidalFavoriteRequest::AddFavoritesRequest(const FavoriteType type, const QS
url_query.addQueryItem(QUrl::toPercentEncoding(param.first), QUrl::toPercentEncoding(param.second));
}
QUrl url(TidalService::kApiUrl + QString("/") + "users/" + QString::number(service_->user_id()) + "/favorites/" + FavoriteText(type));
QUrl url(QString(TidalService::kApiUrl) + QString("/") + "users/" + QString::number(service_->user_id()) + "/favorites/" + FavoriteText(type));
QNetworkRequest req(url);
req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
@ -250,7 +250,7 @@ void TidalFavoriteRequest::RemoveFavoritesRequest(const FavoriteType type, const
url_query.addQueryItem(QUrl::toPercentEncoding(param.first), QUrl::toPercentEncoding(param.second));
}
QUrl url(TidalService::kApiUrl + QString("/") + "users/" + QString::number(service_->user_id()) + "/favorites/" + FavoriteText(type) + QString("/") + id);
QUrl url(QString(TidalService::kApiUrl) + QString("/") + "users/" + QString::number(service_->user_id()) + "/favorites/" + FavoriteText(type) + QString("/") + id);
url.setQuery(url_query);
QNetworkRequest req(url);
#if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)

File diff suppressed because it is too large Load Diff

View File

@ -41,6 +41,7 @@
#include "tidalbaserequest.h"
class QNetworkReply;
class QTimer;
class Application;
class NetworkAccessManager;
class TidalService;
@ -60,16 +61,34 @@ class TidalRequest : public TidalBaseRequest {
void Search(const int query_id, const QString &search_text);
private:
struct Request {
Request() : offset(0), limit(0), album_explicit(false) {}
struct Artist {
QString artist_id;
QString artist;
};
struct Album {
Album() : album_explicit(false) {}
QString album_id;
QString song_id;
QString album;
QUrl cover_url;
bool album_explicit;
};
struct Request {
Request() : offset(0), limit(0) {}
int offset;
int limit;
};
struct ArtistAlbumsRequest {
ArtistAlbumsRequest() : offset(0), limit(0) {}
Artist artist;
int offset;
int limit;
};
struct AlbumSongsRequest {
AlbumSongsRequest() : offset(0), limit(0) {}
Artist artist;
Album album;
int offset;
int limit;
QString album_artist;
QString album;
bool album_explicit;
};
struct AlbumCoverRequest {
QString artist_id;
@ -83,7 +102,6 @@ class TidalRequest : public TidalBaseRequest {
void LoginFailure(QString failure_reason);
void Results(int id, SongMap songs = SongMap(), QString error = QString());
void UpdateStatus(int id, QString text);
void ProgressSetMaximum(int id, int max);
void UpdateProgress(int id, int max);
void StreamURLFinished(QUrl original_url, QUrl url, Song::FileType, QString error = QString());
@ -91,13 +109,13 @@ class TidalRequest : public TidalBaseRequest {
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 QString &artist_id_requested, const int limit_requested, const int offset_requested, const bool auto_login);
void AlbumsReceived(QNetworkReply *reply, const Artist &artist_artist, 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 SongsReceived(QNetworkReply *reply, const QString &artist_id, const QString &album_id, const int limit_requested, const int offset_requested, const bool auto_login = false, const QString &album_artist = QString(), const QString &album = QString(), const bool album_explicit = false);
void SongsReceived(QNetworkReply *reply, const Artist &artist, const Album &album, const int limit_requested, const int offset_requested, const bool auto_login = false);
void ArtistAlbumsReplyReceived(QNetworkReply *reply, const QString &artist_id, const int offset_requested);
void AlbumSongsReplyReceived(QNetworkReply *reply, const QString &artist_id, const QString &album_id, const int offset_requested, const QString &album_artist, const QString &album, const bool album_explicit);
void ArtistAlbumsReplyReceived(QNetworkReply *reply, const Artist &artist, const int offset_requested);
void AlbumSongsReplyReceived(QNetworkReply *reply, const Artist &artist, const Album &album, const int offset_requested);
void AlbumCoverReceived(QNetworkReply *reply, const QString &album_id, const QUrl &url, const QString &filename);
public slots:
@ -107,6 +125,9 @@ class TidalRequest : public TidalBaseRequest {
bool IsQuery() { return (type_ == QueryType_Artists || type_ == QueryType_Albums || type_ == QueryType_Songs); }
bool IsSearch() { return (type_ == QueryType_SearchArtists || type_ == QueryType_SearchAlbums || type_ == QueryType_SearchSongs); }
void StartRequests();
void FlushRequests();
void GetArtists();
void GetAlbums();
void GetSongs();
@ -126,42 +147,47 @@ class TidalRequest : public TidalBaseRequest {
void FlushSongsRequests();
void ArtistsFinishCheck(const int limit = 0, const int offset = 0, const int artists_received = 0);
void AlbumsFinishCheck(const QString &artist_id, const int limit = 0, const int offset = 0, const int albums_total = 0, const int albums_received = 0);
void SongsFinishCheck(const QString &artist_id, const QString &album_id, const int limit, const int offset, const int songs_total, const int songs_received, const QString &album_artist, const QString &album, const bool album_explicit);
void AlbumsFinishCheck(const Artist &artist, const int limit = 0, const int offset = 0, const int albums_total = 0, const int albums_received = 0);
void SongsFinishCheck(const Artist &artist, const Album &album, const int limit = 0, const int offset = 0, const int songs_total = 0, const int songs_received = 0);
void AddArtistAlbumsRequest(const QString &artist_id, const int offset = 0);
void AddArtistAlbumsRequest(const Artist &artist, const int offset = 0);
void FlushArtistAlbumsRequests();
void AddAlbumSongsRequest(const QString &artist_id, const QString &album_id, const QString &album_artist, const QString &album, const bool album_explicit, const int offset = 0);
void AddAlbumSongsRequest(const Artist &artist, const Album &album, 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 QString &album_album = QString(), const bool album_explicit = false);
void ParseSong(Song &song, const QJsonObject &json_obj, const Artist &album_artist, const Album &album);
void GetAlbumCoversCheck();
void GetAlbumCovers();
void AddAlbumCoverRequest(const Song &song);
void FlushAlbumCoverRequests();
void AlbumCoverFinishCheck();
int GetProgress(const int count, const int total);
void FinishCheck();
static void Warn(const QString &error, const QVariant &debug = QVariant());
void Error(const QString &error, const QVariant &debug = QVariant()) override;
static const char *kResourcesUrl;
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;
static const int kFlushRequestsDelay;
TidalService *service_;
TidalUrlHandler *url_handler_;
Application *app_;
NetworkAccessManager *network_;
QTimer *timer_flush_requests_;
QueryType type_;
bool fetchalbums_;
QString coversize_;
const QueryType type_;
const bool fetchalbums_;
const QString coversize_;
int query_id_;
QString search_text_;
@ -172,32 +198,47 @@ class TidalRequest : public TidalBaseRequest {
QQueue<Request> albums_requests_queue_;
QQueue<Request> songs_requests_queue_;
QQueue<Request> artist_albums_requests_queue_;
QQueue<Request> album_songs_requests_queue_;
QQueue<ArtistAlbumsRequest> artist_albums_requests_queue_;
QQueue<AlbumSongsRequest> album_songs_requests_queue_;
QQueue<AlbumCoverRequest> album_cover_requests_queue_;
QList<QString> artist_albums_requests_pending_;
QHash<QString, Request> album_songs_requests_pending_;
QHash<QString, ArtistAlbumsRequest> artist_albums_requests_pending_;
QHash<QString, AlbumSongsRequest> album_songs_requests_pending_;
QMultiMap<QString, QString> album_covers_requests_sent_;
int artists_requests_total_;
int artists_requests_active_;
int artists_requests_received_;
int artists_total_;
int artists_received_;
int albums_requests_total_;
int albums_requests_active_;
int songs_requests_active_;
int albums_requests_received_;
int albums_total_;
int albums_received_;
int songs_requests_total_;
int songs_requests_active_;
int songs_requests_received_;
int songs_total_;
int songs_received_;
int artist_albums_requests_total_;
int artist_albums_requests_active_;
int artist_albums_requested_;
int artist_albums_requests_received_;
int artist_albums_total_;
int artist_albums_received_;
int album_songs_requests_active_;
int album_songs_requested_;
int album_songs_requests_received_;
int album_songs_requests_total_;
int album_songs_total_;
int album_songs_received_;
int album_covers_requests_total_;
int album_covers_requests_active_;
int album_covers_requested_;
int album_covers_received_;
int album_covers_requests_received_;
SongMap songs_;
QStringList errors_;

View File

@ -61,23 +61,23 @@
#include "settings/settingsdialog.h"
#include "settings/tidalsettingspage.h"
const Song::Source TidalService::kSource = Song::Source_Tidal;
const char *TidalService::kOAuthUrl = "https://login.tidal.com/authorize";
const char *TidalService::kOAuthAccessTokenUrl = "https://login.tidal.com/oauth2/token";
const char *TidalService::kOAuthRedirectUrl = "tidal://login/auth";
const char *TidalService::kAuthUrl = "https://api.tidalhifi.com/v1/login/username";
const char *TidalService::kApiUrl = "https://api.tidalhifi.com/v1";
const char *TidalService::kResourcesUrl = "https://resources.tidal.com";
const int TidalService::kLoginAttempts = 2;
const int TidalService::kTimeResetLoginAttempts = 60000;
constexpr Song::Source TidalService::kSource = Song::Source_Tidal;
constexpr char TidalService::kOAuthUrl[] = "https://login.tidal.com/authorize";
constexpr char TidalService::kOAuthAccessTokenUrl[] = "https://login.tidal.com/oauth2/token";
constexpr char TidalService::kOAuthRedirectUrl[] = "tidal://login/auth";
constexpr char TidalService::kAuthUrl[] = "https://api.tidalhifi.com/v1/login/username";
constexpr char TidalService::kApiUrl[] = "https://api.tidalhifi.com/v1";
constexpr char TidalService::kResourcesUrl[] = "https://resources.tidal.com";
constexpr int TidalService::kLoginAttempts = 2;
constexpr int TidalService::kTimeResetLoginAttempts = 60000;
const char *TidalService::kArtistsSongsTable = "tidal_artists_songs";
const char *TidalService::kAlbumsSongsTable = "tidal_albums_songs";
const char *TidalService::kSongsTable = "tidal_songs";
constexpr char TidalService::kArtistsSongsTable[] = "tidal_artists_songs";
constexpr char TidalService::kAlbumsSongsTable[] = "tidal_albums_songs";
constexpr char TidalService::kSongsTable[] = "tidal_songs";
const char *TidalService::kArtistsSongsFtsTable = "tidal_artists_songs_fts";
const char *TidalService::kAlbumsSongsFtsTable = "tidal_albums_songs_fts";
const char *TidalService::kSongsFtsTable = "tidal_songs_fts";
constexpr char TidalService::kArtistsSongsFtsTable[] = "tidal_artists_songs_fts";
constexpr char TidalService::kAlbumsSongsFtsTable[] = "tidal_albums_songs_fts";
constexpr char TidalService::kSongsFtsTable[] = "tidal_songs_fts";
using namespace std::chrono_literals;
@ -753,7 +753,6 @@ void TidalService::GetArtists() {
QObject::connect(artists_request_.get(), &TidalRequest::RequestLogin, this, &TidalService::SendLogin);
QObject::connect(artists_request_.get(), &TidalRequest::Results, this, &TidalService::ArtistsResultsReceived);
QObject::connect(artists_request_.get(), &TidalRequest::UpdateStatus, this, &TidalService::ArtistsUpdateStatusReceived);
QObject::connect(artists_request_.get(), &TidalRequest::ProgressSetMaximum, this, &TidalService::ArtistsProgressSetMaximumReceived);
QObject::connect(artists_request_.get(), &TidalRequest::UpdateProgress, this, &TidalService::ArtistsUpdateProgressReceived);
QObject::connect(this, &TidalService::LoginComplete, artists_request_.get(), &TidalRequest::LoginComplete);
@ -774,11 +773,6 @@ void TidalService::ArtistsUpdateStatusReceived(const int id, const QString &text
emit ArtistsUpdateStatus(text);
}
void TidalService::ArtistsProgressSetMaximumReceived(const int id, const int max) {
Q_UNUSED(id);
emit ArtistsProgressSetMaximum(max);
}
void TidalService::ArtistsUpdateProgressReceived(const int id, const int progress) {
Q_UNUSED(id);
emit ArtistsUpdateProgress(progress);
@ -814,7 +808,6 @@ void TidalService::GetAlbums() {
QObject::connect(albums_request_.get(), &TidalRequest::RequestLogin, this, &TidalService::SendLogin);
QObject::connect(albums_request_.get(), &TidalRequest::Results, this, &TidalService::AlbumsResultsReceived);
QObject::connect(albums_request_.get(), &TidalRequest::UpdateStatus, this, &TidalService::AlbumsUpdateStatusReceived);
QObject::connect(albums_request_.get(), &TidalRequest::ProgressSetMaximum, this, &TidalService::AlbumsProgressSetMaximumReceived);
QObject::connect(albums_request_.get(), &TidalRequest::UpdateProgress, this, &TidalService::AlbumsUpdateProgressReceived);
QObject::connect(this, &TidalService::LoginComplete, albums_request_.get(), &TidalRequest::LoginComplete);
@ -835,11 +828,6 @@ void TidalService::AlbumsUpdateStatusReceived(const int id, const QString &text)
emit AlbumsUpdateStatus(text);
}
void TidalService::AlbumsProgressSetMaximumReceived(const int id, const int max) {
Q_UNUSED(id);
emit AlbumsProgressSetMaximum(max);
}
void TidalService::AlbumsUpdateProgressReceived(const int id, const int progress) {
Q_UNUSED(id);
emit AlbumsUpdateProgress(progress);
@ -875,7 +863,6 @@ void TidalService::GetSongs() {
QObject::connect(songs_request_.get(), &TidalRequest::RequestLogin, this, &TidalService::SendLogin);
QObject::connect(songs_request_.get(), &TidalRequest::Results, this, &TidalService::SongsResultsReceived);
QObject::connect(songs_request_.get(), &TidalRequest::UpdateStatus, this, &TidalService::SongsUpdateStatusReceived);
QObject::connect(songs_request_.get(), &TidalRequest::ProgressSetMaximum, this, &TidalService::SongsProgressSetMaximumReceived);
QObject::connect(songs_request_.get(), &TidalRequest::UpdateProgress, this, &TidalService::SongsUpdateProgressReceived);
QObject::connect(this, &TidalService::LoginComplete, songs_request_.get(), &TidalRequest::LoginComplete);
@ -896,11 +883,6 @@ void TidalService::SongsUpdateStatusReceived(const int id, const QString &text)
emit SongsUpdateStatus(text);
}
void TidalService::SongsProgressSetMaximumReceived(const int id, const int max) {
Q_UNUSED(id);
emit SongsProgressSetMaximum(max);
}
void TidalService::SongsUpdateProgressReceived(const int id, const int progress) {
Q_UNUSED(id);
emit SongsUpdateProgress(progress);
@ -973,7 +955,6 @@ void TidalService::SendSearch() {
QObject::connect(search_request_.get(), &TidalRequest::RequestLogin, this, &TidalService::SendLogin);
QObject::connect(search_request_.get(), &TidalRequest::Results, this, &TidalService::SearchResultsReceived);
QObject::connect(search_request_.get(), &TidalRequest::UpdateStatus, this, &TidalService::SearchUpdateStatus);
QObject::connect(search_request_.get(), &TidalRequest::ProgressSetMaximum, this, &TidalService::SearchProgressSetMaximum);
QObject::connect(search_request_.get(), &TidalRequest::UpdateProgress, this, &TidalService::SearchUpdateProgress);
QObject::connect(this, &TidalService::LoginComplete, search_request_.get(), &TidalRequest::LoginComplete);

View File

@ -64,8 +64,8 @@ class TidalService : public InternetService {
~TidalService() override;
static const Song::Source kSource;
static const char *kApiUrl;
static const char *kResourcesUrl;
static const char kApiUrl[];
static const char kResourcesUrl[];
void Exit() override;
void ReloadSettings() override;
@ -74,33 +74,33 @@ class TidalService : public InternetService {
int Search(const QString &text, InternetSearchView::SearchType type) override;
void CancelSearch() override;
int max_login_attempts() { return kLoginAttempts; }
int max_login_attempts() const { return kLoginAttempts; }
Application *app() { return app_; }
Application *app() const { return app_; }
bool oauth() override { return oauth_; }
QString client_id() { return client_id_; }
QString api_token() { return api_token_; }
quint64 user_id() { return user_id_; }
QString country_code() { return country_code_; }
QString username() { return username_; }
QString password() { return password_; }
QString quality() { return quality_; }
int artistssearchlimit() { return artistssearchlimit_; }
int albumssearchlimit() { return albumssearchlimit_; }
int songssearchlimit() { return songssearchlimit_; }
bool fetchalbums() { return fetchalbums_; }
QString coversize() { return coversize_; }
bool download_album_covers() { return download_album_covers_; }
TidalSettingsPage::StreamUrlMethod stream_url_method() { return stream_url_method_; }
bool album_explicit() { return album_explicit_; }
bool oauth() const override { return oauth_; }
QString client_id() const { return client_id_; }
QString api_token() const { return api_token_; }
quint64 user_id() const { return user_id_; }
QString country_code() const { return country_code_; }
QString username() const { return username_; }
QString password() const { return password_; }
QString quality() const { return quality_; }
int artistssearchlimit() const { return artistssearchlimit_; }
int albumssearchlimit() const { return albumssearchlimit_; }
int songssearchlimit() const { return songssearchlimit_; }
bool fetchalbums() const { return fetchalbums_; }
QString coversize() const { return coversize_; }
bool download_album_covers() const { return download_album_covers_; }
TidalSettingsPage::StreamUrlMethod stream_url_method() const { return stream_url_method_; }
bool album_explicit() const { return album_explicit_; }
QString access_token() { return access_token_; }
QString session_id() { return session_id_; }
QString access_token() const { return access_token_; }
QString session_id() const { return session_id_; }
bool authenticated() override { return (!access_token_.isEmpty() || !session_id_.isEmpty()); }
bool login_sent() { return login_sent_; }
bool login_attempts() { return login_attempts_; }
bool authenticated() const override { return (!access_token_.isEmpty() || !session_id_.isEmpty()); }
bool login_sent() const { return login_sent_; }
bool login_attempts() const { return login_attempts_; }
uint GetStreamURL(const QUrl &url, QString &error);
@ -145,9 +145,6 @@ class TidalService : public InternetService {
void ArtistsUpdateStatusReceived(const int id, const QString &text);
void AlbumsUpdateStatusReceived(const int id, const QString &text);
void SongsUpdateStatusReceived(const int id, const QString &text);
void ArtistsProgressSetMaximumReceived(const int id, const int max);
void AlbumsProgressSetMaximumReceived(const int id, const int max);
void SongsProgressSetMaximumReceived(const int id, const int max);
void ArtistsUpdateProgressReceived(const int id, const int progress);
void AlbumsUpdateProgressReceived(const int id, const int progress);
void SongsUpdateProgressReceived(const int id, const int progress);
@ -163,21 +160,21 @@ class TidalService : public InternetService {
void SendSearch();
void LoginError(const QString &error = QString(), const QVariant &debug = QVariant());
static const char *kOAuthUrl;
static const char *kOAuthAccessTokenUrl;
static const char *kOAuthRedirectUrl;
static const char *kAuthUrl;
static const char kOAuthUrl[];
static const char kOAuthAccessTokenUrl[];
static const char kOAuthRedirectUrl[];
static const char kAuthUrl[];
static const int kLoginAttempts;
static const int kTimeResetLoginAttempts;
static const char *kArtistsSongsTable;
static const char *kAlbumsSongsTable;
static const char *kSongsTable;
static const char kArtistsSongsTable[];
static const char kAlbumsSongsTable[];
static const char kSongsTable[];
static const char *kArtistsSongsFtsTable;
static const char *kAlbumsSongsFtsTable;
static const char *kSongsFtsTable;
static const char kArtistsSongsFtsTable[];
static const char kAlbumsSongsFtsTable[];
static const char kSongsFtsTable[];
Application *app_;
NetworkAccessManager *network_;