Remove tidal and qobuz

Fixes #369
This commit is contained in:
Jonas Kvinge
2020-02-25 01:08:03 +01:00
parent 7312e3f452
commit 2e0f7b367f
66 changed files with 43 additions and 9578 deletions

View File

@@ -1,195 +0,0 @@
/*
* Strawberry Music Player
* Copyright 2019, 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
* 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/>.
*
*/
#include "config.h"
#include <algorithm>
#include <QObject>
#include <QByteArray>
#include <QPair>
#include <QList>
#include <QString>
#include <QUrl>
#include <QUrlQuery>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QSslError>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonValue>
#include "core/network.h"
#include "qobuzservice.h"
#include "qobuzbaserequest.h"
const char *QobuzBaseRequest::kApiUrl = "https://www.qobuz.com/api.json/0.2";
QobuzBaseRequest::QobuzBaseRequest(QobuzService *service, NetworkAccessManager *network, QObject *parent) :
QObject(parent),
service_(service),
network_(network)
{}
QobuzBaseRequest::~QobuzBaseRequest() {}
QNetworkReply *QobuzBaseRequest::CreateRequest(const QString &ressource_name, const QList<Param> &params_provided) {
ParamList params = ParamList() << params_provided
<< Param("app_id", app_id());
std::sort(params.begin(), params.end());
QUrlQuery url_query;
for (const Param& param : params) {
EncodedParam encoded_param(QUrl::toPercentEncoding(param.first), QUrl::toPercentEncoding(param.second));
url_query.addQueryItem(encoded_param.first, encoded_param.second);
}
QUrl url(kApiUrl + QString("/") + ressource_name);
url.setQuery(url_query);
QNetworkRequest req(url);
req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
req.setRawHeader("X-App-Id", app_id().toUtf8());
if (authenticated())
req.setRawHeader("X-User-Auth-Token", user_auth_token().toUtf8());
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
#endif
QNetworkReply *reply = network_->get(req);
connect(reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(HandleSSLErrors(QList<QSslError>)));
//qLog(Debug) << "Qobuz: Sending request" << url;
return reply;
}
void QobuzBaseRequest::HandleSSLErrors(QList<QSslError> ssl_errors) {
for (QSslError &ssl_error : ssl_errors) {
Error(ssl_error.errorString());
}
}
QByteArray QobuzBaseRequest::GetReplyData(QNetworkReply *reply) {
QByteArray data;
if (reply->error() == QNetworkReply::NoError && reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 200) {
data = reply->readAll();
}
else {
if (reply->error() != QNetworkReply::NoError && reply->error() < 200) {
// This is a network error, there is nothing more to do.
Error(QString("%1 (%2)").arg(reply->errorString()).arg(reply->error()));
}
else {
// See if there is Json data containing "status", "code" and "message" - 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("status") && json_obj.contains("code") && json_obj.contains("message")) {
QString status = json_obj["status"].toString();
int code = json_obj["code"].toInt();
QString message = json_obj["message"].toString();
error = QString("%1 (%2)").arg(message).arg(code);
}
}
if (error.isEmpty()) {
if (reply->error() != QNetworkReply::NoError) {
error = QString("%1 (%2)").arg(reply->errorString()).arg(reply->error());
}
else {
error = QString("Received HTTP code %1").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
}
}
Error(error);
}
return QByteArray();
}
return data;
}
QJsonObject QobuzBaseRequest::ExtractJsonObj(QByteArray &data) {
QJsonParseError json_error;
QJsonDocument json_doc = QJsonDocument::fromJson(data, &json_error);
if (json_error.error != QJsonParseError::NoError) {
Error("Reply from server missing Json data.", data);
return QJsonObject();
}
if (json_doc.isEmpty()) {
Error("Received empty Json document.", data);
return QJsonObject();
}
if (!json_doc.isObject()) {
Error("Json document is not an object.", json_doc);
return QJsonObject();
}
QJsonObject json_obj = json_doc.object();
if (json_obj.isEmpty()) {
Error("Received empty Json object.", json_doc);
return QJsonObject();
}
return json_obj;
}
QJsonValue QobuzBaseRequest::ExtractItems(QByteArray &data) {
QJsonObject json_obj = ExtractJsonObj(data);
if (json_obj.isEmpty()) return QJsonValue();
return ExtractItems(json_obj);
}
QJsonValue QobuzBaseRequest::ExtractItems(QJsonObject &json_obj) {
if (!json_obj.contains("items")) {
Error("Json reply is missing items.", json_obj);
return QJsonArray();
}
QJsonValue json_items = json_obj["items"];
return json_items;
}
QString QobuzBaseRequest::ErrorsToHTML(const QStringList &errors) {
QString error_html;
for (const QString &error : errors) {
error_html += error + "<br />";
}
return error_html;
}

View File

