Formatting
This commit is contained in:
@@ -35,7 +35,7 @@ using namespace Qt::Literals::StringLiterals;
|
||||
|
||||
namespace {
|
||||
constexpr char kApiChannelsUrl[] = "https://api.radioparadise.com/api/list_streams";
|
||||
}
|
||||
} // namespace
|
||||
|
||||
RadioParadiseService::RadioParadiseService(const SharedPtr<TaskManager> task_manager, const SharedPtr<NetworkAccessManager> network, QObject *parent)
|
||||
: RadioService(Song::Source::RadioParadise, u"Radio Paradise"_s, IconLoader::Load(u"radioparadise"_s), task_manager, network, parent) {}
|
||||
@@ -60,9 +60,8 @@ void RadioParadiseService::GetChannels() {
|
||||
|
||||
Abort();
|
||||
|
||||
QUrl url(QString::fromLatin1(kApiChannelsUrl));
|
||||
QNetworkRequest req(url);
|
||||
QNetworkReply *reply = network_->get(req);
|
||||
QNetworkRequest network_request(QUrl(QString::fromLatin1(kApiChannelsUrl)));
|
||||
QNetworkReply *reply = network_->get(network_request);
|
||||
replies_ << reply;
|
||||
const int task_id = task_manager_->StartTask(tr("Getting %1 channels").arg(name_));
|
||||
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, task_id]() { GetChannelsReply(reply, task_id); });
|
||||
@@ -74,7 +73,7 @@ void RadioParadiseService::GetChannelsReply(QNetworkReply *reply, const int task
|
||||
if (replies_.contains(reply)) replies_.removeAll(reply);
|
||||
reply->deleteLater();
|
||||
|
||||
QJsonObject object = ExtractJsonObj(reply);
|
||||
const QJsonObject object = ExtractJsonObj(reply);
|
||||
if (object.isEmpty()) {
|
||||
task_manager_->SetTaskFinished(task_id);
|
||||
Q_EMIT NewChannels();
|
||||
@@ -92,23 +91,23 @@ void RadioParadiseService::GetChannelsReply(QNetworkReply *reply, const int task
|
||||
RadioChannelList channels;
|
||||
for (const QJsonValue &value_channel : array_channels) {
|
||||
if (!value_channel.isObject()) continue;
|
||||
QJsonObject obj_channel = value_channel.toObject();
|
||||
const QJsonObject obj_channel = value_channel.toObject();
|
||||
if (!obj_channel.contains("chan_name"_L1) || !obj_channel.contains("streams"_L1)) {
|
||||
continue;
|
||||
}
|
||||
QString name = obj_channel["chan_name"_L1].toString();
|
||||
QJsonValue value_streams = obj_channel["streams"_L1];
|
||||
const QString name = obj_channel["chan_name"_L1].toString();
|
||||
const QJsonValue value_streams = obj_channel["streams"_L1];
|
||||
if (!value_streams.isArray()) {
|
||||
continue;
|
||||
}
|
||||
const QJsonArray array_streams = obj_channel["streams"_L1].toArray();
|
||||
for (const QJsonValue &value_stream : array_streams) {
|
||||
if (!value_stream.isObject()) continue;
|
||||
QJsonObject obj_stream = value_stream.toObject();
|
||||
const QJsonObject obj_stream = value_stream.toObject();
|
||||
if (!obj_stream.contains("label"_L1) || !obj_stream.contains("url"_L1)) {
|
||||
continue;
|
||||
}
|
||||
QString label = obj_stream["label"_L1].toString();
|
||||
const QString label = obj_stream["label"_L1].toString();
|
||||
QString url = obj_stream["url"_L1].toString();
|
||||
static const QRegularExpression regex_url_schema(u"^[0-9a-zA-Z]*:\\/\\/"_s, QRegularExpression::CaseInsensitiveOption);
|
||||
if (!url.contains(regex_url_schema)) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2021, Jonas Kvinge <jonas@jkvinge.net>
|
||||
* Copyright 2021-2025, 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
|
||||
@@ -66,30 +66,30 @@ QJsonObject RadioService::ExtractJsonObj(const QByteArray &data) {
|
||||
}
|
||||
|
||||
QJsonParseError json_error;
|
||||
QJsonDocument json_doc = QJsonDocument::fromJson(data, &json_error);
|
||||
const QJsonDocument json_document = QJsonDocument::fromJson(data, &json_error);
|
||||
|
||||
if (json_error.error != QJsonParseError::NoError) {
|
||||
Error(QStringLiteral("Failed to parse Json data from %1: %2").arg(name_, json_error.errorString()));
|
||||
return QJsonObject();
|
||||
}
|
||||
|
||||
if (json_doc.isEmpty()) {
|
||||
if (json_document.isEmpty()) {
|
||||
Error(QStringLiteral("%1: Received empty Json document.").arg(name_), data);
|
||||
return QJsonObject();
|
||||
}
|
||||
|
||||
if (!json_doc.isObject()) {
|
||||
Error(QStringLiteral("%1: Json document is not an object.").arg(name_), json_doc);
|
||||
if (!json_document.isObject()) {
|
||||
Error(QStringLiteral("%1: Json document is not an object.").arg(name_), json_document);
|
||||
return QJsonObject();
|
||||
}
|
||||
|
||||
QJsonObject json_obj = json_doc.object();
|
||||
if (json_obj.isEmpty()) {
|
||||
Error(QStringLiteral("%1: Received empty Json object.").arg(name_), json_doc);
|
||||
const QJsonObject json_object = json_document.object();
|
||||
if (json_object.isEmpty()) {
|
||||
Error(QStringLiteral("%1: Received empty Json object.").arg(name_), json_document);
|
||||
return QJsonObject();
|
||||
}
|
||||
|
||||
return json_obj;
|
||||
return json_object;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2021, Jonas Kvinge <jonas@jkvinge.net>
|
||||
* Copyright 2021-2025, 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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2021, Jonas Kvinge <jonas@jkvinge.net>
|
||||
* Copyright 2021-2025, 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
|
||||
@@ -39,7 +39,7 @@ using namespace Qt::Literals::StringLiterals;
|
||||
|
||||
namespace {
|
||||
constexpr char kApiChannelsUrl[] = "https://somafm.com/channels.json";
|
||||
}
|
||||
} // namespace
|
||||
|
||||
SomaFMService::SomaFMService(const SharedPtr<TaskManager> task_manager, const SharedPtr<NetworkAccessManager> network, QObject *parent)
|
||||
: RadioService(Song::Source::SomaFM, u"SomaFM"_s, IconLoader::Load(u"somafm"_s), task_manager, network, parent) {}
|
||||
@@ -68,9 +68,9 @@ void SomaFMService::GetChannels() {
|
||||
|
||||
Abort();
|
||||
|
||||
QUrl url(QString::fromLatin1(kApiChannelsUrl));
|
||||
QNetworkRequest req(url);
|
||||
QNetworkReply *reply = network_->get(req);
|
||||
const QUrl url(QString::fromLatin1(kApiChannelsUrl));
|
||||
QNetworkRequest network_request(url);
|
||||
QNetworkReply *reply = network_->get(network_request);
|
||||
replies_ << reply;
|
||||
const int task_id = task_manager_->StartTask(tr("Getting %1 channels").arg(name_));
|
||||
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, task_id]() { GetChannelsReply(reply, task_id); });
|
||||
@@ -82,7 +82,7 @@ void SomaFMService::GetChannelsReply(QNetworkReply *reply, const int task_id) {
|
||||
if (replies_.contains(reply)) replies_.removeAll(reply);
|
||||
reply->deleteLater();
|
||||
|
||||
QJsonObject object = ExtractJsonObj(reply);
|
||||
const QJsonObject object = ExtractJsonObj(reply);
|
||||
if (object.isEmpty()) {
|
||||
task_manager_->SetTaskFinished(task_id);
|
||||
Q_EMIT NewChannels();
|
||||
@@ -141,8 +141,8 @@ void SomaFMService::GetChannelsReply(QNetworkReply *reply, const int task_id) {
|
||||
|
||||
void SomaFMService::GetStreamUrl(const int task_id, const RadioChannel &channel) {
|
||||
|
||||
QNetworkRequest req(channel.url);
|
||||
QNetworkReply *reply = network_->get(req);
|
||||
QNetworkRequest network_request(channel.url);
|
||||
QNetworkReply *reply = network_->get(network_request);
|
||||
replies_ << reply;
|
||||
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, task_id, channel]() { GetStreamUrlsReply(reply, task_id, channel); });
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2021, Jonas Kvinge <jonas@jkvinge.net>
|
||||
* Copyright 2021-2025, 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
|
||||
|
||||
Reference in New Issue
Block a user