Added podcast support, only from subsonic API for now, ref #726

This commit is contained in:
emeric
2025-09-13 15:04:13 +02:00
parent 1d584ebcc6
commit 932e7715f5
111 changed files with 4717 additions and 188 deletions
+1
View File
@@ -51,6 +51,7 @@ namespace lms::core::logging
HTTP,
MAIN,
METADATA,
PODCAST,
REMOTE,
SCROBBLING,
SERVICE,
-6
View File
@@ -24,14 +24,8 @@
#include <string>
#include <string_view>
#include <Wt/WDateTime.h>
namespace lms::core::pathUtils
{
// Make sure the given path is a directory
// Create it if needed
bool ensureDirectory(const std::filesystem::path& dir);
// Check if file's extension is one of provided extensions
bool hasFileAnyExtension(const std::filesystem::path& file, std::span<const std::filesystem::path> extensions);
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2025 Emeric Poupon
*
* This file is part of LMS.
*
* LMS 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.
*
* LMS 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 LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <cstddef>
namespace lms::core::literals
{
constexpr std::size_t operator""_KiB(unsigned long long int x)
{
return 1024ULL * x;
}
constexpr std::size_t operator""_MiB(unsigned long long int x)
{
return 1024_KiB * x;
}
constexpr std::size_t operator""_GiB(unsigned long long int x)
{
return 1024_MiB * x;
}
constexpr std::size_t operator""_TiB(unsigned long long int x)
{
return 1024_GiB * x;
}
constexpr std::size_t operator""_PiB(unsigned long long int x)
{
return 1024_TiB * x;
}
} // namespace lms::core::literals
+3 -1
View File
@@ -110,12 +110,14 @@ namespace lms::core::stringUtils
[[nodiscard]] bool stringEndsWith(std::string_view str, std::string_view ending);
[[nodiscard]] std::optional<std::string> stringFromHex(const std::string& str);
[[nodiscard]] std::optional<std::string> stringFromHex(std::string_view str);
[[nodiscard]] std::string toHexString(std::string_view str);
[[nodiscard]] std::string toISO8601String(const Wt::WDateTime& dateTime);
[[nodiscard]] std::string toISO8601String(const Wt::WDate& date);
[[nodiscard]] Wt::WDateTime fromISO8601String(std::string_view dateTime);
[[nodiscard]] Wt::WDateTime fromRFC822String(std::string_view dateTime);
// to "[minutes:seconds.milliseconds]"
std::string formatTimestamp(std::chrono::milliseconds timestamp);
@@ -19,8 +19,9 @@
#pragma once
#include <cstddef>
#include <functional>
#include <string_view>
#include <span>
#include <vector>
#include <Wt/Http/Message.h>
@@ -37,13 +38,28 @@ namespace lms::core::http
};
Priority priority{ Priority::Normal };
std::string relativeUrl; // relative to baseUrl used by the client
std::string relativeUrl; // relative to baseUrl used by the client
std::size_t responseBufferSize{ 10 * 1024 * 1024 }; // only used if onChunkReceived is not set
using OnSuccessFunc = std::function<void(std::string_view msgBody)>;
// If `onChunkReceived` is set, the response will be streamed in chunks.
// In that case, `onSuccessFunc` is still called at the end (with an empty msgBody).
// If `onChunkReceived` is not set, the response will be fully buffered and passed to `onSuccessFunc`.
enum class ChunckReceivedResult
{
Continue,
Abort,
};
using OnChunkReceived = std::function<ChunckReceivedResult(std::span<const std::byte> chunk)>; // return false to stop (onFailureFunc callback will be called)
OnChunkReceived onChunkReceived;
using OnSuccessFunc = std::function<void(const Wt::Http::Message& msg)>;
OnSuccessFunc onSuccessFunc;
using OnFailureFunc = std::function<void()>;
OnFailureFunc onFailureFunc;
using OnAbortFunc = std::function<void()>;
OnAbortFunc onAbortFunc;
};
struct ClientGETRequestParameters final : public ClientRequestParameters
@@ -27,6 +27,8 @@
namespace lms::core::http
{
// Very simple http client, will handle all requests sequentially.
// User callbacks are dispatched within a strand.
class IClient
{
public:
@@ -34,6 +36,8 @@ namespace lms::core::http
virtual void sendGETRequest(ClientGETRequestParameters&& request) = 0;
virtual void sendPOSTRequest(ClientPOSTRequestParameters&& request) = 0;
virtual void abortAllRequests() = 0;
};
std::unique_ptr<IClient> createClient(boost::asio::io_context& ioContext, std::string_view baseUrl);