mirror of
https://github.com/strawberrymusicplayer/strawberry
synced 2025-01-30 00:55:33 +01:00
Subsonic: Use common static function CreateUrl()
This commit is contained in:
parent
23ef4fb132
commit
71868936d1
@ -57,9 +57,13 @@ SubsonicBaseRequest::SubsonicBaseRequest(SubsonicService *service, QObject *pare
|
||||
|
||||
}
|
||||
|
||||
void SubsonicBaseRequest::AddPasswordToParams(ParamList ¶ms, const SubsonicSettingsPage::AuthMethod auth_method, const QString &password) {
|
||||
QUrl SubsonicBaseRequest::CreateUrl(const QUrl &server_url, const SubsonicSettingsPage::AuthMethod auth_method, const QString &username, const QString &password, const QString &ressource_name, const ParamList ¶ms_provided) {
|
||||
|
||||
if (password.isEmpty()) return;
|
||||
ParamList params = ParamList() << params_provided
|
||||
<< Param("c", SubsonicService::kClientName)
|
||||
<< Param("v", SubsonicService::kApiVersion)
|
||||
<< Param("f", "json")
|
||||
<< Param("u", username);
|
||||
|
||||
if (auth_method == SubsonicSettingsPage::AuthMethod_Hex) {
|
||||
params << Param("p", QString("enc:" + password.toUtf8().toHex()));
|
||||
@ -73,24 +77,12 @@ void SubsonicBaseRequest::AddPasswordToParams(ParamList ¶ms, const SubsonicS
|
||||
params << Param("t", md5.result().toHex());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QUrl SubsonicBaseRequest::CreateUrl(const QString &ressource_name, const ParamList ¶ms_provided) const {
|
||||
|
||||
ParamList params = ParamList() << params_provided
|
||||
<< Param("c", client_name())
|
||||
<< Param("v", api_version())
|
||||
<< Param("f", "json")
|
||||
<< Param("u", username());
|
||||
|
||||
AddPasswordToParams(params, auth_method(), password());
|
||||
|
||||
QUrlQuery url_query;
|
||||
for (const Param ¶m : params) {
|
||||
url_query.addQueryItem(QUrl::toPercentEncoding(param.first), QUrl::toPercentEncoding(param.second));
|
||||
}
|
||||
|
||||
QUrl url(server_url());
|
||||
QUrl url(server_url);
|
||||
|
||||
if (!url.path().isEmpty() && url.path().right(1) == "/") {
|
||||
url.setPath(url.path() + QString("rest/") + ressource_name + QString(".view"));
|
||||
@ -107,7 +99,7 @@ QUrl SubsonicBaseRequest::CreateUrl(const QString &ressource_name, const ParamLi
|
||||
|
||||
QNetworkReply *SubsonicBaseRequest::CreateGetRequest(const QString &ressource_name, const ParamList ¶ms_provided) const {
|
||||
|
||||
QUrl url = CreateUrl(ressource_name, params_provided);
|
||||
QUrl url = CreateUrl(server_url(), auth_method(), username(), password(), ressource_name, params_provided);
|
||||
QNetworkRequest req(url);
|
||||
|
||||
if (url.scheme() == "https" && !verify_certificate()) {
|
||||
|
@ -53,10 +53,9 @@ class SubsonicBaseRequest : public QObject {
|
||||
typedef QList<Param> ParamList;
|
||||
|
||||
public:
|
||||
static void AddPasswordToParams(ParamList ¶ms, const SubsonicSettingsPage::AuthMethod auth_method, const QString &password);
|
||||
static QUrl CreateUrl(const QUrl &server_url, const SubsonicSettingsPage::AuthMethod auth_method, const QString &username, const QString &password, const QString &ressource_name, const ParamList ¶ms_provided);
|
||||
|
||||
protected:
|
||||
QUrl CreateUrl(const QString &ressource_name, const ParamList ¶ms_provided) const;
|
||||
QNetworkReply *CreateGetRequest(const QString &ressource_name, const ParamList ¶ms_provided) const;
|
||||
QByteArray GetReplyData(QNetworkReply *reply);
|
||||
QJsonObject ExtractJsonObj(QByteArray &data);
|
||||
@ -64,8 +63,6 @@ class SubsonicBaseRequest : public QObject {
|
||||
virtual void Error(const QString &error, const QVariant &debug = QVariant()) = 0;
|
||||
static QString ErrorsToHTML(const QStringList &errors);
|
||||
|
||||
QString client_name() const { return service_->client_name(); }
|
||||
QString api_version() const { return service_->api_version(); }
|
||||
QUrl server_url() const { return service_->server_url(); }
|
||||
QString username() const { return service_->username(); }
|
||||
QString password() const { return service_->password(); }
|
||||
|
@ -346,8 +346,7 @@ void SubsonicRequest::FlushAlbumSongsRequests() {
|
||||
|
||||
Request request = album_songs_requests_queue_.dequeue();
|
||||
++album_songs_requests_active_;
|
||||
ParamList params = ParamList() << Param("id", request.album_id);
|
||||
QNetworkReply *reply = CreateGetRequest(QString("getAlbum"), params);
|
||||
QNetworkReply *reply = CreateGetRequest(QString("getAlbum"), ParamList() << Param("id", request.album_id));
|
||||
replies_ << reply;
|
||||
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, request]() { AlbumSongsReplyReceived(reply, request.artist_id, request.album_id, request.album_artist); });
|
||||
timeouts_->AddReply(reply);
|
||||
@ -635,7 +634,7 @@ QString SubsonicRequest::ParseSong(Song &song, const QJsonObject &json_obj, cons
|
||||
|
||||
QUrl cover_url;
|
||||
if (!cover_art_id.isEmpty()) {
|
||||
cover_url = CreateUrl("getCoverArt", ParamList() << Param("id", cover_art_id));
|
||||
cover_url = CreateUrl(server_url(), auth_method(), username(), password(), "getCoverArt", ParamList() << Param("id", cover_art_id));
|
||||
}
|
||||
|
||||
Song::FileType filetype(Song::FileType_Stream);
|
||||
|
@ -75,12 +75,11 @@ void SubsonicScrobbleRequest::FlushScrobbleRequests() {
|
||||
Request request = scrobble_requests_queue_.dequeue();
|
||||
++scrobble_requests_active_;
|
||||
|
||||
ParamList params = ParamList() <<
|
||||
Param("id", request.song_id) <<
|
||||
Param("submission", QVariant(request.submission).toString()) <<
|
||||
Param("time", QVariant(request.time_ms).toString());
|
||||
ParamList params = ParamList() << Param("id", request.song_id)
|
||||
<< Param("submission", QVariant(request.submission).toString())
|
||||
<< Param("time", QVariant(request.time_ms).toString());
|
||||
|
||||
QNetworkReply *reply = CreateGetRequest(QString("scrobble"), params);
|
||||
QNetworkReply *reply = CreateGetRequest("scrobble", params);
|
||||
replies_ << reply;
|
||||
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply]() { ScrobbleReplyReceived(reply); });
|
||||
|
||||
|
@ -60,14 +60,14 @@ class SubsonicService : public InternetService {
|
||||
~SubsonicService() override;
|
||||
|
||||
static const Song::Source kSource;
|
||||
static const char *kClientName;
|
||||
static const char *kApiVersion;
|
||||
|
||||
void ReloadSettings() override;
|
||||
void Exit() override;
|
||||
|
||||
Application *app() const { return app_; }
|
||||
|
||||
QString client_name() const { return kClientName; }
|
||||
QString api_version() const { return kApiVersion; }
|
||||
QUrl server_url() const { return server_url_; }
|
||||
QString username() const { return username_; }
|
||||
QString password() const { return password_; }
|
||||
@ -105,8 +105,6 @@ class SubsonicService : public InternetService {
|
||||
|
||||
void PingError(const QString &error = QString(), const QVariant &debug = QVariant());
|
||||
|
||||
static const char *kClientName;
|
||||
static const char *kApiVersion;
|
||||
static const char *kSongsTable;
|
||||
static const char *kSongsFtsTable;
|
||||
static const int kMaxRedirects;
|
||||
|
@ -46,29 +46,7 @@ UrlHandler::LoadResult SubsonicUrlHandler::StartLoading(const QUrl &url) {
|
||||
return LoadResult(url, LoadResult::Error, tr("Missing Subsonic username or password."));
|
||||
}
|
||||
|
||||
ParamList params = ParamList() << Param("c", client_name())
|
||||
<< Param("v", api_version())
|
||||
<< Param("f", "json")
|
||||
<< Param("u", username())
|
||||
<< Param("id", url.path());
|
||||
|
||||
SubsonicBaseRequest::AddPasswordToParams(params, auth_method(), password());
|
||||
|
||||
QUrlQuery url_query;
|
||||
for (const Param ¶m : params) {
|
||||
url_query.addQueryItem(QUrl::toPercentEncoding(param.first), QUrl::toPercentEncoding(param.second));
|
||||
}
|
||||
|
||||
QUrl stream_url(server_url());
|
||||
|
||||
if (!stream_url.path().isEmpty() && stream_url.path().right(1) == "/") {
|
||||
stream_url.setPath(stream_url.path() + QString("rest/stream.view"));
|
||||
}
|
||||
else {
|
||||
stream_url.setPath(stream_url.path() + QString("/rest/stream.view"));
|
||||
}
|
||||
|
||||
stream_url.setQuery(url_query);
|
||||
const QUrl stream_url = SubsonicBaseRequest::CreateUrl(server_url(), auth_method(), username(), password(), "stream", ParamList() << Param("id", url.path()));
|
||||
|
||||
return LoadResult(url, LoadResult::TrackAvailable, stream_url);
|
||||
|
||||
|
@ -42,8 +42,6 @@ class SubsonicUrlHandler : public UrlHandler {
|
||||
explicit SubsonicUrlHandler(Application *app, SubsonicService *service);
|
||||
|
||||
QString scheme() const override { return service_->url_scheme(); }
|
||||
QString client_name() const { return service_->client_name(); }
|
||||
QString api_version() const { return service_->api_version(); }
|
||||
QUrl server_url() const { return service_->server_url(); }
|
||||
QString username() const { return service_->username(); }
|
||||
QString password() const { return service_->password(); }
|
||||
|
Loading…
x
Reference in New Issue
Block a user