@@ -1,109 +0,0 @@
/*
* Strawberry Music Player
* Copyright 2019, 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
* 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 QOBUZBASEREQUEST_H
#define QOBUZBASEREQUEST_H
#include "config.h"
#include <QtGlobal>
#include <QObject>
#include <QPair>
#include <QSet>
#include <QList>
#include <QVariant>
#include <QByteArray>
#include <QString>
#include <QStringList>
#include <QJsonObject>
#include <QJsonValue>
#include "core/song.h"
#include "qobuzservice.h"
class QNetworkReply;
class NetworkAccessManager;
class QobuzBaseRequest : public QObject {
Q_OBJECT
public:
enum QueryType {
QueryType_None,
QueryType_Artists,
QueryType_Albums,
QueryType_Songs,
QueryType_SearchArtists,
QueryType_SearchAlbums,
QueryType_SearchSongs,
QueryType_StreamURL,
};
QobuzBaseRequest(QobuzService *service, NetworkAccessManager *network, QObject *parent);
~QobuzBaseRequest();
typedef QPair<QString, QString> Param;
typedef QList<Param> ParamList;
typedef QPair<QByteArray, QByteArray> EncodedParam;
typedef QList<EncodedParam> EncodedParamList;
QNetworkReply *CreateRequest(const QString &ressource_name, const QList<Param> &params_provided);
QByteArray GetReplyData(QNetworkReply *reply);
QJsonObject ExtractJsonObj(QByteArray &data);
QJsonValue ExtractItems(QByteArray &data);
QJsonValue ExtractItems(QJsonObject &json_obj);
virtual void Error(const QString &error, const QVariant &debug = QVariant()) = 0;
QString ErrorsToHTML(const QStringList &errors);
QString api_url() { return QString(kApiUrl); }
QString app_id() { return service_->app_id(); }
QString app_secret() { return service_->app_secret(); }
QString username() { return service_->username(); }
QString password() { return service_->password(); }
int format() { return service_->format(); }
int artistssearchlimit() { return service_->artistssearchlimit(); }
int albumssearchlimit() { return service_->albumssearchlimit(); }
int songssearchlimit() { return service_->songssearchlimit(); }
qint64 user_id() { return service_->user_id(); }
QString user_auth_token() { return service_->user_auth_token(); }
QString device_id() { return service_->device_id(); }
qint64 credential_id() { return service_->credential_id(); }
bool authenticated() { return service_->authenticated(); }
bool login_sent() { return service_->login_sent(); }
int max_login_attempts() { return service_->max_login_attempts(); }
int login_attempts() { return service_->login_attempts(); }
private slots:
void HandleSSLErrors(QList<QSslError> ssl_errors);
private:
static const char *kApiUrl;
QobuzService *service_;
NetworkAccessManager *network_;
};
#endif // QOBUZBASEREQUEST_H

View File

@@ -1,282 +0,0 @@
/*
* Strawberry Music Player
* Copyright 2019, 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
* 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/>.
*
*/
#include "config.h"
#include <QObject>
#include <QPair>
#include <QByteArray>
#include <QString>
#include <QStringList>
#include <QUrl>
#include <QUrlQuery>
#include <QNetworkReply>
#include <QtDebug>
#include "core/logging.h"
#include "core/network.h"
#include "core/closure.h"
#include "core/song.h"
#include "qobuzservice.h"
#include "qobuzbaserequest.h"
#include "qobuzfavoriterequest.h"
QobuzFavoriteRequest::QobuzFavoriteRequest(QobuzService *service, NetworkAccessManager *network, QObject *parent)
: QobuzBaseRequest(service, network, parent),
service_(service),
network_(network) {}
QobuzFavoriteRequest::~QobuzFavoriteRequest() {
while (!replies_.isEmpty()) {
QNetworkReply *reply = replies_.takeFirst();
disconnect(reply, 0, this, 0);
reply->abort();
reply->deleteLater();
}
}
QString QobuzFavoriteRequest::FavoriteText(const FavoriteType type) {
switch (type) {
case FavoriteType_Artists:
return "artists";
case FavoriteType_Albums:
return "albums";
case FavoriteType_Songs:
default:
return "tracks";
}
}
void QobuzFavoriteRequest::AddArtists(const SongList &songs) {
AddFavorites(FavoriteType_Artists, songs);
}
void QobuzFavoriteRequest::AddAlbums(const SongList &songs) {
AddFavorites(FavoriteType_Albums, songs);
}
void QobuzFavoriteRequest::AddSongs(const SongList &songs) {
AddFavorites(FavoriteType_Songs, songs);
}
void QobuzFavoriteRequest::AddFavorites(const FavoriteType type, const SongList &songs) {
if (songs.isEmpty()) return;
QString text;
switch (type) {
case FavoriteType_Artists:
text = "artist_ids";
break;
case FavoriteType_Albums:
text = "album_ids";
break;
case FavoriteType_Songs:
text = "track_ids";
break;
}
QStringList ids_list;
for (const Song &song : songs) {
QString id;
switch (type) {
case FavoriteType_Artists:
if (song.artist_id() <= 0) continue;
id = QString::number(song.artist_id());
break;
case FavoriteType_Albums:
if (song.album_id().isEmpty()) continue;
id = song.album_id();
break;
case FavoriteType_Songs:
if (song.song_id() <= 0) continue;
id = QString::number(song.song_id());
break;
}
if (id.isEmpty()) continue;
if (!ids_list.contains(id)) {
ids_list << id;
}
}
if (ids_list.isEmpty()) return;
QString ids = ids_list.join(',');
typedef QPair<QByteArray, QByteArray> EncodedParam;
ParamList params = ParamList() << Param("app_id", app_id())
<< Param("user_auth_token", user_auth_token())
<< Param(text, ids);
QUrlQuery url_query;
for (const Param& param : params) {
EncodedParam encoded_param(QUrl::toPercentEncoding(param.first), QUrl::toPercentEncoding(param.second));
url_query.addQueryItem(encoded_param.first, encoded_param.second);
}
QNetworkReply *reply = CreateRequest("favorite/create", params);
NewClosure(reply, SIGNAL(finished()), this, SLOT(AddFavoritesReply(QNetworkReply*, const FavoriteType, const SongList&)), reply, type, songs);
replies_ << reply;
}
void QobuzFavoriteRequest::AddFavoritesReply(QNetworkReply *reply, const FavoriteType type, const SongList &songs) {
if (replies_.contains(reply)) {
replies_.removeAll(reply);
reply->deleteLater();
}
else {
return;
}
QByteArray data = GetReplyData(reply);
if (reply->error() != QNetworkReply::NoError) {
return;
}
qLog(Debug) << "Qobuz:" << songs.count() << "songs added to" << FavoriteText(type) << "favorites.";
switch (type) {
case FavoriteType_Artists:
emit ArtistsAdded(songs);
break;
case FavoriteType_Albums:
emit AlbumsAdded(songs);
break;
case FavoriteType_Songs:
emit SongsAdded(songs);
break;
}
}
void QobuzFavoriteRequest::RemoveArtists(const SongList &songs) {
RemoveFavorites(FavoriteType_Artists, songs);
}
void QobuzFavoriteRequest::RemoveAlbums(const SongList &songs) {
RemoveFavorites(FavoriteType_Albums, songs);
}
void QobuzFavoriteRequest::RemoveSongs(const SongList &songs) {
RemoveFavorites(FavoriteType_Songs, songs);
}
void QobuzFavoriteRequest::RemoveFavorites(const FavoriteType type, const SongList &songs) {
if (songs.isEmpty()) return;
QString text;
switch (type) {
case FavoriteType_Artists:
text = "artist_ids";
break;
case FavoriteType_Albums:
text = "album_ids";
break;
case FavoriteType_Songs:
text = "track_ids";
break;
}
QStringList ids_list;
for (const Song &song : songs) {
QString id;
switch (type) {
case FavoriteType_Artists:
if (song.artist_id() <= 0) continue;
id = QString::number(song.artist_id());
break;
case FavoriteType_Albums:
if (song.album_id().isEmpty()) continue;
id = song.album_id();
break;
case FavoriteType_Songs:
if (song.song_id() <= 0) continue;
id = QString::number(song.song_id());
break;
}
if (id.isEmpty()) continue;
if (!ids_list.contains(id)) {
ids_list << id;
}
}
if (ids_list.isEmpty()) return;
QString ids = ids_list.join(',');
ParamList params = ParamList() << Param("app_id", app_id())
<< Param("user_auth_token", user_auth_token())
<< Param(text, ids);
QUrlQuery url_query;
for (const Param &param : params) {
EncodedParam encoded_param(QUrl::toPercentEncoding(param.first), QUrl::toPercentEncoding(param.second));
url_query.addQueryItem(encoded_param.first, encoded_param.second);
}
QNetworkReply *reply = CreateRequest("favorite/delete", params);
NewClosure(reply, SIGNAL(finished()), this, SLOT(RemoveFavoritesReply(QNetworkReply*, const FavoriteType, const SongList&)), reply, type, songs);
replies_ << reply;
}
void QobuzFavoriteRequest::RemoveFavoritesReply(QNetworkReply *reply, const FavoriteType type, const SongList &songs) {
if (replies_.contains(reply)) {
replies_.removeAll(reply);
reply->deleteLater();
}
else {
return;
}
QByteArray data = GetReplyData(reply);
if (reply->error() != QNetworkReply::NoError) {
return;
}
qLog(Debug) << "Qobuz:" << songs.count() << "songs removed from" << FavoriteText(type) << "favorites.";
switch (type) {
case FavoriteType_Artists:
emit ArtistsRemoved(songs);
break;
case FavoriteType_Albums:
emit AlbumsRemoved(songs);
break;
case FavoriteType_Songs:
emit SongsRemoved(songs);
break;
}
}
void QobuzFavoriteRequest::Error(const QString &error, const QVariant &debug) {
qLog(Error) << "Qobuz:" << error;
if (debug.isValid()) qLog(Debug) << debug;
}

View File

