2019-06-17 23:54:24 +02:00
|
|
|
/*
|
|
|
|
* Strawberry Music Player
|
2021-03-20 21:14:47 +01:00
|
|
|
* Copyright 2019-2021, Jonas Kvinge <jonas@jkvinge.net>
|
2019-06-17 23:54:24 +02:00
|
|
|
*
|
|
|
|
* Strawberry is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Strawberry is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-12 00:07:05 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2020-02-09 02:29:35 +01:00
|
|
|
#include <QtGlobal>
|
2019-06-17 23:54:24 +02:00
|
|
|
#include <QUrl>
|
|
|
|
#include <QUrlQuery>
|
|
|
|
|
|
|
|
#include "subsonicservice.h"
|
2021-09-21 01:27:55 +02:00
|
|
|
#include "subsonicbaserequest.h"
|
2019-06-17 23:54:24 +02:00
|
|
|
#include "subsonicurlhandler.h"
|
|
|
|
|
|
|
|
class Application;
|
|
|
|
|
2019-09-15 20:27:32 +02:00
|
|
|
SubsonicUrlHandler::SubsonicUrlHandler(Application *app, SubsonicService *service) : UrlHandler(service), service_(service) {
|
|
|
|
Q_UNUSED(app);
|
|
|
|
}
|
2019-06-17 23:54:24 +02:00
|
|
|
|
|
|
|
UrlHandler::LoadResult SubsonicUrlHandler::StartLoading(const QUrl &url) {
|
|
|
|
|
2019-06-20 20:49:02 +02:00
|
|
|
if (!server_url().isValid()) {
|
2021-07-23 21:30:08 +02:00
|
|
|
return LoadResult(url, LoadResult::Error, tr("Subsonic server URL is invalid."));
|
2019-06-20 20:49:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (username().isEmpty() || password().isEmpty()) {
|
2021-07-23 21:30:08 +02:00
|
|
|
return LoadResult(url, LoadResult::Error, tr("Missing Subsonic username or password."));
|
2019-06-20 20:49:02 +02:00
|
|
|
}
|
|
|
|
|
2021-09-25 01:18:08 +02:00
|
|
|
const QUrl stream_url = SubsonicBaseRequest::CreateUrl(server_url(), auth_method(), username(), password(), "stream", ParamList() << Param("id", url.path()));
|
2019-06-17 23:54:24 +02:00
|
|
|
|
2019-09-07 23:34:13 +02:00
|
|
|
return LoadResult(url, LoadResult::TrackAvailable, stream_url);
|
2019-06-17 23:54:24 +02:00
|
|
|
|
|
|
|
}
|