Migrate to VoidLibrary (toolchain + API groundwork)
This commit is contained in:
1 parent
5e1e3d66c4
commit
e17cfed56f
38 files changed
+3077
-2505
No files matched your search
@@ -0,0 +1,196 @@
|
||||
#pragma once
|
||||
|
||||
#include "AudioTypes.hpp"
|
||||
#include "Types.hpp"
|
||||
#include <Void/Data/Reflect.hpp> // Void::Json::Value + ReflectError
|
||||
#include <chrono>
|
||||
#include <expected>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Echoion::Api
|
||||
{
|
||||
|
||||
enum class TrackSource : uint8_t {
|
||||
Unknown = 0,
|
||||
YouTube,
|
||||
SoundCloud,
|
||||
Spotify,
|
||||
LocalFile,
|
||||
URL
|
||||
};
|
||||
|
||||
struct TrackInfo {
|
||||
std::string id;
|
||||
std::string title;
|
||||
std::string artist;
|
||||
std::string album;
|
||||
std::optional<std::string> thumbnailUrl;
|
||||
std::optional<std::chrono::milliseconds> duration;
|
||||
TrackSource source;
|
||||
std::string originalUrl;
|
||||
std::optional<std::string>
|
||||
shortenedUrl; // faumaray.ru shortened link
|
||||
std::optional<std::string> streamUrl;
|
||||
std::optional<AudioStreamInfo> audioInfo;
|
||||
std::chrono::system_clock::time_point addedAt;
|
||||
std::string requestedBy;
|
||||
|
||||
// Format track as markdown link: [Title](shortenedUrl)
|
||||
// Only uses shortened URL (faumaray), returns empty string if not
|
||||
// available
|
||||
[[nodiscard]] std::string formatWithLink() const
|
||||
{
|
||||
if (shortenedUrl.has_value() && !shortenedUrl->empty()) {
|
||||
return std::format("[{}]({})", title, *shortenedUrl);
|
||||
}
|
||||
return std::format("[{}]",
|
||||
title); // No link if no shortened URL
|
||||
}
|
||||
|
||||
// Format track with artist and link
|
||||
// Only uses shortened URL (faumaray), returns text only if not
|
||||
// available
|
||||
[[nodiscard]] std::string formatWithArtistAndLink() const
|
||||
{
|
||||
std::string displayTitle = title;
|
||||
if (!artist.empty()) {
|
||||
displayTitle = std::format("{} by {}", title, artist);
|
||||
}
|
||||
if (shortenedUrl.has_value() && !shortenedUrl->empty()) {
|
||||
return std::format("[{}]({})", displayTitle, *shortenedUrl);
|
||||
}
|
||||
return displayTitle; // No link if no shortened URL
|
||||
}
|
||||
|
||||
// ── Void::Json customization ──────────────────────────────────
|
||||
// TrackInfo holds chrono and an optional nested AudioStreamInfo,
|
||||
// neither of which Void::Json reflection covers, so it provides an
|
||||
// explicit serializer. chrono is stored as integer milliseconds and
|
||||
// the enum as its underlying value (stable round-trips). The
|
||||
// transient audioInfo (re-derived on playback) is intentionally not
|
||||
// persisted.
|
||||
[[nodiscard]] Void::Json::Value to_json() const
|
||||
{
|
||||
using Void::Json::Value;
|
||||
Value out = Void::Json::object();
|
||||
auto& o = out.as_object();
|
||||
o.emplace_back("id", Value{id});
|
||||
o.emplace_back("title", Value{title});
|
||||
o.emplace_back("artist", Value{artist});
|
||||
o.emplace_back("album", Value{album});
|
||||
o.emplace_back("thumbnailUrl", thumbnailUrl
|
||||
? Value{*thumbnailUrl}
|
||||
: Value{nullptr});
|
||||
o.emplace_back(
|
||||
"durationMs",
|
||||
duration ? Value{static_cast<double>(duration->count())}
|
||||
: Value{nullptr});
|
||||
o.emplace_back("source",
|
||||
Value{static_cast<double>(
|
||||
static_cast<std::uint8_t>(source))});
|
||||
o.emplace_back("originalUrl", Value{originalUrl});
|
||||
o.emplace_back("shortenedUrl", shortenedUrl ? Value{*shortenedUrl}
|
||||
: Value{nullptr});
|
||||
o.emplace_back("streamUrl",
|
||||
streamUrl ? Value{*streamUrl} : Value{nullptr});
|
||||
o.emplace_back(
|
||||
"addedAtMs",
|
||||
Value{static_cast<double>(
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
addedAt.time_since_epoch())
|
||||
.count())});
|
||||
o.emplace_back("requestedBy", Value{requestedBy});
|
||||
return out;
|
||||
}
|
||||
|
||||
[[nodiscard]] static std::expected<TrackInfo, Void::Json::ReflectError>
|
||||
from_json(const Void::Json::Value& j)
|
||||
{
|
||||
TrackInfo t;
|
||||
const auto str = [&](const char* k) -> std::string {
|
||||
const auto* v = j.find(k);
|
||||
return (v && v->is_string()) ? v->as_string()
|
||||
: std::string{};
|
||||
};
|
||||
const auto optStr =
|
||||
[&](const char* k) -> std::optional<std::string> {
|
||||
const auto* v = j.find(k);
|
||||
if (v && v->is_string()) {
|
||||
return v->as_string();
|
||||
}
|
||||
return std::nullopt;
|
||||
};
|
||||
t.id = str("id");
|
||||
t.title = str("title");
|
||||
t.artist = str("artist");
|
||||
t.album = str("album");
|
||||
t.thumbnailUrl = optStr("thumbnailUrl");
|
||||
if (const auto* d = j.find("durationMs");
|
||||
d && d->is_number()) {
|
||||
t.duration = std::chrono::milliseconds(
|
||||
static_cast<std::int64_t>(d->as_number()));
|
||||
}
|
||||
if (const auto* s = j.find("source"); s && s->is_number()) {
|
||||
t.source = static_cast<TrackSource>(
|
||||
static_cast<std::uint8_t>(s->as_number()));
|
||||
} else {
|
||||
t.source = TrackSource::Unknown;
|
||||
}
|
||||
t.originalUrl = str("originalUrl");
|
||||
t.shortenedUrl = optStr("shortenedUrl");
|
||||
t.streamUrl = optStr("streamUrl");
|
||||
if (const auto* a = j.find("addedAtMs");
|
||||
a && a->is_number()) {
|
||||
t.addedAt = std::chrono::system_clock::time_point(
|
||||
std::chrono::milliseconds(
|
||||
static_cast<std::int64_t>(a->as_number())));
|
||||
}
|
||||
t.requestedBy = str("requestedBy");
|
||||
return t;
|
||||
}
|
||||
};
|
||||
|
||||
struct PlaylistInfo {
|
||||
std::string id;
|
||||
std::string name;
|
||||
std::string description;
|
||||
std::optional<std::string> thumbnailUrl;
|
||||
std::string owner;
|
||||
std::vector<TrackInfo> tracks;
|
||||
std::chrono::system_clock::time_point createdAt;
|
||||
std::chrono::system_clock::time_point updatedAt;
|
||||
};
|
||||
|
||||
struct QueueEntry {
|
||||
uint64_t queueId;
|
||||
TrackInfo track;
|
||||
std::chrono::system_clock::time_point addedAt;
|
||||
std::string addedBy;
|
||||
bool isPlaying;
|
||||
std::optional<std::chrono::milliseconds> position;
|
||||
};
|
||||
|
||||
struct PlaybackState {
|
||||
std::optional<QueueEntry> currentTrack;
|
||||
std::vector<QueueEntry> queue;
|
||||
bool isPlaying;
|
||||
bool isPaused;
|
||||
std::chrono::milliseconds position;
|
||||
std::chrono::milliseconds buffered;
|
||||
float volume;
|
||||
bool repeat;
|
||||
bool shuffle;
|
||||
std::chrono::system_clock::time_point lastUpdate;
|
||||
};
|
||||
|
||||
struct SearchResult {
|
||||
std::vector<TrackInfo> tracks;
|
||||
std::vector<PlaylistInfo> playlists;
|
||||
std::string query;
|
||||
std::optional<std::string> nextPageToken;
|
||||
uint32_t totalResults;
|
||||
};
|
||||
|
||||
} // namespace Echoion::Api
|
||||
Reference in new issue
Block a user