@@ -1,82 +0,0 @@
/*
* Strawberry Music Player
* Copyright 2019, 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
* 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 QOBUZFAVORITEREQUEST_H
#define QOBUZFAVORITEREQUEST_H
#include "config.h"
#include <QObject>
#include <QList>
#include <QVariant>
#include <QString>
#include "qobuzbaserequest.h"
#include "core/song.h"
class QNetworkReply;
class QobuzService;
class NetworkAccessManager;
class QobuzFavoriteRequest : public QobuzBaseRequest {
Q_OBJECT
public:
QobuzFavoriteRequest(QobuzService *service, NetworkAccessManager *network, QObject *parent);
~QobuzFavoriteRequest();
enum FavoriteType {
FavoriteType_Artists,
FavoriteType_Albums,
FavoriteType_Songs
};
signals:
void ArtistsAdded(const SongList &songs);
void AlbumsAdded(const SongList &songs);
void SongsAdded(const SongList &songs);
void ArtistsRemoved(const SongList &songs);
void AlbumsRemoved(const SongList &songs);
void SongsRemoved(const SongList &songs);
private slots:
void AddArtists(const SongList &songs);
void AddAlbums(const SongList &songs);
void AddSongs(const SongList &songs);
void RemoveArtists(const SongList &songs);
void RemoveAlbums(const SongList &songs);
void RemoveSongs(const SongList &songs);
void AddFavoritesReply(QNetworkReply *reply, const FavoriteType type, const SongList &songs);
void RemoveFavoritesReply(QNetworkReply *reply, const FavoriteType type, const SongList &songs);
private:
void Error(const QString &error, const QVariant &debug = QVariant());
QString FavoriteText(const FavoriteType type);
void AddFavorites(const FavoriteType type, const SongList &songs);
void RemoveFavorites(const FavoriteType type, const SongList &songs);
QobuzService *service_;
NetworkAccessManager *network_;
QList<QNetworkReply*> replies_;
};
#endif // QOBUZFAVORITEREQUEST_H

File diff suppressed because it is too large Load Diff

View File

@@ -1,206 +0,0 @@
/*
* Strawberry Music Player
* Copyright 2019, 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
* 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 QOBUZREQUEST_H
#define QOBUZREQUEST_H
#include "config.h"
#include <QtGlobal>
#include <QObject>
#include <QPair>
#include <QSet>
#include <QList>
#include <QHash>
#include <QMap>
#include <QMultiMap>
#include <QQueue>
#include <QVariant>
#include <QString>
#include <QStringList>
#include <QUrl>
#include <QJsonObject>
#include "core/song.h"
#include "qobuzbaserequest.h"
class QNetworkReply;
class Application;
class NetworkAccessManager;
class QobuzService;
class QobuzUrlHandler;
class QobuzRequest : public QobuzBaseRequest {
Q_OBJECT
public:
QobuzRequest(QobuzService *service, QobuzUrlHandler *url_handler, Application *app, NetworkAccessManager *network, QueryType type, QObject *parent);
~QobuzRequest();
void ReloadSettings();
void Process();
void Search(const int search_id, const QString &search_text);
signals:
void Login();
void Login(const QString &username, const QString &password, const QString &token);
void LoginSuccess();
void LoginFailure(QString failure_reason);
void Results(const int id, const SongList &songs, const QString &error);
void UpdateStatus(const int id, const QString &text);
void ProgressSetMaximum(const int id, const int max);
void UpdateProgress(const int id, const int max);
void StreamURLFinished(const QUrl original_url, const QUrl url, const Song::FileType, QString error = QString());
private slots:
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 qint64 artist_id_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 qint64 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 ArtistAlbumsReplyReceived(QNetworkReply *reply, const qint64 artist_id, const int offset_requested);
void AlbumSongsReplyReceived(QNetworkReply *reply, const qint64 artist_id, const QString &album_id, const int offset_requested, const QString &album_artist, const QString &album);
void AlbumCoverReceived(QNetworkReply *reply, const QUrl &cover_url, const QString &filename);
private:
typedef QPair<QString, QString> Param;
typedef QList<Param> ParamList;
struct Request {
qint64 artist_id = 0;
QString album_id = 0;
qint64 song_id = 0;
int offset = 0;
int limit = 0;
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 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 qint64 artist_id, const int limit = 0, const int offset = 0, const int albums_total = 0, const int albums_received = 0);
void SongsFinishCheck(const qint64 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 AddArtistAlbumsRequest(const qint64 artist_id, const int offset = 0);
void FlushArtistAlbumsRequests();
void AddAlbumSongsRequest(const qint64 artist_id, const QString &album_id, const QString &album_artist, const QString &album, const int offset = 0);
void FlushAlbumSongsRequests();
int ParseSong(Song &song, const QJsonObject &json_obj, qint64 artist_id, QString album_id, QString album_artist, QString album, QUrl cover_url);
QString AlbumCoverFileName(const Song &song);
void GetAlbumCovers();
void AddAlbumCoverRequest(Song &song);
void FlushAlbumCoverRequests();
void AlbumCoverFinishCheck();
void FinishCheck();
void Warn(const QString &error, const QVariant &debug = QVariant());
void Error(const QString &error, const QVariant &debug = QVariant());
static const int kMaxConcurrentArtistsRequests;
static const int kMaxConcurrentAlbumsRequests;
static const int kMaxConcurrentSongsRequests;
static const int kMaxConcurrentArtistAlbumsRequests;
static const int kMaxConcurrentAlbumSongsRequests;
static const int kMaxConcurrentAlbumCoverRequests;
QobuzService *service_;
QobuzUrlHandler *url_handler_;
Application *app_;
NetworkAccessManager *network_;
QueryType type_;
int query_id_;
QString search_text_;
bool finished_;
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<qint64> artist_albums_requests_pending_;
QHash<QString, Request> album_songs_requests_pending_;
QMultiMap<QUrl, Song*> album_covers_requests_sent_;
int artists_requests_active_;
int artists_total_;
int artists_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_;
QStringList errors_;
bool no_results_;
QList<QNetworkReply*> replies_;
QList<QNetworkReply*> album_cover_replies_;
};
#endif // QOBUZREQUEST_H

View File

@@ -1,765 +0,0 @@
/*
* Strawberry Music Player
* Copyright 2019, 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
* 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/>.
*
*/
#include "config.h"
#include <memory>
#include <QObject>
#include <QByteArray>
#include <QPair>
#include <QList>
#include <QString>
#include <QUrl>
#include <QUrlQuery>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QTimer>
#include <QJsonValue>
#include <QJsonDocument>
#include <QJsonObject>
#include <QSettings>
#include <QSortFilterProxyModel>
#include <QSslError>
#include <QtDebug>
#include "core/application.h"
#include "core/player.h"
#include "core/closure.h"
#include "core/logging.h"
#include "core/network.h"
#include "core/database.h"
#include "core/song.h"
#include "core/utilities.h"
#include "internet/internetsearch.h"
#include "collection/collectionbackend.h"
#include "collection/collectionmodel.h"
#include "qobuzservice.h"
#include "qobuzurlhandler.h"
#include "qobuzbaserequest.h"
#include "qobuzrequest.h"
#include "qobuzfavoriterequest.h"
#include "qobuzstreamurlrequest.h"
#include "settings/settingsdialog.h"
#include "settings/qobuzsettingspage.h"
using std::shared_ptr;
const Song::Source QobuzService::kSource = Song::Source_Qobuz;
const char *QobuzService::kAuthUrl = "https://www.qobuz.com/api.json/0.2/user/login";
const int QobuzService::kLoginAttempts = 2;
const int QobuzService::kTimeResetLoginAttempts = 60000;
const char *QobuzService::kArtistsSongsTable = "qobuz_artists_songs";
const char *QobuzService::kAlbumsSongsTable = "qobuz_albums_songs";
const 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";
QobuzService::QobuzService(Application *app, QObject *parent)
: InternetService(Song::Source_Qobuz, "Qobuz", "qobuz", app, parent),
app_(app),
network_(new NetworkAccessManager(this)),
url_handler_(new QobuzUrlHandler(app, this)),
artists_collection_backend_(nullptr),
albums_collection_backend_(nullptr),
songs_collection_backend_(nullptr),
artists_collection_model_(nullptr),
albums_collection_model_(nullptr),
songs_collection_model_(nullptr),
artists_collection_sort_model_(new QSortFilterProxyModel(this)),
albums_collection_sort_model_(new QSortFilterProxyModel(this)),
songs_collection_sort_model_(new QSortFilterProxyModel(this)),
timer_search_delay_(new QTimer(this)),
timer_login_attempt_(new QTimer(this)),
favorite_request_(new QobuzFavoriteRequest(this, network_, this)),
format_(0),
search_delay_(1500),
artistssearchlimit_(1),
albumssearchlimit_(1),
songssearchlimit_(1),
download_album_covers_(true),
user_id_(-1),
credential_id_(-1),
pending_search_id_(0),
next_pending_search_id_(1),
search_id_(0),
login_sent_(false),
login_attempts_(0)
{
app->player()->RegisterUrlHandler(url_handler_);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
network_->setRedirectPolicy(QNetworkRequest::NoLessSafeRedirectPolicy);
#endif
// Backends
artists_collection_backend_ = new CollectionBackend();
artists_collection_backend_->moveToThread(app_->database()->thread());
artists_collection_backend_->Init(app_->database(), Song::Source_Qobuz, kArtistsSongsTable, QString(), QString(), kArtistsSongsFtsTable);
albums_collection_backend_ = new CollectionBackend();
albums_collection_backend_->moveToThread(app_->database()->thread());
albums_collection_backend_->Init(app_->database(), Song::Source_Qobuz, kAlbumsSongsTable, QString(), QString(), kAlbumsSongsFtsTable);
songs_collection_backend_ = new CollectionBackend();
songs_collection_backend_->moveToThread(app_->database()->thread());
songs_collection_backend_->Init(app_->database(), Song::Source_Qobuz, kSongsTable, QString(), QString(), kSongsFtsTable);
artists_collection_model_ = new CollectionModel(artists_collection_backend_, app_, this);
albums_collection_model_ = new CollectionModel(albums_collection_backend_, app_, this);
songs_collection_model_ = new CollectionModel(songs_collection_backend_, app_, this);
artists_collection_sort_model_->setSourceModel(artists_collection_model_);
artists_collection_sort_model_->setSortRole(CollectionModel::Role_SortText);
artists_collection_sort_model_->setDynamicSortFilter(true);
artists_collection_sort_model_->setSortLocaleAware(true);
artists_collection_sort_model_->sort(0);
albums_collection_sort_model_->setSourceModel(albums_collection_model_);
albums_collection_sort_model_->setSortRole(CollectionModel::Role_SortText);
albums_collection_sort_model_->setDynamicSortFilter(true);
albums_collection_sort_model_->setSortLocaleAware(true);
albums_collection_sort_model_->sort(0);
songs_collection_sort_model_->setSourceModel(songs_collection_model_);
songs_collection_sort_model_->setSortRole(CollectionModel::Role_SortText);
songs_collection_sort_model_->setDynamicSortFilter(true);
songs_collection_sort_model_->setSortLocaleAware(true);
songs_collection_sort_model_->sort(0);
// Search
timer_search_delay_->setSingleShot(true);
connect(timer_search_delay_, SIGNAL(timeout()), SLOT(StartSearch()));
timer_login_attempt_->setSingleShot(true);
connect(timer_login_attempt_, SIGNAL(timeout()), SLOT(ResetLoginAttempts()));
connect(this, SIGNAL(Login()), SLOT(SendLogin()));
connect(this, SIGNAL(Login(QString, QString, QString)), SLOT(SendLogin(QString, QString, QString)));
connect(this, SIGNAL(AddArtists(const SongList&)), favorite_request_, SLOT(AddArtists(const SongList&)));
connect(this, SIGNAL(AddAlbums(const SongList&)), favorite_request_, SLOT(AddAlbums(const SongList&)));
connect(this, SIGNAL(AddSongs(const SongList&)), favorite_request_, SLOT(AddSongs(const SongList&)));
connect(this, SIGNAL(RemoveArtists(const SongList&)), favorite_request_, SLOT(RemoveArtists(const SongList&)));
connect(this, SIGNAL(RemoveAlbums(const SongList&)), favorite_request_, SLOT(RemoveAlbums(const SongList&)));
connect(this, SIGNAL(RemoveSongs(const SongList&)), favorite_request_, SLOT(RemoveSongs(const SongList&)));
connect(favorite_request_, SIGNAL(ArtistsAdded(const SongList&)), artists_collection_backend_, SLOT(AddOrUpdateSongs(const SongList&)));
connect(favorite_request_, SIGNAL(AlbumsAdded(const SongList&)), albums_collection_backend_, SLOT(AddOrUpdateSongs(const SongList&)));
connect(favorite_request_, SIGNAL(SongsAdded(const SongList&)), songs_collection_backend_, SLOT(AddOrUpdateSongs(const SongList&)));
connect(favorite_request_, SIGNAL(ArtistsRemoved(const SongList&)), artists_collection_backend_, SLOT(DeleteSongs(const SongList&)));
connect(favorite_request_, SIGNAL(AlbumsRemoved(const SongList&)), albums_collection_backend_, SLOT(DeleteSongs(const SongList&)));
connect(favorite_request_, SIGNAL(SongsRemoved(const SongList&)), songs_collection_backend_, SLOT(DeleteSongs(const SongList&)));
ReloadSettings();
}
QobuzService::~QobuzService() {
while (!stream_url_requests_.isEmpty()) {
QobuzStreamURLRequest *stream_url_req = stream_url_requests_.takeFirst();
disconnect(stream_url_req, 0, this, 0);
stream_url_req->deleteLater();
}
artists_collection_backend_->deleteLater();
albums_collection_backend_->deleteLater();
songs_collection_backend_->deleteLater();
}
void QobuzService::Exit() {
wait_for_exit_ << artists_collection_backend_ << albums_collection_backend_ << songs_collection_backend_;
connect(artists_collection_backend_, SIGNAL(ExitFinished()), this, SLOT(ExitReceived()));
connect(albums_collection_backend_, SIGNAL(ExitFinished()), this, SLOT(ExitReceived()));
connect(songs_collection_backend_, SIGNAL(ExitFinished()), this, SLOT(ExitReceived()));
artists_collection_backend_->ExitAsync();
albums_collection_backend_->ExitAsync();
songs_collection_backend_->ExitAsync();
}
void QobuzService::ExitReceived() {
QObject *obj = static_cast<QObject*>(sender());
disconnect(obj, 0, this, 0);
qLog(Debug) << obj << "successfully exited.";
wait_for_exit_.removeAll(obj);
if (wait_for_exit_.isEmpty()) emit ExitFinished();
}
void QobuzService::ShowConfig() {
app_->OpenSettingsDialogAtPage(SettingsDialog::Page_Qobuz);
}
void QobuzService::ReloadSettings() {
QSettings s;
s.beginGroup(QobuzSettingsPage::kSettingsGroup);
app_id_ = s.value("app_id").toString();
app_secret_ = s.value("app_secret").toString();
username_ = s.value("username").toString();
QByteArray password = s.value("password").toByteArray();
if (password.isEmpty()) password_.clear();
else password_ = QString::fromUtf8(QByteArray::fromBase64(password));
format_ = s.value("format", 27).toInt();
search_delay_ = s.value("searchdelay", 1500).toInt();
artistssearchlimit_ = s.value("artistssearchlimit", 4).toInt();
albumssearchlimit_ = s.value("albumssearchlimit", 10).toInt();
songssearchlimit_ = s.value("songssearchlimit", 10).toInt();
download_album_covers_ = s.value("downloadalbumcovers", true).toBool();
user_id_ = s.value("user_id").toInt();
device_id_ = s.value("device_id").toString();
user_auth_token_ = s.value("user_auth_token").toString();
s.endGroup();
}
void QobuzService::SendLogin() {
SendLogin(app_id_, username_, password_);
}
void QobuzService::SendLogin(const QString &app_id, const QString &username, const QString &password) {
emit UpdateStatus(tr("Authenticating..."));
login_errors_.clear();
login_sent_ = true;
++login_attempts_;
if (timer_login_attempt_->isActive()) timer_login_attempt_->stop();
timer_login_attempt_->setInterval(kTimeResetLoginAttempts);
timer_login_attempt_->start();
const ParamList params = ParamList() << Param("app_id", app_id)
<< Param("username", username)
<< Param("password", password)
<< Param("device_manufacturer_id", Utilities::MacAddress());
QUrlQuery url_query;
for (const Param &param : params) {
EncodedParam encoded_param(QUrl::toPercentEncoding(param.first), QUrl::toPercentEncoding(param.second));
url_query.addQueryItem(encoded_param.first, encoded_param.second);
}
QUrl url(kAuthUrl);
QNetworkRequest req(url);
req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
QByteArray query = url_query.toString(QUrl::FullyEncoded).toUtf8();
QNetworkReply *reply = network_->post(req, query);
connect(reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(HandleLoginSSLErrors(QList<QSslError>)));
NewClosure(reply, SIGNAL(finished()), this, SLOT(HandleAuthReply(QNetworkReply*)), reply);
qLog(Debug) << "Qobuz: Sending request" << url << query;
}
void QobuzService::HandleLoginSSLErrors(QList<QSslError> ssl_errors) {
for (QSslError &ssl_error : ssl_errors) {
login_errors_ += ssl_error.errorString();
}
}
void QobuzService::HandleAuthReply(QNetworkReply *reply) {
reply->deleteLater();
login_sent_ = false;
if (reply->error() != QNetworkReply::NoError || reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() != 200) {
if (reply->error() != QNetworkReply::NoError && reply->error() < 200) {
// This is a network error, there is nothing more to do.
LoginError(QString("%1 (%2)").arg(reply->errorString()).arg(reply->error()));
return;
}
else {
// See if there is Json data containing "status", "code" and "message" - then use that instead.
QByteArray data(reply->readAll());
QJsonParseError json_error;
QJsonDocument json_doc = QJsonDocument::fromJson(data, &json_error);
if (json_error.error == QJsonParseError::NoError && !json_doc.isEmpty() && json_doc.isObject()) {
QJsonObject json_obj = json_doc.object();
if (!json_obj.isEmpty() && json_obj.contains("status") && json_obj.contains("code") && json_obj.contains("message")) {
QString status = json_obj["status"].toString();
int code = json_obj["code"].toInt();
QString message = json_obj["message"].toString();
login_errors_ << QString("%1 (%2)").arg(message).arg(code);
}
}
if (login_errors_.isEmpty()) {
if (reply->error() != QNetworkReply::NoError) {
login_errors_ << QString("%1 (%2)").arg(reply->errorString()).arg(reply->error());
}
else {
login_errors_ << QString("Received HTTP code %1").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
}
}
LoginError();
return;
}
}
login_errors_.clear();
QByteArray data(reply->readAll());
QJsonParseError json_error;
QJsonDocument json_doc = QJsonDocument::fromJson(data, &json_error);
if (json_error.error != QJsonParseError::NoError) {
LoginError("Authentication reply from server missing Json data.");
return;
}
if (json_doc.isEmpty()) {
LoginError("Authentication reply from server has empty Json document.");
return;
}
if (!json_doc.isObject()) {
LoginError("Authentication reply from server has Json document that is not an object.", json_doc);
return;
}
QJsonObject json_obj = json_doc.object();
if (json_obj.isEmpty()) {
LoginError("Authentication reply from server has empty Json object.", json_doc);
return;
}
if (!json_obj.contains("user_auth_token")) {
LoginError("Authentication reply from server is missing user_auth_token", json_obj);
return;
}
user_auth_token_ = json_obj["user_auth_token"].toString();
if (!json_obj.contains("user")) {
LoginError("Authentication reply from server is missing user", json_obj);
return;
}
QJsonValue json_user = json_obj["user"];
if (!json_user.isObject()) {
LoginError("Authentication reply user is not a object", json_obj);
return;
}
QJsonObject json_obj_user = json_user.toObject();
if (!json_obj_user.contains("id")) {
LoginError("Authentication reply from server is missing user id", json_obj_user);
return;
}
user_id_ = json_obj_user["id"].toInt();
if (!json_obj_user.contains("device")) {
LoginError("Authentication reply from server is missing user device", json_obj_user);
return;
}
QJsonValue json_device = json_obj_user["device"];
if (!json_device.isObject()) {
LoginError("Authentication reply from server user device is not a object", json_device);
return;
}
QJsonObject json_obj_device = json_device.toObject();
if (!json_obj_device.contains("device_manufacturer_id")) {
LoginError("Authentication reply from server device is missing device_manufacturer_id", json_obj_device);
return;
}
device_id_ = json_obj_device["device_manufacturer_id"].toString();
if (!json_obj_user.contains("credential")) {
LoginError("Authentication reply from server is missing user credential", json_obj_user);
return;
}
QJsonValue json_credential = json_obj_user["credential"];
if (!json_credential.isObject()) {
LoginError("Authentication reply from serve userr credential is not a object", json_device);
return;
}
QJsonObject json_obj_credential = json_credential.toObject();
if (!json_obj_credential.contains("id")) {
LoginError("Authentication reply user credential from server is missing user credential id", json_obj_device);
return;
}
credential_id_ = json_obj_credential["id"].toInt();
QSettings s;
s.beginGroup(QobuzSettingsPage::kSettingsGroup);
s.setValue("user_auth_token", user_auth_token_);
s.setValue("user_id", user_id_);
s.setValue("credential_id", credential_id_);
s.setValue("device_id", device_id_);
s.endGroup();
qLog(Debug) << "Qobuz: Login successful" << "user id" << user_id_ << "user auth token" << user_auth_token_ << "device id" << device_id_;
login_attempts_ = 0;
if (timer_login_attempt_->isActive()) timer_login_attempt_->stop();
emit LoginComplete(true);
emit LoginSuccess();
}
void QobuzService::Logout() {
user_auth_token_.clear();
device_id_.clear();
user_id_ = -1;
credential_id_ = -1;
QSettings s;
s.beginGroup(QobuzSettingsPage::kSettingsGroup);
s.remove("user_id");
s.remove("credential_id");
s.remove("device_id");
s.remove("user_auth_token");
s.endGroup();
}
void QobuzService::ResetLoginAttempts() {
login_attempts_ = 0;
}
void QobuzService::TryLogin() {
if (authenticated() || login_sent_) return;
if (login_attempts_ >= kLoginAttempts) {
emit LoginComplete(false, tr("Maximum number of login attempts reached."));
return;
}
if (app_id_.isEmpty()) {
emit LoginComplete(false, tr("Missing Qobuz app ID."));
return;
}
if (username_.isEmpty()) {
emit LoginComplete(false, tr("Missing Qobuz username."));
return;
}
if (password_.isEmpty()) {
emit LoginComplete(false, tr("Missing Qobuz password."));
return;
}
emit Login();
}
void QobuzService::ResetArtistsRequest() {
if (artists_request_.get()) {
disconnect(artists_request_.get(), 0, this, 0);
disconnect(this, 0, artists_request_.get(), 0);
artists_request_.reset();
}
}
void QobuzService::GetArtists() {
if (app_id().isEmpty()) {
emit ArtistsResults(SongList(), tr("Missing Qobuz app ID."));
return;
}
if (!authenticated()) {
emit ArtistsResults(SongList(), tr("Not authenticated with Qobuz."));
return;
}
ResetArtistsRequest();
artists_request_.reset(new QobuzRequest(this, url_handler_, app_, network_, QobuzBaseRequest::QueryType_Artists, this));
connect(artists_request_.get(), SIGNAL(Results(const int, const SongList&, const QString&)), SLOT(ArtistsResultsReceived(const int, const SongList&, const QString&)));
connect(artists_request_.get(), SIGNAL(UpdateStatus(const int, const QString&)), SLOT(ArtistsUpdateStatusReceived(const int, const QString&)));
connect(artists_request_.get(), SIGNAL(ProgressSetMaximum(const int, const int)), SLOT(ArtistsProgressSetMaximumReceived(const int, const int)));
connect(artists_request_.get(), SIGNAL(UpdateProgress(const int, const int)), SLOT(ArtistsUpdateProgressReceived(const int, const int)));
artists_request_->Process();
}
void QobuzService::ArtistsResultsReceived(const int id, const SongList &songs, const QString &error) {
Q_UNUSED(id);
emit ArtistsResults(songs, error);
}
void QobuzService::ArtistsUpdateStatusReceived(const int id, const QString &text) {
Q_UNUSED(id);
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);
}
void QobuzService::ResetAlbumsRequest() {
if (albums_request_.get()) {
disconnect(albums_request_.get(), 0, this, 0);
disconnect(this, 0, albums_request_.get(), 0);
albums_request_.reset();
}
}
void QobuzService::GetAlbums() {
if (app_id().isEmpty()) {
emit AlbumsResults(SongList(), tr("Missing Qobuz app ID."));
return;
}
if (!authenticated()) {
emit AlbumsResults(SongList(), tr("Not authenticated with Qobuz."));
return;
}
ResetAlbumsRequest();
albums_request_.reset(new QobuzRequest(this, url_handler_, app_, network_, QobuzBaseRequest::QueryType_Albums, this));
connect(albums_request_.get(), SIGNAL(Results(const int, const SongList&, const QString&)), SLOT(AlbumsResultsReceived(const int, const SongList&, const QString&)));
connect(albums_request_.get(), SIGNAL(UpdateStatus(const int, const QString&)), SLOT(AlbumsUpdateStatusReceived(const int, const QString&)));
connect(albums_request_.get(), SIGNAL(ProgressSetMaximum(const int, const int)), SLOT(AlbumsProgressSetMaximumReceived(const int, const int)));
connect(albums_request_.get(), SIGNAL(UpdateProgress(const int, const int)), SLOT(AlbumsUpdateProgressReceived(const int, const int)));
albums_request_->Process();
}
void QobuzService::AlbumsResultsReceived(const int id, const SongList &songs, const QString &error) {
Q_UNUSED(id);
emit AlbumsResults(songs, error);
}
void QobuzService::AlbumsUpdateStatusReceived(const int id, const QString &text) {
Q_UNUSED(id);
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);
}
void QobuzService::ResetSongsRequest() {
if (songs_request_.get()) {
disconnect(songs_request_.get(), 0, this, 0);
disconnect(this, 0, songs_request_.get(), 0);
songs_request_.reset();
}
}
void QobuzService::GetSongs() {
if (app_id().isEmpty()) {
emit SongsResults(SongList(), tr("Missing Qobuz app ID."));
return;
}
if (!authenticated()) {
emit SongsResults(SongList(), tr("Not authenticated with Qobuz."));
return;
}
ResetSongsRequest();
songs_request_.reset(new QobuzRequest(this, url_handler_, app_, network_, QobuzBaseRequest::QueryType_Songs, this));
connect(songs_request_.get(), SIGNAL(Results(const int, const SongList&, const QString&)), SLOT(SongsResultsReceived(const int, const SongList&, const QString&)));
connect(songs_request_.get(), SIGNAL(UpdateStatus(const int, const QString&)), SLOT(SongsUpdateStatusReceived(const int, const QString&)));
connect(songs_request_.get(), SIGNAL(ProgressSetMaximum(const int, const int)), SLOT(SongsProgressSetMaximumReceived(const int, const int)));
connect(songs_request_.get(), SIGNAL(UpdateProgress(const int, const int)), SLOT(SongsUpdateProgressReceived(const int, const int)));
songs_request_->Process();
}
void QobuzService::SongsResultsReceived(const int id, const SongList &songs, const QString &error) {
Q_UNUSED(id);
emit SongsResults(songs, error);
}
void QobuzService::SongsUpdateStatusReceived(const int id, const QString &text) {
Q_UNUSED(id);
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);
}
int QobuzService::Search(const QString &text, InternetSearch::SearchType type) {
pending_search_id_ = next_pending_search_id_;
pending_search_text_ = text;
pending_search_type_ = type;
next_pending_search_id_++;
if (text.isEmpty()) {
timer_search_delay_->stop();
return pending_search_id_;
}
timer_search_delay_->setInterval(search_delay_);
timer_search_delay_->start();
return pending_search_id_;
}
void QobuzService::StartSearch() {
search_id_ = pending_search_id_;
search_text_ = pending_search_text_;
if (app_id_.isEmpty()) { // App ID is the only thing needed to search.
emit SearchResults(search_id_, SongList(), tr("Missing Qobuz app ID."));
return;
}
SendSearch();
}
void QobuzService::CancelSearch() {
}
void QobuzService::SendSearch() {
QobuzBaseRequest::QueryType type;
switch (pending_search_type_) {
case InternetSearch::SearchType_Artists:
type = QobuzBaseRequest::QueryType_SearchArtists;
break;
case InternetSearch::SearchType_Albums:
type = QobuzBaseRequest::QueryType_SearchAlbums;
break;
case InternetSearch::SearchType_Songs:
type = QobuzBaseRequest::QueryType_SearchSongs;
break;
default:
//Error("Invalid search type.");
return;
}
search_request_.reset(new QobuzRequest(this, url_handler_, app_, network_, type, this));
connect(search_request_.get(), SIGNAL(Results(const int, const SongList&, const QString&)), SLOT(SearchResultsReceived(const int, const SongList&, const QString&)));
connect(search_request_.get(), SIGNAL(UpdateStatus(const int, const QString&)), SIGNAL(SearchUpdateStatus(const int, const QString&)));
connect(search_request_.get(), SIGNAL(ProgressSetMaximum(const int, const int)), SIGNAL(SearchProgressSetMaximum(const int, const int)));
connect(search_request_.get(), SIGNAL(UpdateProgress(const int, const int)), SIGNAL(SearchUpdateProgress(const int, const int)));
search_request_->Search(search_id_, search_text_);
search_request_->Process();
}
void QobuzService::SearchResultsReceived(const int id, const SongList &songs, const QString &error) {
emit SearchResults(id, songs, error);
}
void QobuzService::GetStreamURL(const QUrl &url) {
if (app_id().isEmpty() || app_secret().isEmpty()) { // Don't check for login here, because we allow automatic login.
emit StreamURLFinished(url, url, Song::FileType_Stream, -1, -1, -1, tr("Missing Qobuz app ID or secret."));
return;
}
QobuzStreamURLRequest *stream_url_req = new QobuzStreamURLRequest(this, network_, url, this);
stream_url_requests_ << stream_url_req;
connect(stream_url_req, SIGNAL(TryLogin()), this, SLOT(TryLogin()));
connect(stream_url_req, SIGNAL(StreamURLFinished(const QUrl&, const QUrl&, const Song::FileType, const int, const int, const qint64, QString)), this, SLOT(HandleStreamURLFinished(const QUrl&, const QUrl&, const Song::FileType, const int, const int, const qint64, QString)));
connect(this, SIGNAL(LoginComplete(const bool, QString)), stream_url_req, SLOT(LoginComplete(const bool, QString)));
stream_url_req->Process();
}
void QobuzService::HandleStreamURLFinished(const QUrl &original_url, const QUrl &stream_url, const Song::FileType filetype, const int samplerate, const int bit_depth, const qint64 duration, QString error) {
QobuzStreamURLRequest *stream_url_req = qobject_cast<QobuzStreamURLRequest*>(sender());
if (!stream_url_req || !stream_url_requests_.contains(stream_url_req)) return;
stream_url_req->deleteLater();
stream_url_requests_.removeAll(stream_url_req);
emit StreamURLFinished(original_url, stream_url, filetype, samplerate, bit_depth, duration, error);
}
void QobuzService::LoginError(const QString &error, const QVariant &debug) {
if (!error.isEmpty()) login_errors_ << error;
QString error_html;
for (const QString &error : login_errors_) {
qLog(Error) << "Qobuz:" << error;
error_html += error + "<br />";
}
if (debug.isValid()) qLog(Debug) << debug;
emit LoginFailure(error_html);
emit LoginComplete(false, error_html);
login_errors_.clear();
}

View File

@@ -1,235 +0,0 @@
/*
* Strawberry Music Player
* Copyright 2019, 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
* 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 QOBUZSERVICE_H
#define QOBUZSERVICE_H
#include "config.h"
#include <memory>
#include <QtGlobal>
#include <QObject>
#include <QPair>
#include <QSet>
#include <QList>
#include <QVariant>
#include <QByteArray>
#include <QString>
#include <QStringList>
#include <QUrl>
#include <QSslError>
#include "core/song.h"
#include "internet/internetservice.h"
#include "internet/internetsearch.h"
class QTimer;
class QNetworkReply;
class QSortFilterProxyModel;
class Application;
class NetworkAccessManager;
class QobuzUrlHandler;
class QobuzRequest;
class QobuzFavoriteRequest;
class QobuzStreamURLRequest;
class CollectionBackend;
class CollectionModel;
using std::shared_ptr;
class QobuzService : public InternetService {
Q_OBJECT
public:
QobuzService(Application *app, QObject *parent);
~QobuzService();
static const Song::Source kSource;
void Exit();
void ReloadSettings();
void Logout();
int Search(const QString &query, InternetSearch::SearchType type);
void CancelSearch();
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_; }
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_; }
bool authenticated() { return (!app_id_.isEmpty() && !app_secret_.isEmpty() && !user_auth_token_.isEmpty()); }
bool login_sent() { return login_sent_; }
bool login_attempts() { return login_attempts_; }
void GetStreamURL(const QUrl &url);
CollectionBackend *artists_collection_backend() { return artists_collection_backend_; }
CollectionBackend *albums_collection_backend() { return albums_collection_backend_; }
CollectionBackend *songs_collection_backend() { return songs_collection_backend_; }
CollectionModel *artists_collection_model() { return artists_collection_model_; }
CollectionModel *albums_collection_model() { return albums_collection_model_; }
CollectionModel *songs_collection_model() { return songs_collection_model_; }
QSortFilterProxyModel *artists_collection_sort_model() { return artists_collection_sort_model_; }
QSortFilterProxyModel *albums_collection_sort_model() { return albums_collection_sort_model_; }
QSortFilterProxyModel *songs_collection_sort_model() { return songs_collection_sort_model_; }
enum QueryType {
QueryType_Artists,
QueryType_Albums,
QueryType_Songs,
QueryType_SearchArtists,
QueryType_SearchAlbums,
QueryType_SearchSongs,
};
signals:
public slots:
void ShowConfig();
void TryLogin();
void SendLogin(const QString &app_id, const QString &username, const QString &password);
void GetArtists();
void GetAlbums();
void GetSongs();
void ResetArtistsRequest();
void ResetAlbumsRequest();
void ResetSongsRequest();
private slots:
void ExitReceived();
void SendLogin();
void HandleLoginSSLErrors(QList<QSslError> ssl_errors);
void HandleAuthReply(QNetworkReply *reply);
void ResetLoginAttempts();
void StartSearch();
void ArtistsResultsReceived(const int id, const SongList &songs, const QString &error);
void AlbumsResultsReceived(const int id, const SongList &songs, const QString &error);
void SongsResultsReceived(const int id, const SongList &songs, const QString &error);
void SearchResultsReceived(const int id, const SongList &songs, const QString &error);
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);
void HandleStreamURLFinished(const QUrl &original_url, const QUrl &stream_url, const Song::FileType filetype, const int samplerate, const int bit_depth, const qint64 duration, QString error);
private:
typedef QPair<QString, QString> Param;
typedef QList<Param> ParamList;
typedef QPair<QByteArray, QByteArray> EncodedParam;
typedef QList<EncodedParam> EncodedParamList;
void SendSearch();
void LoginError(const QString &error = QString(), const QVariant &debug = QVariant());
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 *kArtistsSongsFtsTable;
static const char *kAlbumsSongsFtsTable;
static const char *kSongsFtsTable;
Application *app_;
NetworkAccessManager *network_;
QobuzUrlHandler *url_handler_;
CollectionBackend *artists_collection_backend_;
CollectionBackend *albums_collection_backend_;
CollectionBackend *songs_collection_backend_;
CollectionModel *artists_collection_model_;
CollectionModel *albums_collection_model_;
CollectionModel *songs_collection_model_;
QSortFilterProxyModel *artists_collection_sort_model_;
QSortFilterProxyModel *albums_collection_sort_model_;
QSortFilterProxyModel *songs_collection_sort_model_;
QTimer *timer_search_delay_;
QTimer *timer_login_attempt_;
std::shared_ptr<QobuzRequest> artists_request_;
std::shared_ptr<QobuzRequest> albums_request_;
std::shared_ptr<QobuzRequest> songs_request_;
std::shared_ptr<QobuzRequest> search_request_;
QobuzFavoriteRequest *favorite_request_;
QString app_id_;
QString app_secret_;
QString username_;
QString password_;
int format_;
int search_delay_;
int artistssearchlimit_;
int albumssearchlimit_;
int songssearchlimit_;
bool download_album_covers_;
qint64 user_id_;
QString user_auth_token_;
QString device_id_;
qint64 credential_id_;
int pending_search_id_;
int next_pending_search_id_;
QString pending_search_text_;
InternetSearch::SearchType pending_search_type_;
int search_id_;
QString search_text_;
bool login_sent_;
int login_attempts_;
QList<QobuzStreamURLRequest*> stream_url_requests_;
QStringList login_errors_;
QList<QObject*> wait_for_exit_;
};
#endif // QOBUZSERVICE_H

View File

@@ -1,246 +0,0 @@
/*
* Strawberry Music Player
* Copyright 2019, 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
* 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/>.
*
*/
#include "config.h"
#include <algorithm>
#include <QObject>
#include <QMimeDatabase>
#include <QMimeType>
#include <QPair>
#include <QList>
#include <QByteArray>
#include <QString>
#include <QChar>
#include <QUrl>
#include <QDateTime>
#include <QNetworkReply>
#include <QCryptographicHash>
#include <QJsonValue>
#include <QJsonObject>
#include <QtDebug>
#include "core/logging.h"
#include "core/network.h"
#include "core/song.h"
#include "core/timeconstants.h"
#include "qobuzservice.h"
#include "qobuzbaserequest.h"
#include "qobuzstreamurlrequest.h"
QobuzStreamURLRequest::QobuzStreamURLRequest(QobuzService *service, NetworkAccessManager *network, const QUrl &original_url, QObject *parent)
: QobuzBaseRequest(service, network, parent),
service_(service),
reply_(nullptr),
original_url_(original_url),
song_id_(original_url.path().toInt()),
tries_(0),
need_login_(false) {}
QobuzStreamURLRequest::~QobuzStreamURLRequest() {
if (reply_) {
disconnect(reply_, 0, this, 0);
if (reply_->isRunning()) reply_->abort();
reply_->deleteLater();
}
}
void QobuzStreamURLRequest::LoginComplete(const bool success, const QString &error) {
if (!need_login_) return;
need_login_ = false;
if (!success) {
emit StreamURLFinished(original_url_, original_url_, Song::FileType_Stream, -1, -1, -1, error);
return;
}
Process();
}
void QobuzStreamURLRequest::Process() {
if (app_id().isEmpty() || app_secret().isEmpty()) {
emit StreamURLFinished(original_url_, original_url_, Song::FileType_Stream, -1, -1, -1, tr("Missing Qobuz app ID or secret."));
return;
}
if (!authenticated()) {
need_login_ = true;
emit TryLogin();
return;
}
GetStreamURL();
}
void QobuzStreamURLRequest::Cancel() {
if (reply_ && reply_->isRunning()) {
reply_->abort();
}
else {
emit StreamURLFinished(original_url_, original_url_, Song::FileType_Stream, -1, -1, -1, tr("Cancelled."));
}
}
void QobuzStreamURLRequest::GetStreamURL() {
++tries_;
if (reply_) {
disconnect(reply_, 0, this, 0);
if (reply_->isRunning()) reply_->abort();
reply_->deleteLater();
}
QByteArray appid = app_id().toUtf8();
QByteArray secret_decoded = QByteArray::fromBase64(app_secret().toUtf8());
QString secret;
for (int x = 0, y = 0; x < secret_decoded.length(); ++x , ++y) {
if (y == appid.length()) y = 0;
secret.append(QChar(secret_decoded[x] ^ appid[y]));
}
quint64 timestamp = QDateTime::currentDateTime().toTime_t();
ParamList params_to_sign = ParamList() << Param("format_id", QString::number(format()))
<< Param("track_id", QString::number(song_id_));
std::sort(params_to_sign.begin(), params_to_sign.end());
QString data_to_sign;
data_to_sign += "trackgetFileUrl";
for (const Param &param : params_to_sign) {
data_to_sign += param.first + param.second;
}
data_to_sign += QString::number(timestamp);
data_to_sign += secret.toUtf8();
QByteArray const digest = QCryptographicHash::hash(data_to_sign.toUtf8(), QCryptographicHash::Md5);
QString signature = QString::fromLatin1(digest.toHex()).rightJustified(32, '0').toLower();
ParamList params = params_to_sign;
params << Param("request_ts", QString::number(timestamp));
params << Param("request_sig", signature);
params << Param("user_auth_token", user_auth_token());
std::sort(params.begin(), params.end());
reply_ = CreateRequest(QString("track/getFileUrl"), params);
connect(reply_, SIGNAL(finished()), this, SLOT(StreamURLReceived()));
}
void QobuzStreamURLRequest::StreamURLReceived() {
if (!reply_) return;
QByteArray data = GetReplyData(reply_);
disconnect(reply_, 0, this, 0);
reply_->deleteLater();
reply_ = nullptr;
if (data.isEmpty()) {
if (!authenticated() && login_sent() && tries_ <= 1) {
need_login_ = true;
return;
}
emit StreamURLFinished(original_url_, original_url_, Song::FileType_Stream, -1, -1, -1, errors_.first());
return;
}
QJsonObject json_obj = ExtractJsonObj(data);
if (json_obj.isEmpty()) {
emit StreamURLFinished(original_url_, original_url_, Song::FileType_Stream, -1, -1, -1, errors_.first());
return;
}
if (!json_obj.contains("track_id")) {
Error("Invalid Json reply, stream url is missing track_id.", json_obj);
emit StreamURLFinished(original_url_, original_url_, Song::FileType_Stream, -1, -1, -1, errors_.first());
return;
}
int track_id = json_obj["track_id"].toInt();
if (track_id != song_id_) {
Error("Incorrect track ID returned.", json_obj);
emit StreamURLFinished(original_url_, original_url_, Song::FileType_Stream, -1, -1, -1, errors_.first());
return;
}
if (!json_obj.contains("mime_type") || !json_obj.contains("url")) {
Error("Invalid Json reply, stream url is missing url or mime_type.", json_obj);
emit StreamURLFinished(original_url_, original_url_, Song::FileType_Stream, -1, -1, -1, errors_.first());
return;
}
QUrl url(json_obj["url"].toString());
QString mimetype = json_obj["mime_type"].toString();
Song::FileType filetype(Song::FileType_Unknown);
QMimeDatabase mimedb;
for (QString suffix : mimedb.mimeTypeForName(mimetype.toUtf8()).suffixes()) {
filetype = Song::FiletypeByExtension(suffix);
if (filetype != Song::FileType_Unknown) break;
}
if (filetype == Song::FileType_Unknown) {
qLog(Debug) << "Qobuz: Unknown mimetype" << mimetype;
filetype = Song::FileType_Stream;
}
if (!url.isValid()) {
Error("Returned stream url is invalid.", json_obj);
emit StreamURLFinished(original_url_, original_url_, filetype, -1, -1, -1, errors_.first());
return;
}
qint64 duration = -1;
if (json_obj.contains("duration")) {
duration = json_obj["duration"].toDouble() * kNsecPerSec;
}
int samplerate = -1;
if (json_obj.contains("sampling_rate")) {
samplerate = json_obj["sampling_rate"].toDouble() * 1000;
}
int bit_depth = -1;
if (json_obj.contains("bit_depth")) {
bit_depth = json_obj["bit_depth"].toDouble();
}
emit StreamURLFinished(original_url_, url, filetype, samplerate, bit_depth, duration);
}
void QobuzStreamURLRequest::Error(const QString &error, const QVariant &debug) {
if (!error.isEmpty()) {
qLog(Error) << "Qobuz:" << error;
errors_ << error;
}
if (debug.isValid()) qLog(Debug) << debug;
}

View File

@@ -1,76 +0,0 @@
/*
* Strawberry Music Player
* Copyright 2019, 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
* 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 QOBUZSTREAMURLREQUEST_H
#define QOBUZSTREAMURLREQUEST_H
#include "config.h"
#include <QtGlobal>
#include <QObject>
#include <QVariant>
#include <QString>
#include <QStringList>
#include <QUrl>
#include "core/song.h"
#include "qobuzbaserequest.h"
class QNetworkReply;
class NetworkAccessManager;
class QobuzService;
class QobuzStreamURLRequest : public QobuzBaseRequest {
Q_OBJECT
public:
QobuzStreamURLRequest(QobuzService *service, NetworkAccessManager *network, const QUrl &original_url, QObject *parent);
~QobuzStreamURLRequest();
void GetStreamURL();
void Process();
void NeedLogin() { need_login_ = true; }
void Cancel();
QUrl original_url() { return original_url_; }
int song_id() { return song_id_; }
bool need_login() { return need_login_; }
signals:
void TryLogin();
void StreamURLFinished(const QUrl &original_url, const QUrl &stream_url, const Song::FileType filetype, const int samplerate, const int bit_depth, const qint64 duration, QString error = QString());
private slots:
void LoginComplete(const bool success, const QString &error = QString());
void StreamURLReceived();
private:
void Error(const QString &error, const QVariant &debug = QVariant());
QobuzService *service_;
QNetworkReply *reply_;
QUrl original_url_;
int song_id_;
int tries_;
bool need_login_;
QStringList errors_;
};
#endif // QOBUZSTREAMURLREQUEST_H

View File

@@ -1,66 +0,0 @@
/*
* Strawberry Music Player
* Copyright 2018, 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
* 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/>.
*
*/
#include <QObject>
#include <QString>
#include <QUrl>
#include "core/application.h"
#include "core/taskmanager.h"
#include "core/song.h"
#include "qobuz/qobuzservice.h"
#include "qobuzurlhandler.h"
QobuzUrlHandler::QobuzUrlHandler(Application *app, QobuzService *service) :
UrlHandler(service),
app_(app),
service_(service),
task_id_(-1)
{
connect(service, SIGNAL(StreamURLFinished(const QUrl&, const QUrl&, const Song::FileType, const int, const int, const qint64, QString)), this, SLOT(GetStreamURLFinished(const QUrl&, const QUrl&, const Song::FileType, const int, const int, const qint64, QString)));
}
UrlHandler::LoadResult QobuzUrlHandler::StartLoading(const QUrl &url) {
LoadResult ret(url);
if (task_id_ != -1) return ret;
task_id_ = app_->task_manager()->StartTask(QString("Loading %1 stream...").arg(url.scheme()));
service_->GetStreamURL(url);
ret.type_ = LoadResult::WillLoadAsynchronously;
return ret;
}
void QobuzUrlHandler::GetStreamURLFinished(const QUrl &original_url, const QUrl &stream_url, const Song::FileType filetype, const int samplerate, const int bit_depth, const qint64 duration, QString error) {
if (task_id_ == -1) return;
CancelTask();
if (error.isEmpty())
emit AsyncLoadComplete(LoadResult(original_url, LoadResult::TrackAvailable, stream_url, filetype, samplerate, bit_depth, duration));
else
emit AsyncLoadComplete(LoadResult(original_url, LoadResult::Error, stream_url, filetype, -1, -1, -1, error));
}
void QobuzUrlHandler::CancelTask() {
app_->task_manager()->SetTaskFinished(task_id_);
task_id_ = -1;
}

View File

@@ -1,55 +0,0 @@
/*
* Strawberry Music Player
* Copyright 2018, 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
* 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 QOBUZURLHANDLER_H
#define QOBUZURLHANDLER_H
#include <QtGlobal>
#include <QObject>
#include <QString>
#include <QUrl>
#include "core/urlhandler.h"
#include "core/song.h"
#include "qobuz/qobuzservice.h"
class Application;
class QobuzUrlHandler : public UrlHandler {
Q_OBJECT
public:
QobuzUrlHandler(Application *app, QobuzService *service);
QString scheme() const { return service_->url_scheme(); }
LoadResult StartLoading(const QUrl &url);
void CancelTask();
private slots:
void GetStreamURLFinished(const QUrl &original_url, const QUrl &stream_url, const Song::FileType filetype, const int samplerate, const int bit_depth, const qint64 duration, QString error = QString());
private:
Application *app_;
QobuzService *service_;
int task_id_;
};
#endif