Initial commit
This commit is contained in:
commit
f6c5bcca39
52 files changed
+55449
No files matched your search
@@ -0,0 +1,419 @@
|
||||
#pragma once
|
||||
#include "PluginInterface.hpp"
|
||||
// #include "Youtube/Client.hpp"
|
||||
#include "ts6bot/AudioDecoder.hpp"
|
||||
#include <memory>
|
||||
#include <quill/Backend.h>
|
||||
#include <quill/Frontend.h>
|
||||
#include <quill/LogMacros.h>
|
||||
#include <quill/Logger.h>
|
||||
#include <quill/core/SinkManager.h>
|
||||
#include <singleton_atomic.hpp>
|
||||
#include "ts6bot/Config.hpp"
|
||||
#include <ts6bot/MusicManager.hpp>
|
||||
#include "quill/sinks/FileSink.h"
|
||||
#include "quill/sinks/ConsoleSink.h"
|
||||
#include <ts6bot/Proxy.hpp>
|
||||
|
||||
#include "PluginDefinitions.hpp"
|
||||
#include "ts6bot/MusicManager.hpp"
|
||||
|
||||
class EchoionCore : public IEchoionPlugin {
|
||||
// Dependencies
|
||||
quill::Logger *m_logger = nullptr;
|
||||
std::shared_ptr<TS3Functions> m_ts3;
|
||||
std::unique_ptr<MusicManager> m_musicManager;
|
||||
|
||||
public:
|
||||
explicit EchoionCore(std::shared_ptr<TS3Functions> funcs) {
|
||||
m_ts3 = std::move(funcs);
|
||||
}
|
||||
|
||||
void Initialize(bool start = true) override;
|
||||
|
||||
void Shutdown() override;
|
||||
|
||||
// --- HOT RELOAD ---
|
||||
void RequestGracefulStop() override ;
|
||||
|
||||
bool IsStopped() override;
|
||||
|
||||
std::string SerializeState() override;
|
||||
|
||||
void DeserializeState(const std::string &jsonState) override;
|
||||
|
||||
void onConnectStatusChangeEvent(uint64 serverConnectionHandlerID, int newStatus, unsigned errorNumber) override {
|
||||
}
|
||||
|
||||
void onNewChannelEvent(uint64 serverConnectionHandlerID, uint64 channelID, uint64 channelParentID) override {
|
||||
}
|
||||
|
||||
void onNewChannelCreatedEvent(uint64 serverConnectionHandlerID, uint64 channelID, uint64 channelParentID,
|
||||
anyID invokerID, const char *invokerName,
|
||||
const char *invokerUniqueIdentifier) override {
|
||||
}
|
||||
|
||||
void onDelChannelEvent(uint64 serverConnectionHandlerID, uint64 channelID, anyID invokerID, const char *invokerName,
|
||||
const char *invokerUniqueIdentifier) override {
|
||||
}
|
||||
|
||||
void onChannelMoveEvent(uint64 serverConnectionHandlerID, uint64 channelID, uint64 newChannelParentID,
|
||||
anyID invokerID, const char *invokerName, const char *invokerUniqueIdentifier) override {
|
||||
}
|
||||
|
||||
void onUpdateChannelEvent(uint64 serverConnectionHandlerID, uint64 channelID) override {
|
||||
}
|
||||
|
||||
void onUpdateChannelEditedEvent(uint64 serverConnectionHandlerID, uint64 channelID, anyID invokerID,
|
||||
const char *invokerName, const char *invokerUniqueIdentifier) override {
|
||||
}
|
||||
|
||||
void onUpdateClientEvent(uint64 serverConnectionHandlerID, anyID clientID, anyID invokerID, const char *invokerName,
|
||||
const char *invokerUniqueIdentifier) override {
|
||||
}
|
||||
|
||||
void onClientMoveEvent(uint64 serverConnectionHandlerID, anyID clientID, uint64 oldChannelID, uint64 newChannelID,
|
||||
int visibility, const char *moveMessage) override;
|
||||
|
||||
void onClientMoveSubscriptionEvent(uint64 serverConnectionHandlerID, anyID clientID, uint64 oldChannelID,
|
||||
uint64 newChannelID, int visibility) override {
|
||||
}
|
||||
|
||||
void onClientMoveTimeoutEvent(uint64 serverConnectionHandlerID, anyID clientID, uint64 oldChannelID,
|
||||
uint64 newChannelID, int visibility, const char *timeoutMessage) override {
|
||||
}
|
||||
|
||||
void onClientMoveMovedEvent(uint64 serverConnectionHandlerID, anyID clientID, uint64 oldChannelID,
|
||||
uint64 newChannelID, int visibility, anyID moverID, const char *moverName,
|
||||
const char *moverUniqueIdentifier,
|
||||
const char *moveMessage) override {
|
||||
}
|
||||
|
||||
void onClientKickFromChannelEvent(uint64 serverConnectionHandlerID, anyID clientID, uint64 oldChannelID,
|
||||
uint64 newChannelID, int visibility, anyID kickerID, const char *kickerName,
|
||||
const char *kickerUniqueIdentifier,
|
||||
const char *kickMessage) override {
|
||||
}
|
||||
|
||||
void onClientKickFromServerEvent(uint64 serverConnectionHandlerID, anyID clientID, uint64 oldChannelID,
|
||||
uint64 newChannelID, int visibility, anyID kickerID, const char *kickerName,
|
||||
const char *kickerUniqueIdentifier,
|
||||
const char *kickMessage) override {
|
||||
}
|
||||
|
||||
void onClientIDsEvent(uint64 serverConnectionHandlerID, const char *uniqueClientIdentifier, anyID clientID,
|
||||
const char *clientName) override {
|
||||
}
|
||||
|
||||
void onClientIDsFinishedEvent(uint64 serverConnectionHandlerID) override {
|
||||
}
|
||||
|
||||
void onServerEditedEvent(uint64 serverConnectionHandlerID, anyID editerID, const char *editerName,
|
||||
const char *editerUniqueIdentifier) override {
|
||||
}
|
||||
|
||||
void onServerUpdatedEvent(uint64 serverConnectionHandlerID) override {
|
||||
}
|
||||
|
||||
int onServerErrorEvent(uint64 serverConnectionHandlerID, const char *errorMessage, unsigned error,
|
||||
const char *returnCode, const char *extraMessage) override {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void onServerStopEvent(uint64 serverConnectionHandlerID, const char *shutdownMessage) override {
|
||||
}
|
||||
|
||||
int onTextMessageEvent(uint64 serverConnectionHandlerID, anyID targetMode, anyID toID, anyID fromID,
|
||||
const char *fromName, const char *fromUniqueIdentifier, const char *message,
|
||||
int ffIgnored) override;
|
||||
|
||||
void onTalkStatusChangeEvent(uint64 serverConnectionHandlerID, int status, int isReceivedWhisper,
|
||||
anyID clientID) override {
|
||||
}
|
||||
|
||||
void onConnectionInfoEvent(uint64 serverConnectionHandlerID, anyID clientID) override {
|
||||
}
|
||||
|
||||
void onServerConnectionInfoEvent(uint64 serverConnectionHandlerID) override {
|
||||
}
|
||||
|
||||
void onChannelSubscribeEvent(uint64 serverConnectionHandlerID, uint64 channelID) override {
|
||||
}
|
||||
|
||||
void onChannelSubscribeFinishedEvent(uint64 serverConnectionHandlerID) override {
|
||||
}
|
||||
|
||||
void onChannelUnsubscribeEvent(uint64 serverConnectionHandlerID, uint64 channelID) override {
|
||||
}
|
||||
|
||||
void onChannelUnsubscribeFinishedEvent(uint64 serverConnectionHandlerID) override {
|
||||
}
|
||||
|
||||
void onChannelDescriptionUpdateEvent(uint64 serverConnectionHandlerID, uint64 channelID) override {
|
||||
}
|
||||
|
||||
void onChannelPasswordChangedEvent(uint64 serverConnectionHandlerID, uint64 channelID) override {
|
||||
}
|
||||
|
||||
void onPlaybackShutdownCompleteEvent(uint64 serverConnectionHandlerID) override {
|
||||
}
|
||||
|
||||
void onSoundDeviceListChangedEvent(const char *modeID, int playOrCap) override {
|
||||
}
|
||||
|
||||
void onEditPlaybackVoiceDataEvent(uint64 serverConnectionHandlerID, anyID clientID, short *samples, int sampleCount,
|
||||
int channels) override {
|
||||
}
|
||||
|
||||
void onEditPostProcessVoiceDataEvent(uint64 serverConnectionHandlerID, anyID clientID, short *samples,
|
||||
int sampleCount, int channels, const unsigned *channelSpeakerArray,
|
||||
unsigned *channelFillMask) override {
|
||||
}
|
||||
|
||||
void onEditMixedPlaybackVoiceDataEvent(uint64 serverConnectionHandlerID, short *samples, int sampleCount,
|
||||
int channels, const unsigned *channelSpeakerArray,
|
||||
unsigned *channelFillMask) override {
|
||||
}
|
||||
|
||||
void onEditCapturedVoiceDataEvent(uint64 serverConnectionHandlerID, short *samples, int sampleCount, int channels,
|
||||
int *edited) override {
|
||||
}
|
||||
|
||||
void onCustom3dRolloffCalculationClientEvent(uint64 serverConnectionHandlerID, anyID clientID, float distance,
|
||||
float *volume) override {
|
||||
}
|
||||
|
||||
void onCustom3dRolloffCalculationWaveEvent(uint64 serverConnectionHandlerID, uint64 waveHandle, float distance,
|
||||
float *volume) override {
|
||||
}
|
||||
|
||||
void onUserLoggingMessageEvent(const char *logMessage, int logLevel, const char *logChannel, uint64 logID,
|
||||
const char *logTime, const char *completeLogString) override {
|
||||
}
|
||||
|
||||
void onClientBanFromServerEvent(uint64 serverConnectionHandlerID, anyID clientID, uint64 oldChannelID,
|
||||
uint64 newChannelID, int visibility, anyID kickerID, const char *kickerName,
|
||||
const char *kickerUniqueIdentifier,
|
||||
uint64 time, const char *kickMessage) override {
|
||||
}
|
||||
|
||||
int onClientPokeEvent(uint64 serverConnectionHandlerID, anyID fromClientID, const char *pokerName,
|
||||
const char *pokerUniqueIdentity, const char *message, int ffIgnored) override {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void onClientSelfVariableUpdateEvent(uint64 serverConnectionHandlerID, int flag, const char *oldValue,
|
||||
const char *newValue) override {
|
||||
}
|
||||
|
||||
void onFileListEvent(uint64 serverConnectionHandlerID, uint64 channelID, const char *path, const char *name,
|
||||
uint64 size, uint64 datetime, int type, uint64 incompletesize, const char *returnCode) override {
|
||||
}
|
||||
|
||||
void onFileListFinishedEvent(uint64 serverConnectionHandlerID, uint64 channelID, const char *path) override {
|
||||
}
|
||||
|
||||
void onFileInfoEvent(uint64 serverConnectionHandlerID, uint64 channelID, const char *name, uint64 size,
|
||||
uint64 datetime) override {
|
||||
}
|
||||
|
||||
void onServerGroupListEvent(uint64 serverConnectionHandlerID, uint64 serverGroupID, const char *name, int type,
|
||||
int iconID, int saveDB) override {
|
||||
}
|
||||
|
||||
void onServerGroupListFinishedEvent(uint64 serverConnectionHandlerID) override {
|
||||
}
|
||||
|
||||
void onServerGroupByClientIDEvent(uint64 serverConnectionHandlerID, const char *name, uint64 serverGroupList,
|
||||
uint64 clientDatabaseID) override {
|
||||
}
|
||||
|
||||
void onServerGroupPermListEvent(uint64 serverConnectionHandlerID, uint64 serverGroupID, unsigned permissionID,
|
||||
int permissionValue, int permissionNegated, int permissionSkip) override {
|
||||
}
|
||||
|
||||
void onServerGroupPermListFinishedEvent(uint64 serverConnectionHandlerID, uint64 serverGroupID) override {
|
||||
}
|
||||
|
||||
void onServerGroupClientListEvent(uint64 serverConnectionHandlerID, uint64 serverGroupID, uint64 clientDatabaseID,
|
||||
const char *clientNameIdentifier, const char *clientUniqueID) override {
|
||||
}
|
||||
|
||||
void onChannelGroupListEvent(uint64 serverConnectionHandlerID, uint64 channelGroupID, const char *name, int type,
|
||||
int iconID, int saveDB) override {
|
||||
}
|
||||
|
||||
void onChannelGroupListFinishedEvent(uint64 serverConnectionHandlerID) override {
|
||||
}
|
||||
|
||||
void onChannelGroupPermListEvent(uint64 serverConnectionHandlerID, uint64 channelGroupID, unsigned permissionID,
|
||||
int permissionValue, int permissionNegated, int permissionSkip) override {
|
||||
}
|
||||
|
||||
void onChannelGroupPermListFinishedEvent(uint64 serverConnectionHandlerID, uint64 channelGroupID) override {
|
||||
}
|
||||
|
||||
void onChannelPermListEvent(uint64 serverConnectionHandlerID, uint64 channelID, unsigned permissionID,
|
||||
int permissionValue, int permissionNegated, int permissionSkip) override {
|
||||
}
|
||||
|
||||
void onChannelPermListFinishedEvent(uint64 serverConnectionHandlerID, uint64 channelID) override {
|
||||
}
|
||||
|
||||
void onClientPermListEvent(uint64 serverConnectionHandlerID, uint64 clientDatabaseID, unsigned permissionID,
|
||||
int permissionValue, int permissionNegated, int permissionSkip) override {
|
||||
}
|
||||
|
||||
void onClientPermListFinishedEvent(uint64 serverConnectionHandlerID, uint64 clientDatabaseID) override {
|
||||
}
|
||||
|
||||
void onChannelClientPermListEvent(uint64 serverConnectionHandlerID, uint64 channelID, uint64 clientDatabaseID,
|
||||
unsigned permissionID, int permissionValue, int permissionNegated,
|
||||
int permissionSkip) override {
|
||||
}
|
||||
|
||||
void onChannelClientPermListFinishedEvent(uint64 serverConnectionHandlerID, uint64 channelID,
|
||||
uint64 clientDatabaseID) override {
|
||||
}
|
||||
|
||||
void onClientChannelGroupChangedEvent(uint64 serverConnectionHandlerID, uint64 channelGroupID, uint64 channelID,
|
||||
anyID clientID, anyID invokerClientID, const char *invokerName,
|
||||
const char *invokerUniqueIdentity) override {
|
||||
}
|
||||
|
||||
int onServerPermissionErrorEvent(uint64 serverConnectionHandlerID, const char *errorMessage, unsigned error,
|
||||
const char *returnCode, unsigned failedPermissionID) override {
|
||||
}
|
||||
|
||||
void onPermissionListGroupEndIDEvent(uint64 serverConnectionHandlerID, unsigned groupEndID) override {
|
||||
}
|
||||
|
||||
void onPermissionListEvent(uint64 serverConnectionHandlerID, unsigned permissionID, const char *permissionName,
|
||||
const char *permissionDescription) override {
|
||||
}
|
||||
|
||||
void onPermissionListFinishedEvent(uint64 serverConnectionHandlerID) override {
|
||||
}
|
||||
|
||||
void onPermissionOverviewEvent(uint64 serverConnectionHandlerID, uint64 clientDatabaseID, uint64 channelID,
|
||||
int overviewType, uint64 overviewID1, uint64 overviewID2, unsigned permissionID,
|
||||
int permissionValue,
|
||||
int permissionNegated, int permissionSkip) override {
|
||||
}
|
||||
|
||||
void onPermissionOverviewFinishedEvent(uint64 serverConnectionHandlerID) override {
|
||||
}
|
||||
|
||||
void onServerGroupClientAddedEvent(uint64 serverConnectionHandlerID, anyID clientID, const char *clientName,
|
||||
const char *clientUniqueIdentity, uint64 serverGroupID, anyID invokerClientID,
|
||||
const char *invokerName,
|
||||
const char *invokerUniqueIdentity) override {
|
||||
}
|
||||
|
||||
void onServerGroupClientDeletedEvent(uint64 serverConnectionHandlerID, anyID clientID, const char *clientName,
|
||||
const char *clientUniqueIdentity, uint64 serverGroupID, anyID invokerClientID,
|
||||
const char *invokerName,
|
||||
const char *invokerUniqueIdentity) override {
|
||||
}
|
||||
|
||||
void onClientNeededPermissionsEvent(uint64 serverConnectionHandlerID, unsigned permissionID,
|
||||
int permissionValue) override {
|
||||
}
|
||||
|
||||
void onClientNeededPermissionsFinishedEvent(uint64 serverConnectionHandlerID) override {
|
||||
}
|
||||
|
||||
void onFileTransferStatusEvent(anyID transferID, unsigned status, const char *statusMessage, uint64 remotefileSize,
|
||||
uint64 serverConnectionHandlerID) override {
|
||||
}
|
||||
|
||||
void onClientChatClosedEvent(uint64 serverConnectionHandlerID, anyID clientID,
|
||||
const char *clientUniqueIdentity) override {
|
||||
}
|
||||
|
||||
void onClientChatComposingEvent(uint64 serverConnectionHandlerID, anyID clientID,
|
||||
const char *clientUniqueIdentity) override {
|
||||
}
|
||||
|
||||
void onServerLogEvent(uint64 serverConnectionHandlerID, const char *logMsg) override {
|
||||
}
|
||||
|
||||
void onServerLogFinishedEvent(uint64 serverConnectionHandlerID, uint64 lastPos, uint64 fileSize) override {
|
||||
}
|
||||
|
||||
void onMessageListEvent(uint64 serverConnectionHandlerID, uint64 messageID, const char *fromClientUniqueIdentity,
|
||||
const char *subject, uint64 timestamp, int flagRead) override {
|
||||
}
|
||||
|
||||
void onMessageGetEvent(uint64 serverConnectionHandlerID, uint64 messageID, const char *fromClientUniqueIdentity,
|
||||
const char *subject, const char *message, uint64 timestamp) override {
|
||||
}
|
||||
|
||||
void onClientDBIDfromUIDEvent(uint64 serverConnectionHandlerID, const char *uniqueClientIdentifier,
|
||||
uint64 clientDatabaseID) override {
|
||||
}
|
||||
|
||||
void onClientNamefromUIDEvent(uint64 serverConnectionHandlerID, const char *uniqueClientIdentifier,
|
||||
uint64 clientDatabaseID, const char *clientNickName) override {
|
||||
}
|
||||
|
||||
void onClientNamefromDBIDEvent(uint64 serverConnectionHandlerID, const char *uniqueClientIdentifier,
|
||||
uint64 clientDatabaseID, const char *clientNickName) override {
|
||||
}
|
||||
|
||||
void onComplainListEvent(uint64 serverConnectionHandlerID, uint64 targetClientDatabaseID,
|
||||
const char *targetClientNickName, uint64 fromClientDatabaseID,
|
||||
const char *fromClientNickName,
|
||||
const char *complainReason, uint64 timestamp) override {
|
||||
}
|
||||
|
||||
void onBanListEvent(uint64 serverConnectionHandlerID, uint64 banid, const char *ip, const char *name, const char *uid,
|
||||
const char *mytsid, uint64 creationTime, uint64 durationTime, const char *invokerName,
|
||||
uint64 invokercldbid,
|
||||
const char *invokeruid, const char *reason, int numberOfEnforcements,
|
||||
const char *lastNickName) override {
|
||||
}
|
||||
|
||||
void onClientServerQueryLoginPasswordEvent(uint64 serverConnectionHandlerID, const char *loginPassword) override {
|
||||
}
|
||||
|
||||
void onPluginCommandEvent(uint64 serverConnectionHandlerID, const char *pluginName, const char *pluginCommand,
|
||||
anyID invokerClientID, const char *invokerName,
|
||||
const char *invokerUniqueIdentity) override {
|
||||
}
|
||||
|
||||
void onIncomingClientQueryEvent(uint64 serverConnectionHandlerID, const char *commandText) override {
|
||||
}
|
||||
|
||||
void onServerTemporaryPasswordListEvent(uint64 serverConnectionHandlerID, const char *clientNickname,
|
||||
const char *uniqueClientIdentifier, const char *description,
|
||||
const char *password, uint64 timestampStart,
|
||||
uint64 timestampEnd, uint64 targetChannelID,
|
||||
const char *targetChannelPW) override {
|
||||
}
|
||||
|
||||
void onAvatarUpdated(uint64 serverConnectionHandlerID, anyID clientID, const char *avatarPath) override {
|
||||
}
|
||||
|
||||
void onMenuItemEvent(uint64 serverConnectionHandlerID, PluginMenuType type, int menuItemID,
|
||||
uint64 selectedItemID) override {
|
||||
}
|
||||
|
||||
void onHotkeyEvent(const char *keyword) override {
|
||||
}
|
||||
|
||||
void onHotkeyRecordedEvent(const char *keyword, const char *key) override {
|
||||
}
|
||||
|
||||
void onClientDisplayNameChanged(uint64 serverConnectionHandlerID, anyID clientID, const char *displayName,
|
||||
const char *uniqueClientIdentifier) override {
|
||||
}
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
IEchoionPlugin *CreatePlugin(const TS3Functions* funcs) {
|
||||
return new EchoionCore(std::make_shared<TS3Functions>(*funcs));
|
||||
}
|
||||
|
||||
void DestroyPlugin(const IEchoionPlugin *plugin) { delete plugin; }
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
#pragma once
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <teamspeak/public_definitions.h>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <glaze/core/common.hpp>
|
||||
|
||||
namespace definitions {
|
||||
|
||||
|
||||
struct StreamInfo {
|
||||
std::string url;
|
||||
int itag = 0;
|
||||
std::string mimeType;
|
||||
int bitrate = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
};
|
||||
|
||||
struct Streams {
|
||||
StreamInfo audio;
|
||||
StreamInfo video;
|
||||
};
|
||||
|
||||
struct QueueItem {
|
||||
std::string name;
|
||||
std::string videoId;
|
||||
std::string requester;
|
||||
std::optional<Streams> streams;
|
||||
|
||||
QueueItem() = default;
|
||||
|
||||
QueueItem(std::string name, std::string videoId, std::string requested_by, const std::optional<Streams> & streams)
|
||||
: name{std::move(name)}, videoId(std::move(videoId)), requester{std::move(requested_by)}, streams{streams} {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct SearchResultItem {
|
||||
std::string name;
|
||||
std::string length;
|
||||
std::string thumbnail;
|
||||
std::string viewCount;
|
||||
std::string url;
|
||||
std::string videoId;
|
||||
};
|
||||
|
||||
struct PluginState {
|
||||
std::vector<QueueItem> queue;
|
||||
std::vector<anyID> onlineSubscribers;
|
||||
std::vector<anyID> offlineSubscribers;
|
||||
std::uint64_t serverConnection;
|
||||
bool wasPlaying = false;
|
||||
};
|
||||
}
|
||||
|
||||
template <> struct glz::meta<definitions::StreamInfo> {
|
||||
using T = definitions::StreamInfo;
|
||||
static constexpr auto value =
|
||||
object("url", &T::url, "itag", &T::itag, "mimeType", &T::mimeType,
|
||||
"bitrate", &T::bitrate, "width", &T::width, "height", &T::height);
|
||||
};
|
||||
|
||||
template <> struct glz::meta<definitions::Streams> {
|
||||
using T = definitions::Streams;
|
||||
static constexpr auto value =
|
||||
object("audio", &T::audio, "video", &T::video);
|
||||
};
|
||||
|
||||
template <> struct glz::meta<definitions::QueueItem> {
|
||||
using T = definitions::QueueItem;
|
||||
static constexpr auto value =
|
||||
object("name", &T::name, "videoId", &T::videoId, "requester", &T::requester,
|
||||
"streams", &T::streams);
|
||||
};
|
||||
@@ -0,0 +1,332 @@
|
||||
#pragma once
|
||||
#include "Spotify/RequestParams.hpp"
|
||||
#include "Spotify/Types/Album.hpp"
|
||||
#include "Spotify/Types/Artist.hpp"
|
||||
#include "Spotify/Types/Common.hpp"
|
||||
#include "Spotify/Types/Other.hpp"
|
||||
#include "Spotify/Types/Player.hpp"
|
||||
#include "Spotify/Types/Playlist.hpp"
|
||||
#include "Spotify/Types/Track.hpp"
|
||||
#include "Spotify/Types/User.hpp"
|
||||
#include "ts6bot/Proxy.hpp"
|
||||
#include <curl/curl.h>
|
||||
#include <expected>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace Spotify {
|
||||
|
||||
// ============================================================================
|
||||
// Error Handling
|
||||
// ============================================================================
|
||||
|
||||
struct ApiError {
|
||||
int status;
|
||||
std::string message;
|
||||
std::string reason;
|
||||
|
||||
auto GetStatus() const -> int { return status; }
|
||||
auto GetMessage() const -> const std::string & { return message; }
|
||||
};
|
||||
|
||||
template <typename T> using Result = std::expected<T, ApiError>;
|
||||
|
||||
// ============================================================================
|
||||
// HTTP Client Implementation Details
|
||||
// ============================================================================
|
||||
|
||||
struct CurlDeleter {
|
||||
void operator()(CURL *ptr) const {
|
||||
if (ptr)
|
||||
curl_easy_cleanup(ptr);
|
||||
}
|
||||
};
|
||||
|
||||
enum class HttpMethod { GET, POST, PUT, DELETE };
|
||||
|
||||
// ============================================================================
|
||||
// Main Spotify Client
|
||||
// ============================================================================
|
||||
|
||||
class Client {
|
||||
public:
|
||||
Client(std::string accessToken);
|
||||
~Client() = default;
|
||||
|
||||
// Configuration
|
||||
void SetVerbose(bool verbose) { m_Verbose = verbose; }
|
||||
void SetProxy(ProxyConfig config) { m_Proxy = std::move(config); }
|
||||
void SetAccessToken(std::string token) { m_AccessToken = std::move(token); }
|
||||
|
||||
// ========================================================================
|
||||
// Albums API
|
||||
// ========================================================================
|
||||
|
||||
auto GetAlbum(const std::string &id, std::optional<std::string> market = {})
|
||||
-> Result<Album>;
|
||||
|
||||
auto GetAlbums(const std::vector<std::string> &ids,
|
||||
std::optional<std::string> market = {})
|
||||
-> Result<std::vector<Album>>;
|
||||
|
||||
auto GetAlbumTracks(const std::string &id,
|
||||
const Request::AlbumTracksParams ¶ms = {})
|
||||
-> Result<PagingObject<SimplifiedTrack>>;
|
||||
|
||||
auto GetSavedAlbums(const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<SavedAlbum>>;
|
||||
|
||||
auto SaveAlbums(const std::vector<std::string> &ids) -> Result<void>;
|
||||
|
||||
auto RemoveSavedAlbums(const std::vector<std::string> &ids) -> Result<void>;
|
||||
|
||||
auto CheckSavedAlbums(const std::vector<std::string> &ids)
|
||||
-> Result<std::vector<bool>>;
|
||||
|
||||
auto GetNewReleases(const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<SimplifiedAlbum>>;
|
||||
|
||||
// ========================================================================
|
||||
// Artists API
|
||||
// ========================================================================
|
||||
|
||||
auto GetArtist(const std::string &id) -> Result<Artist>;
|
||||
|
||||
auto GetArtists(const std::vector<std::string> &ids)
|
||||
-> Result<std::vector<Artist>>;
|
||||
|
||||
auto GetArtistAlbums(const std::string &id,
|
||||
const Request::ArtistAlbumsParams ¶ms = {})
|
||||
-> Result<PagingObject<SimplifiedAlbum>>;
|
||||
|
||||
auto GetArtistTopTracks(const std::string &id, const std::string &market)
|
||||
-> Result<std::vector<Track>>;
|
||||
|
||||
auto GetArtistRelatedArtists(const std::string &id)
|
||||
-> Result<std::vector<Artist>>;
|
||||
|
||||
// ========================================================================
|
||||
// Tracks API
|
||||
// ========================================================================
|
||||
|
||||
auto GetTrack(const std::string &id, std::optional<std::string> market = {})
|
||||
-> Result<Track>;
|
||||
|
||||
auto GetTracks(const std::vector<std::string> &ids,
|
||||
std::optional<std::string> market = {})
|
||||
-> Result<std::vector<Track>>;
|
||||
|
||||
auto GetSavedTracks(const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<SavedTrack>>;
|
||||
|
||||
auto SaveTracks(const std::vector<std::string> &ids) -> Result<void>;
|
||||
|
||||
auto RemoveSavedTracks(const std::vector<std::string> &ids) -> Result<void>;
|
||||
|
||||
auto CheckSavedTracks(const std::vector<std::string> &ids)
|
||||
-> Result<std::vector<bool>>;
|
||||
|
||||
auto GetAudioFeatures(const std::string &id) -> Result<AudioFeatures>;
|
||||
|
||||
auto GetAudioFeaturesForTracks(const std::vector<std::string> &ids)
|
||||
-> Result<std::vector<AudioFeatures>>;
|
||||
|
||||
auto GetAudioAnalysis(const std::string &id) -> Result<AudioAnalysis>;
|
||||
|
||||
auto GetRecommendations(const Request::RecommendationParams ¶ms)
|
||||
-> Result<Recommendations>;
|
||||
|
||||
// ========================================================================
|
||||
// Search API
|
||||
// ========================================================================
|
||||
|
||||
auto Search(const Request::SearchParams ¶ms) -> Result<SearchResults>;
|
||||
|
||||
auto SearchTracks(const Request::TrackSearchFilters &filters,
|
||||
const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<Track>>;
|
||||
|
||||
auto SearchAlbums(const Request::AlbumSearchFilters &filters,
|
||||
const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<SimplifiedAlbum>>;
|
||||
|
||||
auto SearchArtists(const Request::ArtistSearchFilters &filters,
|
||||
const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<Artist>>;
|
||||
|
||||
// ========================================================================
|
||||
// Playlists API
|
||||
// ========================================================================
|
||||
|
||||
auto GetPlaylist(const std::string &id,
|
||||
std::optional<std::string> market = {}) -> Result<Playlist>;
|
||||
|
||||
auto GetPlaylistTracks(const std::string &id,
|
||||
const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<PlaylistTrack>>;
|
||||
|
||||
auto CreatePlaylist(const std::string &user_id,
|
||||
const Request::CreatePlaylistParams ¶ms)
|
||||
-> Result<Playlist>;
|
||||
|
||||
auto UpdatePlaylist(const std::string &id,
|
||||
const Request::UpdatePlaylistParams ¶ms)
|
||||
-> Result<void>;
|
||||
|
||||
auto AddTracksToPlaylist(const std::string &id,
|
||||
const Request::AddTracksToPlaylistParams ¶ms)
|
||||
-> Result<std::string>;
|
||||
|
||||
auto RemoveTracksFromPlaylist(
|
||||
const std::string &id,
|
||||
const Request::RemoveTracksFromPlaylistParams ¶ms)
|
||||
-> Result<std::string>;
|
||||
|
||||
auto ReorderPlaylistTracks(const std::string &id,
|
||||
const Request::ReorderPlaylistParams ¶ms)
|
||||
-> Result<std::string>;
|
||||
|
||||
auto ReplacePlaylistTracks(const std::string &id,
|
||||
const Request::ReplacePlaylistTracksParams ¶ms)
|
||||
-> Result<void>;
|
||||
|
||||
auto GetCurrentUserPlaylists(const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<SimplifiedPlaylist>>;
|
||||
|
||||
auto GetUserPlaylists(const std::string &user_id,
|
||||
const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<SimplifiedPlaylist>>;
|
||||
|
||||
auto GetFeaturedPlaylists(const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<SimplifiedPlaylist>>;
|
||||
|
||||
auto GetCategoryPlaylists(const std::string &category_id,
|
||||
const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<SimplifiedPlaylist>>;
|
||||
|
||||
// ========================================================================
|
||||
// User API
|
||||
// ========================================================================
|
||||
|
||||
auto GetCurrentUser() -> Result<User>;
|
||||
|
||||
auto GetUser(const std::string &user_id) -> Result<User>;
|
||||
|
||||
auto GetTopArtists(const Request::TopItemsParams ¶ms = {})
|
||||
-> Result<PagingObject<Artist>>;
|
||||
|
||||
auto GetTopTracks(const Request::TopItemsParams ¶ms = {})
|
||||
-> Result<PagingObject<Track>>;
|
||||
|
||||
// ========================================================================
|
||||
// Follow API
|
||||
// ========================================================================
|
||||
|
||||
auto FollowArtistsOrUsers(const Request::FollowParams ¶ms)
|
||||
-> Result<void>;
|
||||
|
||||
auto UnfollowArtistsOrUsers(const Request::UnfollowParams ¶ms)
|
||||
-> Result<void>;
|
||||
|
||||
auto CheckFollowingArtistsOrUsers(const Request::CheckFollowingParams ¶ms)
|
||||
-> Result<std::vector<bool>>;
|
||||
|
||||
auto GetFollowedArtists(std::optional<int> limit = {},
|
||||
std::optional<std::string> after = {})
|
||||
-> Result<CursorPagingObject<Artist>>;
|
||||
|
||||
auto FollowPlaylist(const std::string &playlist_id,
|
||||
const Request::FollowPlaylistParams ¶ms = {})
|
||||
-> Result<void>;
|
||||
|
||||
auto UnfollowPlaylist(const std::string &playlist_id) -> Result<void>;
|
||||
|
||||
auto CheckFollowingPlaylist(const std::string &playlist_id,
|
||||
const std::vector<std::string> &user_ids)
|
||||
-> Result<std::vector<bool>>;
|
||||
|
||||
// ========================================================================
|
||||
// Player API
|
||||
// ========================================================================
|
||||
|
||||
auto GetPlaybackState(std::optional<std::string> market = {})
|
||||
-> Result<PlaybackState>;
|
||||
|
||||
auto GetAvailableDevices() -> Result<std::vector<Device>>;
|
||||
|
||||
auto GetCurrentlyPlayingTrack(std::optional<std::string> market = {})
|
||||
-> Result<PlaybackState>;
|
||||
|
||||
auto StartOrResumePlayback(const Request::PlayParams ¶ms,
|
||||
std::optional<std::string> device_id = {})
|
||||
-> Result<void>;
|
||||
|
||||
auto PausePlayback(std::optional<std::string> device_id = {}) -> Result<void>;
|
||||
|
||||
auto SkipToNext(std::optional<std::string> device_id = {}) -> Result<void>;
|
||||
|
||||
auto SkipToPrevious(std::optional<std::string> device_id = {})
|
||||
-> Result<void>;
|
||||
|
||||
auto SeekToPosition(int position_ms,
|
||||
std::optional<std::string> device_id = {})
|
||||
-> Result<void>;
|
||||
|
||||
auto SetRepeatMode(RepeatMode mode, std::optional<std::string> device_id = {})
|
||||
-> Result<void>;
|
||||
|
||||
auto SetPlaybackVolume(int volume_percent,
|
||||
std::optional<std::string> device_id = {})
|
||||
-> Result<void>;
|
||||
|
||||
auto TogglePlaybackShuffle(bool state,
|
||||
std::optional<std::string> device_id = {})
|
||||
-> Result<void>;
|
||||
|
||||
auto TransferPlayback(const Request::TransferPlaybackParams ¶ms)
|
||||
-> Result<void>;
|
||||
|
||||
auto AddToQueue(const Request::QueueParams ¶ms) -> Result<void>;
|
||||
|
||||
auto GetRecentlyPlayedTracks(std::optional<int> limit = {},
|
||||
std::optional<int64_t> after = {},
|
||||
std::optional<int64_t> before = {})
|
||||
-> Result<CursorPagingObject<PlaylistTrack>>;
|
||||
|
||||
// ========================================================================
|
||||
// Browse API
|
||||
// ========================================================================
|
||||
|
||||
auto GetCategories(const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<Category>>;
|
||||
|
||||
auto GetCategory(const std::string &category_id,
|
||||
std::optional<std::string> locale = {}) -> Result<Category>;
|
||||
|
||||
auto GetAvailableGenreSeeds() -> Result<std::vector<std::string>>;
|
||||
|
||||
auto GetAvailableMarkets() -> Result<std::vector<std::string>>;
|
||||
|
||||
private:
|
||||
std::string m_AccessToken;
|
||||
ProxyConfig m_Proxy;
|
||||
bool m_Verbose = false;
|
||||
|
||||
auto PerformRequest(const std::string &url,
|
||||
HttpMethod method = HttpMethod::GET,
|
||||
const std::string &body = "",
|
||||
const std::vector<std::string> &extra_headers = {})
|
||||
-> Result<std::string>;
|
||||
|
||||
static auto WriteCallback(void *contents, size_t size, size_t nmemb,
|
||||
std::string *out) -> size_t;
|
||||
|
||||
auto BuildUrl(const std::string &endpoint,
|
||||
const std::map<std::string, std::string> ¶ms = {}) const
|
||||
-> std::string;
|
||||
auto BuildUrl(const std::string &endpoint,
|
||||
const Request::RequestParams ¶ms) const -> std::string;
|
||||
auto UrlEncode(const std::string &value) const -> std::string;
|
||||
};
|
||||
|
||||
} // namespace Spotify
|
||||
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace Spotify {
|
||||
|
||||
struct CallbackResult {
|
||||
std::string code;
|
||||
std::string state;
|
||||
std::string error;
|
||||
};
|
||||
|
||||
class HttpCallbackServer {
|
||||
public:
|
||||
HttpCallbackServer(std::string host, uint16_t port, std::string path);
|
||||
|
||||
// Wait for one callback request or timeout. Returns std::nullopt on timeout.
|
||||
std::optional<CallbackResult> WaitForCallback(std::chrono::milliseconds timeout);
|
||||
|
||||
private:
|
||||
std::string m_Host;
|
||||
uint16_t m_Port;
|
||||
std::string m_Path;
|
||||
};
|
||||
|
||||
} // namespace ts6bot
|
||||
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <Spotify/Client.hpp> // for ProxyConfig + CurlDeleter + ProxyType
|
||||
|
||||
namespace Spotify {
|
||||
|
||||
struct TokenSet {
|
||||
std::string access_token;
|
||||
std::string token_type;
|
||||
std::string scope;
|
||||
std::string refresh_token;
|
||||
std::int64_t expires_at_utc{}; // unix seconds
|
||||
|
||||
bool IsExpired(std::chrono::seconds skew = std::chrono::seconds{60}) const;
|
||||
};
|
||||
|
||||
class PkceAuth {
|
||||
public:
|
||||
PkceAuth(std::string clientId, std::string redirectUri, std::filesystem::path tokenCachePath);
|
||||
|
||||
void SetProxy(ProxyConfig p) { m_Proxy = std::move(p); }
|
||||
void SetVerbose(bool v) { m_Verbose = v; }
|
||||
|
||||
// One-time interactive step: prints URL and waits for redirect; stores refresh token.
|
||||
void AuthorizeAndStore(const std::vector<std::string>& scopes,
|
||||
std::chrono::milliseconds timeout = std::chrono::minutes(5));
|
||||
|
||||
// Headless: load from cache and refresh if needed.
|
||||
TokenSet LoadOrRefresh();
|
||||
|
||||
private:
|
||||
std::string m_ClientId;
|
||||
std::string m_RedirectUri;
|
||||
std::filesystem::path m_TokenCachePath;
|
||||
ProxyConfig m_Proxy;
|
||||
bool m_Verbose = false;
|
||||
|
||||
TokenSet ExchangeCodeForToken(const std::string& code, const std::string& codeVerifier);
|
||||
TokenSet RefreshAccessToken(const TokenSet& current);
|
||||
|
||||
void Save(const TokenSet& t) const;
|
||||
std::optional<TokenSet> Load() const;
|
||||
|
||||
static std::int64_t NowUnixSeconds();
|
||||
friend TokenSet;
|
||||
};
|
||||
|
||||
} // namespace ts6bot
|
||||
@@ -0,0 +1,496 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
#include <map>
|
||||
#include <format>
|
||||
#include <ranges>
|
||||
#include <algorithm>
|
||||
|
||||
namespace Spotify::Request {
|
||||
|
||||
// ============================================================================
|
||||
// Base Request Parameter Class
|
||||
// ============================================================================
|
||||
|
||||
class RequestParams {
|
||||
public:
|
||||
virtual ~RequestParams() = default;
|
||||
virtual auto ToQueryParams() const -> std::map<std::string, std::string> = 0;
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Search Type Enum
|
||||
// ============================================================================
|
||||
|
||||
enum class SearchType {
|
||||
Album,
|
||||
Artist,
|
||||
Playlist,
|
||||
Track,
|
||||
Show,
|
||||
Episode,
|
||||
Audiobook
|
||||
};
|
||||
|
||||
inline auto SearchTypeToString(SearchType type) -> std::string {
|
||||
switch (type) {
|
||||
case SearchType::Album: return "album";
|
||||
case SearchType::Artist: return "artist";
|
||||
case SearchType::Playlist: return "playlist";
|
||||
case SearchType::Track: return "track";
|
||||
case SearchType::Show: return "show";
|
||||
case SearchType::Episode: return "episode";
|
||||
case SearchType::Audiobook: return "audiobook";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Time Range Enum
|
||||
// ============================================================================
|
||||
|
||||
enum class TimeRange {
|
||||
LongTerm,
|
||||
MediumTerm,
|
||||
ShortTerm
|
||||
};
|
||||
|
||||
inline auto TimeRangeToString(TimeRange range) -> std::string {
|
||||
switch (range) {
|
||||
case TimeRange::LongTerm: return "long_term";
|
||||
case TimeRange::MediumTerm: return "medium_term";
|
||||
case TimeRange::ShortTerm: return "short_term";
|
||||
}
|
||||
return "medium_term";
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Pagination Parameters
|
||||
// ============================================================================
|
||||
|
||||
struct PaginationParams : public RequestParams {
|
||||
public:
|
||||
std::optional<int> limit = 20;
|
||||
std::optional<int> offset = 0;
|
||||
std::optional<std::string> market;
|
||||
|
||||
auto ToQueryParams() const -> std::map<std::string, std::string> override {
|
||||
std::map<std::string, std::string> params;
|
||||
if (limit) params["limit"] = std::to_string(*limit);
|
||||
if (offset) params["offset"] = std::to_string(*offset);
|
||||
if (market) params["market"] = *market;
|
||||
return params;
|
||||
}
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Search Parameters
|
||||
// ============================================================================
|
||||
|
||||
struct SearchParams : public RequestParams {
|
||||
public:
|
||||
//You can narrow down your search using field filters. The available filters are album, artist, track, year, upc, tag:hipster, tag:new, isrc, and genre. Each field filter only applies to certain result types.
|
||||
//The artist and year filters can be used while searching albums, artists and tracks. You can filter on a single year or a range (e.g. 1955-1960).
|
||||
//The album filter can be used while searching albums and tracks.
|
||||
//The genre filter can be used while searching artists and tracks.
|
||||
//The isrc and track filters can be used while searching tracks.
|
||||
//The upc, tag:new and tag:hipster filters can only be used while searching albums. The tag:new filter will return albums released in the past two weeks and tag:hipster can be used to return only albums with the lowest 10% popularity.
|
||||
//Example: q=remaster%2520track%3ADoxy%2520artist%3AMiles%2520Davis
|
||||
std::string query;
|
||||
std::vector<SearchType> types;
|
||||
std::optional<std::string> market;
|
||||
std::optional<int> limit = 20;
|
||||
std::optional<int> offset = 0;
|
||||
std::optional<bool> include_external;
|
||||
|
||||
auto ToQueryParams() const -> std::map<std::string, std::string> override {
|
||||
std::map<std::string, std::string> params;
|
||||
params["q"] = query;
|
||||
|
||||
std::vector<std::string> type_strings;
|
||||
for (const auto& type : types) {
|
||||
type_strings.push_back(SearchTypeToString(type));
|
||||
}
|
||||
params["type"] = std::views::join_with(type_strings, ',') | std::ranges::to<std::string>();
|
||||
|
||||
if (market) params["market"] = *market;
|
||||
if (limit) params["limit"] = std::to_string(*limit);
|
||||
if (offset) params["offset"] = std::to_string(*offset);
|
||||
if (include_external) params["include_external"] = *include_external ? "audio" : "";
|
||||
|
||||
return params;
|
||||
}
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Track Search Filters
|
||||
// ============================================================================
|
||||
|
||||
struct TrackSearchFilters : public RequestParams {
|
||||
public:
|
||||
std::optional<std::string> track;
|
||||
std::optional<std::string> artist;
|
||||
std::optional<std::string> album;
|
||||
std::optional<int> year;
|
||||
std::optional<std::string> genre;
|
||||
std::optional<std::string> isrc;
|
||||
std::optional<std::string> upc;
|
||||
std::optional<bool> is_new;
|
||||
std::optional<bool> hipster;
|
||||
|
||||
auto ToQueryString() const -> std::string {
|
||||
std::vector<std::string> parts;
|
||||
|
||||
if (track) parts.push_back(std::format("track:{}", *track));
|
||||
if (artist) parts.push_back(std::format("artist:{}", *artist));
|
||||
if (album) parts.push_back(std::format("album:{}", *album));
|
||||
if (year) parts.push_back(std::format("year:{}", *year));
|
||||
if (genre) parts.push_back(std::format("genre:{}", *genre));
|
||||
if (isrc) parts.push_back(std::format("isrc:{}", *isrc));
|
||||
if (upc) parts.push_back(std::format("upc:{}", *upc));
|
||||
if (is_new && *is_new) parts.push_back("tag:new");
|
||||
if (hipster && *hipster) parts.push_back("tag:hipster");
|
||||
|
||||
return std::views::join_with(parts, ' ') | std::ranges::to<std::string>();
|
||||
}
|
||||
|
||||
auto ToQueryParams() const -> std::map<std::string, std::string> override {
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Album Search Filters
|
||||
// ============================================================================
|
||||
|
||||
struct AlbumSearchFilters : public RequestParams {
|
||||
public:
|
||||
std::optional<std::string> album;
|
||||
std::optional<std::string> artist;
|
||||
std::optional<int> year;
|
||||
std::optional<std::string> genre;
|
||||
std::optional<std::string> upc;
|
||||
|
||||
auto ToQueryString() const -> std::string {
|
||||
std::vector<std::string> parts;
|
||||
|
||||
if (album) parts.push_back(std::format("album:{}", *album));
|
||||
if (artist) parts.push_back(std::format("artist:{}", *artist));
|
||||
if (year) parts.push_back(std::format("year:{}", *year));
|
||||
if (genre) parts.push_back(std::format("genre:{}", *genre));
|
||||
if (upc) parts.push_back(std::format("upc:{}", *upc));
|
||||
|
||||
return std::views::join_with(parts, ' ') | std::ranges::to<std::string>();
|
||||
}
|
||||
|
||||
auto ToQueryParams() const -> std::map<std::string, std::string> override {
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Artist Search Filters
|
||||
// ============================================================================
|
||||
|
||||
struct ArtistSearchFilters : public RequestParams {
|
||||
public:
|
||||
std::optional<std::string> artist;
|
||||
std::optional<std::string> genre;
|
||||
|
||||
auto ToQueryString() const -> std::string {
|
||||
std::vector<std::string> parts;
|
||||
|
||||
if (artist) parts.push_back(std::format("artist:{}", *artist));
|
||||
if (genre) parts.push_back(std::format("genre:{}", *genre));
|
||||
|
||||
return std::views::join_with(parts, ' ') | std::ranges::to<std::string>();
|
||||
}
|
||||
|
||||
auto ToQueryParams() const -> std::map<std::string, std::string> override {
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Album Tracks Parameters
|
||||
// ============================================================================
|
||||
|
||||
struct AlbumTracksParams : public RequestParams {
|
||||
public:
|
||||
std::optional<int> limit = 20;
|
||||
std::optional<int> offset = 0;
|
||||
std::optional<std::string> market;
|
||||
|
||||
auto ToQueryParams() const -> std::map<std::string, std::string> override {
|
||||
std::map<std::string, std::string> params;
|
||||
if (limit) params["limit"] = std::to_string(*limit);
|
||||
if (offset) params["offset"] = std::to_string(*offset);
|
||||
if (market) params["market"] = *market;
|
||||
return params;
|
||||
}
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Artist Albums Parameters
|
||||
// ============================================================================
|
||||
|
||||
struct ArtistAlbumsParams : public RequestParams {
|
||||
public:
|
||||
std::optional<std::vector<std::string>> include_groups;
|
||||
std::optional<std::string> market;
|
||||
std::optional<int> limit = 20;
|
||||
std::optional<int> offset = 0;
|
||||
|
||||
auto ToQueryParams() const -> std::map<std::string, std::string> override {
|
||||
std::map<std::string, std::string> params;
|
||||
|
||||
if (include_groups && !include_groups->empty()) {
|
||||
params["include_groups"] = std::views::join_with(*include_groups, ',') | std::ranges::to<std::string>();
|
||||
}
|
||||
if (market) params["market"] = *market;
|
||||
if (limit) params["limit"] = std::to_string(*limit);
|
||||
if (offset) params["offset"] = std::to_string(*offset);
|
||||
|
||||
return params;
|
||||
}
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Top Items Parameters
|
||||
// ============================================================================
|
||||
|
||||
struct TopItemsParams : public RequestParams {
|
||||
public:
|
||||
std::optional<TimeRange> time_range = TimeRange::MediumTerm;
|
||||
std::optional<int> limit = 20;
|
||||
std::optional<int> offset = 0;
|
||||
|
||||
auto ToQueryParams() const -> std::map<std::string, std::string> override {
|
||||
std::map<std::string, std::string> params;
|
||||
|
||||
if (time_range) params["time_range"] = TimeRangeToString(*time_range);
|
||||
if (limit) params["limit"] = std::to_string(*limit);
|
||||
if (offset) params["offset"] = std::to_string(*offset);
|
||||
|
||||
return params;
|
||||
}
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Recommendation Parameters
|
||||
// ============================================================================
|
||||
|
||||
struct RecommendationParams : public RequestParams {
|
||||
public:
|
||||
std::optional<std::vector<std::string>> seed_artists;
|
||||
std::optional<std::vector<std::string>> seed_genres;
|
||||
std::optional<std::vector<std::string>> seed_tracks;
|
||||
std::optional<int> limit = 20;
|
||||
std::optional<std::string> market;
|
||||
|
||||
// Tunable attributes
|
||||
std::optional<float> min_acousticness;
|
||||
std::optional<float> max_acousticness;
|
||||
std::optional<float> target_acousticness;
|
||||
|
||||
std::optional<float> min_danceability;
|
||||
std::optional<float> max_danceability;
|
||||
std::optional<float> target_danceability;
|
||||
|
||||
std::optional<int> min_duration_ms;
|
||||
std::optional<int> max_duration_ms;
|
||||
std::optional<int> target_duration_ms;
|
||||
|
||||
std::optional<float> min_energy;
|
||||
std::optional<float> max_energy;
|
||||
std::optional<float> target_energy;
|
||||
|
||||
std::optional<float> min_instrumentalness;
|
||||
std::optional<float> max_instrumentalness;
|
||||
std::optional<float> target_instrumentalness;
|
||||
|
||||
std::optional<int> min_key;
|
||||
std::optional<int> max_key;
|
||||
std::optional<int> target_key;
|
||||
|
||||
std::optional<float> min_liveness;
|
||||
std::optional<float> max_liveness;
|
||||
std::optional<float> target_liveness;
|
||||
|
||||
std::optional<float> min_loudness;
|
||||
std::optional<float> max_loudness;
|
||||
std::optional<float> target_loudness;
|
||||
|
||||
std::optional<int> min_mode;
|
||||
std::optional<int> max_mode;
|
||||
std::optional<int> target_mode;
|
||||
|
||||
std::optional<int> min_popularity;
|
||||
std::optional<int> max_popularity;
|
||||
std::optional<int> target_popularity;
|
||||
|
||||
std::optional<float> min_speechiness;
|
||||
std::optional<float> max_speechiness;
|
||||
std::optional<float> target_speechiness;
|
||||
|
||||
std::optional<float> min_tempo;
|
||||
std::optional<float> max_tempo;
|
||||
std::optional<float> target_tempo;
|
||||
|
||||
std::optional<int> min_time_signature;
|
||||
std::optional<int> max_time_signature;
|
||||
std::optional<int> target_time_signature;
|
||||
|
||||
std::optional<float> min_valence;
|
||||
std::optional<float> max_valence;
|
||||
std::optional<float> target_valence;
|
||||
|
||||
auto ToQueryParams() const -> std::map<std::string, std::string> override {
|
||||
std::map<std::string, std::string> params;
|
||||
|
||||
if (seed_artists && !seed_artists->empty()) {
|
||||
params["seed_artists"] = std::views::join_with(*seed_artists, ',') | std::ranges::to<std::string>();
|
||||
}
|
||||
if (seed_genres && !seed_genres->empty()) {
|
||||
params["seed_genres"] = std::views::join_with(*seed_genres, ',') | std::ranges::to<std::string>();
|
||||
}
|
||||
if (seed_tracks && !seed_tracks->empty()) {
|
||||
params["seed_tracks"] = std::views::join_with(*seed_tracks, ',') | std::ranges::to<std::string>();
|
||||
}
|
||||
|
||||
if (limit) params["limit"] = std::to_string(*limit);
|
||||
if (market) params["market"] = *market;
|
||||
|
||||
// Add all tunable attributes
|
||||
if (min_acousticness) params["min_acousticness"] = std::to_string(*min_acousticness);
|
||||
if (max_acousticness) params["max_acousticness"] = std::to_string(*max_acousticness);
|
||||
if (target_acousticness) params["target_acousticness"] = std::to_string(*target_acousticness);
|
||||
|
||||
if (min_danceability) params["min_danceability"] = std::to_string(*min_danceability);
|
||||
if (max_danceability) params["max_danceability"] = std::to_string(*max_danceability);
|
||||
if (target_danceability) params["target_danceability"] = std::to_string(*target_danceability);
|
||||
|
||||
if (min_energy) params["min_energy"] = std::to_string(*min_energy);
|
||||
if (max_energy) params["max_energy"] = std::to_string(*max_energy);
|
||||
if (target_energy) params["target_energy"] = std::to_string(*target_energy);
|
||||
|
||||
if (min_popularity) params["min_popularity"] = std::to_string(*min_popularity);
|
||||
if (max_popularity) params["max_popularity"] = std::to_string(*max_popularity);
|
||||
if (target_popularity) params["target_popularity"] = std::to_string(*target_popularity);
|
||||
|
||||
// Add remaining attributes as needed...
|
||||
|
||||
return params;
|
||||
}
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Create Playlist Parameters
|
||||
// ============================================================================
|
||||
|
||||
struct CreatePlaylistParams {
|
||||
std::string name;
|
||||
std::optional<bool> public_playlist = true;
|
||||
std::optional<bool> collaborative = false;
|
||||
std::optional<std::string> description;
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Update Playlist Parameters
|
||||
// ============================================================================
|
||||
|
||||
struct UpdatePlaylistParams {
|
||||
std::optional<std::string> name;
|
||||
std::optional<bool> public_playlist;
|
||||
std::optional<bool> collaborative;
|
||||
std::optional<std::string> description;
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Playlist Track Operations
|
||||
// ============================================================================
|
||||
|
||||
struct AddTracksToPlaylistParams {
|
||||
std::vector<std::string> uris;
|
||||
std::optional<int> position;
|
||||
};
|
||||
|
||||
struct RemoveTracksFromPlaylistParams {
|
||||
std::vector<std::string> uris;
|
||||
std::optional<std::string> snapshot_id;
|
||||
};
|
||||
|
||||
struct ReorderPlaylistParams {
|
||||
int range_start;
|
||||
int insert_before;
|
||||
std::optional<int> range_length = 1;
|
||||
std::optional<std::string> snapshot_id;
|
||||
};
|
||||
|
||||
struct ReplacePlaylistTracksParams {
|
||||
std::vector<std::string> uris;
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Playback Control Parameters
|
||||
// ============================================================================
|
||||
|
||||
struct PlayParams {
|
||||
std::optional<std::string> context_uri;
|
||||
std::optional<std::vector<std::string>> uris;
|
||||
std::optional<std::map<std::string, int>> offset;
|
||||
std::optional<int> position_ms;
|
||||
};
|
||||
|
||||
struct TransferPlaybackParams {
|
||||
std::vector<std::string> device_ids;
|
||||
std::optional<bool> play;
|
||||
};
|
||||
|
||||
struct QueueParams {
|
||||
std::string uri;
|
||||
std::optional<std::string> device_id;
|
||||
};
|
||||
struct RequestBody {
|
||||
std::vector<std::string> ids;
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Follow Parameters
|
||||
// ============================================================================
|
||||
struct ErrorResponse {
|
||||
struct Error {
|
||||
int status;
|
||||
std::string message;
|
||||
} error;
|
||||
};
|
||||
enum class FollowType {
|
||||
Artist,
|
||||
User
|
||||
};
|
||||
|
||||
inline auto FollowTypeToString(FollowType type) -> std::string {
|
||||
return type == FollowType::Artist ? "artist" : "user";
|
||||
}
|
||||
|
||||
struct FollowParams {
|
||||
FollowType type;
|
||||
std::vector<std::string> ids;
|
||||
};
|
||||
|
||||
struct UnfollowParams {
|
||||
FollowType type;
|
||||
std::vector<std::string> ids;
|
||||
};
|
||||
|
||||
struct CheckFollowingParams {
|
||||
FollowType type;
|
||||
std::vector<std::string> ids;
|
||||
};
|
||||
|
||||
struct FollowPlaylistParams {
|
||||
std::optional<bool> public_playlist = true;
|
||||
};
|
||||
|
||||
} // namespace Spotify::Request
|
||||
@@ -0,0 +1,178 @@
|
||||
#pragma once
|
||||
#include "Spotify/Types/Common.hpp"
|
||||
#include "Spotify/Types/Artist.hpp"
|
||||
|
||||
namespace Spotify {
|
||||
|
||||
// ============================================================================
|
||||
// Album Group Enum
|
||||
// ============================================================================
|
||||
|
||||
enum class AlbumGroup {
|
||||
Album,
|
||||
Single,
|
||||
AppearsOn,
|
||||
Compilation
|
||||
};
|
||||
|
||||
inline auto AlbumGroupToString(AlbumGroup group) -> std::string {
|
||||
switch (group) {
|
||||
case AlbumGroup::Album: return "album";
|
||||
case AlbumGroup::Single: return "single";
|
||||
case AlbumGroup::AppearsOn: return "appears_on";
|
||||
case AlbumGroup::Compilation: return "compilation";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Album Base
|
||||
// ============================================================================
|
||||
|
||||
class AlbumBase {
|
||||
public:
|
||||
std::string album_type;
|
||||
int total_tracks;
|
||||
std::vector<std::string> available_markets;
|
||||
ExternalUrls external_urls;
|
||||
std::string href;
|
||||
std::string id;
|
||||
std::vector<Image> images;
|
||||
std::string name;
|
||||
std::string release_date;
|
||||
std::string release_date_precision;
|
||||
std::optional<Restrictions> restrictions;
|
||||
std::string type;
|
||||
std::string uri;
|
||||
std::vector<SimplifiedArtist> artists;
|
||||
bool is_playable;
|
||||
|
||||
virtual ~AlbumBase() = default;
|
||||
|
||||
auto GetId() const -> const std::string& { return id; }
|
||||
auto GetName() const -> const std::string& { return name; }
|
||||
auto GetUri() const -> const std::string& { return uri; }
|
||||
auto GetReleaseDate() const -> const std::string& { return release_date; }
|
||||
auto GetTotalTracks() const -> int { return total_tracks; }
|
||||
|
||||
auto GetAlbumType() const -> AlbumType {
|
||||
if (album_type == "album") return AlbumType::Album;
|
||||
if (album_type == "single") return AlbumType::Single;
|
||||
return AlbumType::Compilation;
|
||||
}
|
||||
|
||||
auto GetReleaseDatePrecision() const -> ReleaseDatePrecision {
|
||||
if (release_date_precision == "year") return ReleaseDatePrecision::Year;
|
||||
if (release_date_precision == "month") return ReleaseDatePrecision::Month;
|
||||
return ReleaseDatePrecision::Day;
|
||||
}
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Simplified Album
|
||||
// ============================================================================
|
||||
|
||||
struct SimplifiedAlbum : AlbumBase {
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Full Album
|
||||
// ============================================================================
|
||||
|
||||
struct Album : AlbumBase {
|
||||
std::vector<Copyright> copyrights;
|
||||
ExternalIds external_ids;
|
||||
std::vector<std::string> genres;
|
||||
std::string label;
|
||||
int popularity;
|
||||
|
||||
auto GetPopularity() const -> int { return popularity; }
|
||||
auto GetLabel() const -> const std::string& { return label; }
|
||||
auto GetGenres() const -> const std::vector<std::string>& { return genres; }
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Saved Album
|
||||
// ============================================================================
|
||||
|
||||
struct SavedAlbum {
|
||||
std::string added_at;
|
||||
Album album;
|
||||
|
||||
auto GetAlbum() const -> const Album& { return album; }
|
||||
auto GetAddedAt() const -> const std::string& { return added_at; }
|
||||
};
|
||||
|
||||
struct AlbumsResponse {
|
||||
std::vector<Album> albums;
|
||||
};
|
||||
} // namespace Spotify
|
||||
|
||||
// ============================================================================
|
||||
// Glaze Metadata
|
||||
// ============================================================================
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::SimplifiedAlbum> {
|
||||
using T = Spotify::SimplifiedAlbum;
|
||||
static constexpr auto value = object(
|
||||
"album_type", &T::album_type,
|
||||
"total_tracks", &T::total_tracks,
|
||||
"available_markets", &T::available_markets,
|
||||
"external_urls", &T::external_urls,
|
||||
"href", &T::href,
|
||||
"id", &T::id,
|
||||
"images", &T::images,
|
||||
"name", &T::name,
|
||||
"release_date", &T::release_date,
|
||||
"release_date_precision", &T::release_date_precision,
|
||||
"restrictions", &T::restrictions,
|
||||
"type", &T::type,
|
||||
"uri", &T::uri,
|
||||
"artists", &T::artists,
|
||||
"is_playable", &T::is_playable
|
||||
);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::AlbumsResponse> {
|
||||
using T = Spotify::AlbumsResponse;
|
||||
static constexpr auto value = object(
|
||||
"albums", &T::albums
|
||||
);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::Album> {
|
||||
using T = Spotify::Album;
|
||||
static constexpr auto value = object(
|
||||
"album_type", &T::album_type,
|
||||
"total_tracks", &T::total_tracks,
|
||||
"available_markets", &T::available_markets,
|
||||
"external_urls", &T::external_urls,
|
||||
"href", &T::href,
|
||||
"id", &T::id,
|
||||
"images", &T::images,
|
||||
"name", &T::name,
|
||||
"release_date", &T::release_date,
|
||||
"release_date_precision", &T::release_date_precision,
|
||||
"restrictions", &T::restrictions,
|
||||
"type", &T::type,
|
||||
"uri", &T::uri,
|
||||
"artists", &T::artists,
|
||||
"copyrights", &T::copyrights,
|
||||
"external_ids", &T::external_ids,
|
||||
"genres", &T::genres,
|
||||
"label", &T::label,
|
||||
"popularity", &T::popularity
|
||||
);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::SavedAlbum> {
|
||||
using T = Spotify::SavedAlbum;
|
||||
static constexpr auto value = object(
|
||||
"added_at", &T::added_at,
|
||||
"album", &T::album
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
#include "Spotify/Types/Common.hpp"
|
||||
|
||||
namespace Spotify {
|
||||
|
||||
// ============================================================================
|
||||
// Artist Base
|
||||
// ============================================================================
|
||||
|
||||
class ArtistBase {
|
||||
public:
|
||||
ExternalUrls external_urls;
|
||||
std::string href;
|
||||
std::string id;
|
||||
std::string name;
|
||||
std::string type;
|
||||
std::string uri;
|
||||
|
||||
virtual ~ArtistBase() = default;
|
||||
|
||||
auto GetId() const -> const std::string& { return id; }
|
||||
auto GetName() const -> const std::string& { return name; }
|
||||
auto GetUri() const -> const std::string& { return uri; }
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Simplified Artist
|
||||
// ============================================================================
|
||||
|
||||
struct SimplifiedArtist : ArtistBase {
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Full Artist
|
||||
// ============================================================================
|
||||
|
||||
struct Artist : ArtistBase {
|
||||
Followers followers;
|
||||
std::vector<std::string> genres;
|
||||
std::vector<Image> images;
|
||||
int popularity;
|
||||
|
||||
auto GetPopularity() const -> int { return popularity; }
|
||||
auto GetGenres() const -> const std::vector<std::string>& { return genres; }
|
||||
};
|
||||
|
||||
struct ArtistsResponse {
|
||||
std::vector<Artist> artists;
|
||||
};
|
||||
} // namespace Spotify
|
||||
|
||||
// ============================================================================
|
||||
// Glaze Metadata
|
||||
// ============================================================================
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::SimplifiedArtist> {
|
||||
using T = Spotify::SimplifiedArtist;
|
||||
static constexpr auto value = object(
|
||||
"external_urls", &T::external_urls,
|
||||
"href", &T::href,
|
||||
"id", &T::id,
|
||||
"name", &T::name,
|
||||
"type", &T::type,
|
||||
"uri", &T::uri
|
||||
);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::Artist> {
|
||||
using T = Spotify::Artist;
|
||||
static constexpr auto value = object(
|
||||
"external_urls", &T::external_urls,
|
||||
"followers", &T::followers,
|
||||
"genres", &T::genres,
|
||||
"href", &T::href,
|
||||
"id", &T::id,
|
||||
"images", &T::images,
|
||||
"name", &T::name,
|
||||
"popularity", &T::popularity,
|
||||
"type", &T::type,
|
||||
"uri", &T::uri
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,185 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
#include <glaze/glaze.hpp>
|
||||
|
||||
namespace Spotify {
|
||||
|
||||
// ============================================================================
|
||||
// Common Enums
|
||||
// ============================================================================
|
||||
|
||||
enum class AlbumType {
|
||||
Album,
|
||||
Single,
|
||||
Compilation
|
||||
};
|
||||
|
||||
enum class ReleaseDatePrecision {
|
||||
Year,
|
||||
Month,
|
||||
Day
|
||||
};
|
||||
|
||||
enum class CopyrightType {
|
||||
Copyright, // "C"
|
||||
Performance // "P"
|
||||
};
|
||||
|
||||
enum class RestrictionReason {
|
||||
Market,
|
||||
Product,
|
||||
Explicit
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Core Structures
|
||||
// ============================================================================
|
||||
|
||||
struct Image {
|
||||
std::string url;
|
||||
std::optional<int> height;
|
||||
std::optional<int> width;
|
||||
};
|
||||
|
||||
struct ExternalUrls {
|
||||
std::string spotify;
|
||||
};
|
||||
|
||||
struct ExternalIds {
|
||||
std::optional<std::string> isrc;
|
||||
std::optional<std::string> ean;
|
||||
std::optional<std::string> upc;
|
||||
};
|
||||
|
||||
struct Followers {
|
||||
std::optional<std::string> href;
|
||||
int total;
|
||||
};
|
||||
|
||||
struct Copyright {
|
||||
std::string text;
|
||||
std::string type;
|
||||
|
||||
auto GetType() const -> CopyrightType {
|
||||
return type == "C" ? CopyrightType::Copyright : CopyrightType::Performance;
|
||||
}
|
||||
};
|
||||
|
||||
struct Restrictions {
|
||||
std::string reason;
|
||||
|
||||
auto GetReason() const -> RestrictionReason {
|
||||
if (reason == "market") return RestrictionReason::Market;
|
||||
if (reason == "product") return RestrictionReason::Product;
|
||||
return RestrictionReason::Explicit;
|
||||
}
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Paging Objects
|
||||
// ============================================================================
|
||||
|
||||
template<typename T>
|
||||
struct PagingObject {
|
||||
std::string href;
|
||||
int limit;
|
||||
std::optional<std::string> next;
|
||||
int offset;
|
||||
std::optional<std::string> previous;
|
||||
int total;
|
||||
std::vector<T> items;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct CursorPagingObject {
|
||||
std::string href;
|
||||
int limit;
|
||||
std::optional<std::string> next;
|
||||
std::optional<std::string> cursors;
|
||||
int total;
|
||||
std::vector<T> items;
|
||||
};
|
||||
} // namespace Spotify
|
||||
|
||||
// ============================================================================
|
||||
// Glaze Metadata for Common Types
|
||||
// ============================================================================
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::Image> {
|
||||
using T = Spotify::Image;
|
||||
static constexpr auto value = object(
|
||||
"url", &T::url,
|
||||
"height", &T::height,
|
||||
"width", &T::width
|
||||
);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::ExternalUrls> {
|
||||
using T = Spotify::ExternalUrls;
|
||||
static constexpr auto value = object("spotify", &T::spotify);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::ExternalIds> {
|
||||
using T = Spotify::ExternalIds;
|
||||
static constexpr auto value = object(
|
||||
"isrc", &T::isrc,
|
||||
"ean", &T::ean,
|
||||
"upc", &T::upc
|
||||
);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::Followers> {
|
||||
using T = Spotify::Followers;
|
||||
static constexpr auto value = object(
|
||||
"href", &T::href,
|
||||
"total", &T::total
|
||||
);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::Copyright> {
|
||||
using T = Spotify::Copyright;
|
||||
static constexpr auto value = object(
|
||||
"text", &T::text,
|
||||
"type", &T::type
|
||||
);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::Restrictions> {
|
||||
using T = Spotify::Restrictions;
|
||||
static constexpr auto value = object("reason", &T::reason);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct glz::meta<Spotify::PagingObject<T>> {
|
||||
using Type = Spotify::PagingObject<T>;
|
||||
static constexpr auto value = object(
|
||||
"href", &Type::href,
|
||||
"limit", &Type::limit,
|
||||
"next", &Type::next,
|
||||
"offset", &Type::offset,
|
||||
"previous", &Type::previous,
|
||||
"total", &Type::total,
|
||||
"items", &Type::items
|
||||
);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct glz::meta<Spotify::CursorPagingObject<T>> {
|
||||
using Type = Spotify::CursorPagingObject<T>;
|
||||
static constexpr auto value = object(
|
||||
"href", &Type::href,
|
||||
"limit", &Type::limit,
|
||||
"next", &Type::next,
|
||||
"cursors", &Type::cursors,
|
||||
"total", &Type::total,
|
||||
"items", &Type::items
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,133 @@
|
||||
#pragma once
|
||||
#include "Spotify/Types/Common.hpp"
|
||||
#include "Spotify/Types/Track.hpp"
|
||||
#include "Spotify/Types/Artist.hpp"
|
||||
#include "Spotify/Types/Album.hpp"
|
||||
#include "Spotify/Types/Playlist.hpp"
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Spotify {
|
||||
|
||||
// ============================================================================
|
||||
// Category
|
||||
// ============================================================================
|
||||
|
||||
struct Category {
|
||||
std::string href;
|
||||
std::vector<Image> icons;
|
||||
std::string id;
|
||||
std::string name;
|
||||
|
||||
auto GetId() const -> const std::string& { return id; }
|
||||
auto GetName() const -> const std::string& { return name; }
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Recommendation Seed
|
||||
// ============================================================================
|
||||
|
||||
enum class SeedType {
|
||||
Artist,
|
||||
Track,
|
||||
Genre
|
||||
};
|
||||
|
||||
inline auto StringToSeedType(const std::string& str) -> SeedType {
|
||||
if (str == "ARTIST") return SeedType::Artist;
|
||||
if (str == "TRACK") return SeedType::Track;
|
||||
return SeedType::Genre;
|
||||
}
|
||||
|
||||
struct RecommendationSeed {
|
||||
int afterFilteringSize;
|
||||
int afterRelinkingSize;
|
||||
std::optional<std::string> href;
|
||||
std::string id;
|
||||
int initialPoolSize;
|
||||
std::string type;
|
||||
|
||||
auto GetId() const -> const std::string& { return id; }
|
||||
auto GetSeedType() const -> SeedType {
|
||||
return StringToSeedType(type);
|
||||
}
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Recommendations Response
|
||||
// ============================================================================
|
||||
|
||||
struct Recommendations {
|
||||
std::vector<RecommendationSeed> seeds;
|
||||
std::vector<Track> tracks;
|
||||
|
||||
auto GetTracks() const -> const std::vector<Track>& { return tracks; }
|
||||
auto GetSeeds() const -> const std::vector<RecommendationSeed>& { return seeds; }
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Search Results
|
||||
// ============================================================================
|
||||
|
||||
struct SearchResults {
|
||||
std::optional<PagingObject<Track>> tracks;
|
||||
std::optional<PagingObject<Artist>> artists;
|
||||
std::optional<PagingObject<SimplifiedAlbum>> albums;
|
||||
std::optional<PagingObject<SimplifiedPlaylist>> playlists;
|
||||
|
||||
auto GetTracks() const -> const std::optional<PagingObject<Track>>& { return tracks; }
|
||||
auto GetArtists() const -> const std::optional<PagingObject<Artist>>& { return artists; }
|
||||
auto GetAlbums() const -> const std::optional<PagingObject<SimplifiedAlbum>>& { return albums; }
|
||||
auto GetPlaylists() const -> const std::optional<PagingObject<SimplifiedPlaylist>>& { return playlists; }
|
||||
};
|
||||
} // namespace Spotify
|
||||
|
||||
// ============================================================================
|
||||
// Glaze Metadata
|
||||
// ============================================================================
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::Category> {
|
||||
using T = Spotify::Category;
|
||||
static constexpr auto value = object(
|
||||
"href", &T::href,
|
||||
"icons", &T::icons,
|
||||
"id", &T::id,
|
||||
"name", &T::name
|
||||
);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::RecommendationSeed> {
|
||||
using T = Spotify::RecommendationSeed;
|
||||
static constexpr auto value = object(
|
||||
"afterFilteringSize", &T::afterFilteringSize,
|
||||
"afterRelinkingSize", &T::afterRelinkingSize,
|
||||
"href", &T::href,
|
||||
"id", &T::id,
|
||||
"initialPoolSize", &T::initialPoolSize,
|
||||
"type", &T::type
|
||||
);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::Recommendations> {
|
||||
using T = Spotify::Recommendations;
|
||||
static constexpr auto value = object(
|
||||
"seeds", &T::seeds,
|
||||
"tracks", &T::tracks
|
||||
);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::SearchResults> {
|
||||
using T = Spotify::SearchResults;
|
||||
static constexpr auto value = object(
|
||||
"tracks", &T::tracks,
|
||||
"artists", &T::artists,
|
||||
"albums", &T::albums,
|
||||
"playlists", &T::playlists
|
||||
);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,218 @@
|
||||
#pragma once
|
||||
#include "Spotify/Types/Common.hpp"
|
||||
#include "Spotify/Types/Track.hpp"
|
||||
|
||||
namespace Spotify {
|
||||
|
||||
// ============================================================================
|
||||
// Device Type Enum
|
||||
// ============================================================================
|
||||
|
||||
enum class DeviceType {
|
||||
Computer,
|
||||
Smartphone,
|
||||
Speaker,
|
||||
TV,
|
||||
AVR,
|
||||
STB,
|
||||
AudioDongle,
|
||||
GameConsole,
|
||||
CastVideo,
|
||||
CastAudio,
|
||||
Automobile,
|
||||
Unknown
|
||||
};
|
||||
|
||||
inline auto StringToDeviceType(const std::string& str) -> DeviceType {
|
||||
if (str == "Computer") return DeviceType::Computer;
|
||||
if (str == "Smartphone") return DeviceType::Smartphone;
|
||||
if (str == "Speaker") return DeviceType::Speaker;
|
||||
if (str == "TV") return DeviceType::TV;
|
||||
if (str == "AVR") return DeviceType::AVR;
|
||||
if (str == "STB") return DeviceType::STB;
|
||||
if (str == "AudioDongle") return DeviceType::AudioDongle;
|
||||
if (str == "GameConsole") return DeviceType::GameConsole;
|
||||
if (str == "CastVideo") return DeviceType::CastVideo;
|
||||
if (str == "CastAudio") return DeviceType::CastAudio;
|
||||
if (str == "Automobile") return DeviceType::Automobile;
|
||||
return DeviceType::Unknown;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Repeat Mode Enum
|
||||
// ============================================================================
|
||||
|
||||
enum class RepeatMode {
|
||||
Off,
|
||||
Track,
|
||||
Context
|
||||
};
|
||||
|
||||
inline auto RepeatModeToString(RepeatMode mode) -> std::string {
|
||||
switch (mode) {
|
||||
case RepeatMode::Off: return "off";
|
||||
case RepeatMode::Track: return "track";
|
||||
case RepeatMode::Context: return "context";
|
||||
}
|
||||
return "off";
|
||||
}
|
||||
|
||||
inline auto StringToRepeatMode(const std::string& str) -> RepeatMode {
|
||||
if (str == "track") return RepeatMode::Track;
|
||||
if (str == "context") return RepeatMode::Context;
|
||||
return RepeatMode::Off;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Context Type Enum
|
||||
// ============================================================================
|
||||
|
||||
enum class ContextType {
|
||||
Artist,
|
||||
Playlist,
|
||||
Album,
|
||||
Show,
|
||||
Collection
|
||||
};
|
||||
|
||||
inline auto StringToContextType(const std::string& str) -> ContextType {
|
||||
if (str == "artist") return ContextType::Artist;
|
||||
if (str == "playlist") return ContextType::Playlist;
|
||||
if (str == "album") return ContextType::Album;
|
||||
if (str == "show") return ContextType::Show;
|
||||
return ContextType::Collection;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Currently Playing Type Enum
|
||||
// ============================================================================
|
||||
|
||||
enum class CurrentlyPlayingType {
|
||||
Track,
|
||||
Episode,
|
||||
Ad,
|
||||
Unknown
|
||||
};
|
||||
|
||||
inline auto StringToCurrentlyPlayingType(const std::string& str) -> CurrentlyPlayingType {
|
||||
if (str == "track") return CurrentlyPlayingType::Track;
|
||||
if (str == "episode") return CurrentlyPlayingType::Episode;
|
||||
if (str == "ad") return CurrentlyPlayingType::Ad;
|
||||
return CurrentlyPlayingType::Unknown;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Device
|
||||
// ============================================================================
|
||||
|
||||
struct Device {
|
||||
std::optional<std::string> id;
|
||||
bool is_active;
|
||||
bool is_private_session;
|
||||
bool is_restricted;
|
||||
std::string name;
|
||||
std::string type;
|
||||
int volume_percent;
|
||||
|
||||
auto GetId() const -> const std::optional<std::string>& { return id; }
|
||||
auto GetName() const -> const std::string& { return name; }
|
||||
auto IsActive() const -> bool { return is_active; }
|
||||
auto GetVolume() const -> int { return volume_percent; }
|
||||
|
||||
auto GetDeviceType() const -> DeviceType {
|
||||
return StringToDeviceType(type);
|
||||
}
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Context
|
||||
// ============================================================================
|
||||
|
||||
struct Context {
|
||||
std::string type;
|
||||
std::string href;
|
||||
ExternalUrls external_urls;
|
||||
std::string uri;
|
||||
|
||||
auto GetUri() const -> const std::string& { return uri; }
|
||||
|
||||
auto GetContextType() const -> ContextType {
|
||||
return StringToContextType(type);
|
||||
}
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Playback State
|
||||
// ============================================================================
|
||||
|
||||
struct PlaybackState {
|
||||
Device device;
|
||||
std::string repeat_state;
|
||||
bool shuffle_state;
|
||||
std::optional<Context> context;
|
||||
int timestamp;
|
||||
int progress_ms;
|
||||
bool is_playing;
|
||||
std::optional<Track> item;
|
||||
std::string currently_playing_type;
|
||||
|
||||
auto GetDevice() const -> const Device& { return device; }
|
||||
auto IsPlaying() const -> bool { return is_playing; }
|
||||
auto IsShuffled() const -> bool { return shuffle_state; }
|
||||
auto GetProgressMs() const -> int { return progress_ms; }
|
||||
auto GetCurrentTrack() const -> const std::optional<Track>& { return item; }
|
||||
|
||||
auto GetRepeatMode() const -> RepeatMode {
|
||||
return StringToRepeatMode(repeat_state);
|
||||
}
|
||||
|
||||
auto GetCurrentlyPlayingType() const -> CurrentlyPlayingType {
|
||||
return StringToCurrentlyPlayingType(currently_playing_type);
|
||||
}
|
||||
};
|
||||
} // namespace Spotify
|
||||
|
||||
// ============================================================================
|
||||
// Glaze Metadata
|
||||
// ============================================================================
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::Device> {
|
||||
using T = Spotify::Device;
|
||||
static constexpr auto value = object(
|
||||
"id", &T::id,
|
||||
"is_active", &T::is_active,
|
||||
"is_private_session", &T::is_private_session,
|
||||
"is_restricted", &T::is_restricted,
|
||||
"name", &T::name,
|
||||
"type", &T::type,
|
||||
"volume_percent", &T::volume_percent
|
||||
);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::Context> {
|
||||
using T = Spotify::Context;
|
||||
static constexpr auto value = object(
|
||||
"type", &T::type,
|
||||
"href", &T::href,
|
||||
"external_urls", &T::external_urls,
|
||||
"uri", &T::uri
|
||||
);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::PlaybackState> {
|
||||
using T = Spotify::PlaybackState;
|
||||
static constexpr auto value = object(
|
||||
"device", &T::device,
|
||||
"repeat_state", &T::repeat_state,
|
||||
"shuffle_state", &T::shuffle_state,
|
||||
"context", &T::context,
|
||||
"timestamp", &T::timestamp,
|
||||
"progress_ms", &T::progress_ms,
|
||||
"is_playing", &T::is_playing,
|
||||
"item", &T::item,
|
||||
"currently_playing_type", &T::currently_playing_type
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,139 @@
|
||||
#pragma once
|
||||
#include "Spotify/Types/Common.hpp"
|
||||
#include "Spotify/Types/Artist.hpp"
|
||||
#include "Spotify/Types/Track.hpp"
|
||||
|
||||
namespace Spotify {
|
||||
|
||||
// ============================================================================
|
||||
// Playlist Track
|
||||
// ============================================================================
|
||||
|
||||
struct PlaylistTrack {
|
||||
std::optional<std::string> added_at;
|
||||
std::optional<SimplifiedArtist> added_by;
|
||||
bool is_local;
|
||||
Track track;
|
||||
|
||||
auto GetTrack() const -> const Track& { return track; }
|
||||
auto GetAddedAt() const -> const std::optional<std::string>& { return added_at; }
|
||||
auto IsLocal() const -> bool { return is_local; }
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Playlist Base
|
||||
// ============================================================================
|
||||
|
||||
class PlaylistBase {
|
||||
public:
|
||||
bool collaborative;
|
||||
std::optional<std::string> description;
|
||||
ExternalUrls external_urls;
|
||||
std::string href;
|
||||
std::string id;
|
||||
std::vector<Image> images;
|
||||
std::string name;
|
||||
SimplifiedArtist owner;
|
||||
bool public_playlist;
|
||||
std::optional<std::string> snapshot_id;
|
||||
std::string type;
|
||||
std::string uri;
|
||||
|
||||
virtual ~PlaylistBase() = default;
|
||||
|
||||
auto GetId() const -> const std::string& { return id; }
|
||||
auto GetName() const -> const std::string& { return name; }
|
||||
auto GetUri() const -> const std::string& { return uri; }
|
||||
auto GetOwner() const -> const SimplifiedArtist& { return owner; }
|
||||
auto IsPublic() const -> bool { return public_playlist; }
|
||||
auto IsCollaborative() const -> bool { return collaborative; }
|
||||
auto GetSnapshotId() const -> const std::optional<std::string>& { return snapshot_id; }
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Simplified Playlist
|
||||
// ============================================================================
|
||||
|
||||
struct SimplifiedPlaylist : PlaylistBase {
|
||||
struct TracksInfo {
|
||||
std::string href;
|
||||
int total;
|
||||
} tracks;
|
||||
|
||||
auto GetTotalTracks() const -> int { return tracks.total; }
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Full Playlist
|
||||
// ============================================================================
|
||||
|
||||
struct Playlist : PlaylistBase {
|
||||
Followers followers;
|
||||
|
||||
auto GetFollowers() const -> const Followers& { return followers; }
|
||||
};
|
||||
} // namespace Spotify
|
||||
|
||||
// ============================================================================
|
||||
// Glaze Metadata
|
||||
// ============================================================================
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::PlaylistTrack> {
|
||||
using T = Spotify::PlaylistTrack;
|
||||
static constexpr auto value = object(
|
||||
"added_at", &T::added_at,
|
||||
"added_by", &T::added_by,
|
||||
"is_local", &T::is_local,
|
||||
"track", &T::track
|
||||
);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::SimplifiedPlaylist::TracksInfo> {
|
||||
using T = Spotify::SimplifiedPlaylist::TracksInfo;
|
||||
static constexpr auto value = object(
|
||||
"href", &T::href,
|
||||
"total", &T::total
|
||||
);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::SimplifiedPlaylist> {
|
||||
using T = Spotify::SimplifiedPlaylist;
|
||||
static constexpr auto value = object(
|
||||
"collaborative", &T::collaborative,
|
||||
"description", &T::description,
|
||||
"external_urls", &T::external_urls,
|
||||
"href", &T::href,
|
||||
"id", &T::id,
|
||||
"images", &T::images,
|
||||
"name", &T::name,
|
||||
"owner", &T::owner,
|
||||
"public", &T::public_playlist,
|
||||
"snapshot_id", &T::snapshot_id,
|
||||
"tracks", &T::tracks,
|
||||
"type", &T::type,
|
||||
"uri", &T::uri
|
||||
);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::Playlist> {
|
||||
using T = Spotify::Playlist;
|
||||
static constexpr auto value = object(
|
||||
"collaborative", &T::collaborative,
|
||||
"description", &T::description,
|
||||
"external_urls", &T::external_urls,
|
||||
"followers", &T::followers,
|
||||
"href", &T::href,
|
||||
"id", &T::id,
|
||||
"images", &T::images,
|
||||
"name", &T::name,
|
||||
"owner", &T::owner,
|
||||
"public", &T::public_playlist,
|
||||
"snapshot_id", &T::snapshot_id,
|
||||
"type", &T::type,
|
||||
"uri", &T::uri
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,318 @@
|
||||
#pragma once
|
||||
#include "Spotify/Types/Common.hpp"
|
||||
#include "Spotify/Types/Artist.hpp"
|
||||
#include "Spotify/Types/Album.hpp"
|
||||
|
||||
namespace Spotify {
|
||||
|
||||
// ============================================================================
|
||||
// Track Base
|
||||
// ============================================================================
|
||||
|
||||
class TrackBase {
|
||||
public:
|
||||
std::vector<SimplifiedArtist> artists;
|
||||
std::vector<std::string> available_markets;
|
||||
int disc_number;
|
||||
int duration_ms;
|
||||
bool explicit_content;
|
||||
ExternalUrls external_urls;
|
||||
std::string href;
|
||||
std::string id;
|
||||
bool is_playable;
|
||||
std::optional<std::string> linked_from;
|
||||
std::optional<Restrictions> restrictions;
|
||||
std::string name;
|
||||
std::optional<std::string> preview_url;
|
||||
int track_number;
|
||||
std::string type;
|
||||
std::string uri;
|
||||
bool is_local;
|
||||
|
||||
virtual ~TrackBase() = default;
|
||||
|
||||
auto GetId() const -> const std::string& { return id; }
|
||||
auto GetName() const -> const std::string& { return name; }
|
||||
auto GetUri() const -> const std::string& { return uri; }
|
||||
auto GetDurationMs() const -> int { return duration_ms; }
|
||||
auto GetTrackNumber() const -> int { return track_number; }
|
||||
auto IsExplicit() const -> bool { return explicit_content; }
|
||||
auto IsLocal() const -> bool { return is_local; }
|
||||
auto GetArtists() const -> const std::vector<SimplifiedArtist>& { return artists; }
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Simplified Track
|
||||
// ============================================================================
|
||||
|
||||
struct SimplifiedTrack : TrackBase {
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Full Track
|
||||
// ============================================================================
|
||||
|
||||
struct Track : TrackBase {
|
||||
SimplifiedAlbum album;
|
||||
ExternalIds external_ids;
|
||||
int popularity;
|
||||
|
||||
auto GetAlbum() const -> const SimplifiedAlbum& { return album; }
|
||||
auto GetPopularity() const -> int { return popularity; }
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Saved Track
|
||||
// ============================================================================
|
||||
|
||||
struct SavedTrack {
|
||||
std::string added_at;
|
||||
Track track;
|
||||
|
||||
auto GetTrack() const -> const Track& { return track; }
|
||||
auto GetAddedAt() const -> const std::string& { return added_at; }
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Audio Features
|
||||
// ============================================================================
|
||||
|
||||
enum class MusicalKey {
|
||||
C = 0, CSharp = 1, D = 2, DSharp = 3,
|
||||
E = 4, F = 5, FSharp = 6, G = 7,
|
||||
GSharp = 8, A = 9, ASharp = 10, B = 11
|
||||
};
|
||||
|
||||
enum class MusicalMode {
|
||||
Minor = 0,
|
||||
Major = 1
|
||||
};
|
||||
|
||||
struct AudioFeatures {
|
||||
float acousticness;
|
||||
std::string analysis_url;
|
||||
float danceability;
|
||||
int duration_ms;
|
||||
float energy;
|
||||
std::string id;
|
||||
float instrumentalness;
|
||||
int key;
|
||||
float liveness;
|
||||
float loudness;
|
||||
int mode;
|
||||
float speechiness;
|
||||
float tempo;
|
||||
int time_signature;
|
||||
std::string track_href;
|
||||
std::string type;
|
||||
std::string uri;
|
||||
float valence;
|
||||
|
||||
auto GetKey() const -> MusicalKey { return static_cast<MusicalKey>(key); }
|
||||
auto GetMode() const -> MusicalMode { return static_cast<MusicalMode>(mode); }
|
||||
auto GetAcousticness() const -> float { return acousticness; }
|
||||
auto GetDanceability() const -> float { return danceability; }
|
||||
auto GetEnergy() const -> float { return energy; }
|
||||
auto GetValence() const -> float { return valence; }
|
||||
auto GetTempo() const -> float { return tempo; }
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Audio Analysis
|
||||
// ============================================================================
|
||||
|
||||
struct TimeInterval {
|
||||
float start;
|
||||
float duration;
|
||||
float confidence;
|
||||
};
|
||||
|
||||
struct Section {
|
||||
float start;
|
||||
float duration;
|
||||
float confidence;
|
||||
float loudness;
|
||||
float tempo;
|
||||
float tempo_confidence;
|
||||
int key;
|
||||
float key_confidence;
|
||||
int mode;
|
||||
float mode_confidence;
|
||||
int time_signature;
|
||||
float time_signature_confidence;
|
||||
};
|
||||
|
||||
struct Segment {
|
||||
float start;
|
||||
float duration;
|
||||
float confidence;
|
||||
float loudness_start;
|
||||
float loudness_max;
|
||||
float loudness_max_time;
|
||||
float loudness_end;
|
||||
std::vector<float> pitches;
|
||||
std::vector<float> timbre;
|
||||
};
|
||||
|
||||
struct AudioAnalysis {
|
||||
std::vector<TimeInterval> bars;
|
||||
std::vector<TimeInterval> beats;
|
||||
std::vector<Section> sections;
|
||||
std::vector<Segment> segments;
|
||||
std::vector<TimeInterval> tatums;
|
||||
|
||||
auto GetBars() const -> const std::vector<TimeInterval>& { return bars; }
|
||||
auto GetBeats() const -> const std::vector<TimeInterval>& { return beats; }
|
||||
auto GetSections() const -> const std::vector<Section>& { return sections; }
|
||||
};
|
||||
|
||||
struct TracksResponse {
|
||||
std::vector<Track> tracks;
|
||||
};
|
||||
} // namespace Spotify
|
||||
|
||||
// ============================================================================
|
||||
// Glaze Metadata
|
||||
// ============================================================================
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::SimplifiedTrack> {
|
||||
using T = Spotify::SimplifiedTrack;
|
||||
static constexpr auto value = object(
|
||||
"artists", &T::artists,
|
||||
"available_markets", &T::available_markets,
|
||||
"disc_number", &T::disc_number,
|
||||
"duration_ms", &T::duration_ms,
|
||||
"explicit", &T::explicit_content,
|
||||
"external_urls", &T::external_urls,
|
||||
"href", &T::href,
|
||||
"id", &T::id,
|
||||
"is_playable", &T::is_playable,
|
||||
"linked_from", &T::linked_from,
|
||||
"restrictions", &T::restrictions,
|
||||
"name", &T::name,
|
||||
"preview_url", &T::preview_url,
|
||||
"track_number", &T::track_number,
|
||||
"type", &T::type,
|
||||
"uri", &T::uri,
|
||||
"is_local", &T::is_local
|
||||
);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::Track> {
|
||||
using T = Spotify::Track;
|
||||
static constexpr auto value = object(
|
||||
"album", &T::album,
|
||||
"artists", &T::artists,
|
||||
"available_markets", &T::available_markets,
|
||||
"disc_number", &T::disc_number,
|
||||
"duration_ms", &T::duration_ms,
|
||||
"explicit", &T::explicit_content,
|
||||
"external_ids", &T::external_ids,
|
||||
"external_urls", &T::external_urls,
|
||||
"href", &T::href,
|
||||
"id", &T::id,
|
||||
"is_playable", &T::is_playable,
|
||||
"linked_from", &T::linked_from,
|
||||
"restrictions", &T::restrictions,
|
||||
"name", &T::name,
|
||||
"popularity", &T::popularity,
|
||||
"preview_url", &T::preview_url,
|
||||
"track_number", &T::track_number,
|
||||
"type", &T::type,
|
||||
"uri", &T::uri,
|
||||
"is_local", &T::is_local
|
||||
);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::SavedTrack> {
|
||||
using T = Spotify::SavedTrack;
|
||||
static constexpr auto value = object(
|
||||
"added_at", &T::added_at,
|
||||
"track", &T::track
|
||||
);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::AudioFeatures> {
|
||||
using T = Spotify::AudioFeatures;
|
||||
static constexpr auto value = object(
|
||||
"acousticness", &T::acousticness,
|
||||
"analysis_url", &T::analysis_url,
|
||||
"danceability", &T::danceability,
|
||||
"duration_ms", &T::duration_ms,
|
||||
"energy", &T::energy,
|
||||
"id", &T::id,
|
||||
"instrumentalness", &T::instrumentalness,
|
||||
"key", &T::key,
|
||||
"liveness", &T::liveness,
|
||||
"loudness", &T::loudness,
|
||||
"mode", &T::mode,
|
||||
"speechiness", &T::speechiness,
|
||||
"tempo", &T::tempo,
|
||||
"time_signature", &T::time_signature,
|
||||
"track_href", &T::track_href,
|
||||
"type", &T::type,
|
||||
"uri", &T::uri,
|
||||
"valence", &T::valence
|
||||
);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::TimeInterval> {
|
||||
using T = Spotify::TimeInterval;
|
||||
static constexpr auto value = object(
|
||||
"start", &T::start,
|
||||
"duration", &T::duration,
|
||||
"confidence", &T::confidence
|
||||
);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::Section> {
|
||||
using T = Spotify::Section;
|
||||
static constexpr auto value = object(
|
||||
"start", &T::start,
|
||||
"duration", &T::duration,
|
||||
"confidence", &T::confidence,
|
||||
"loudness", &T::loudness,
|
||||
"tempo", &T::tempo,
|
||||
"tempo_confidence", &T::tempo_confidence,
|
||||
"key", &T::key,
|
||||
"key_confidence", &T::key_confidence,
|
||||
"mode", &T::mode,
|
||||
"mode_confidence", &T::mode_confidence,
|
||||
"time_signature", &T::time_signature,
|
||||
"time_signature_confidence", &T::time_signature_confidence
|
||||
);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::Segment> {
|
||||
using T = Spotify::Segment;
|
||||
static constexpr auto value = object(
|
||||
"start", &T::start,
|
||||
"duration", &T::duration,
|
||||
"confidence", &T::confidence,
|
||||
"loudness_start", &T::loudness_start,
|
||||
"loudness_max", &T::loudness_max,
|
||||
"loudness_max_time", &T::loudness_max_time,
|
||||
"loudness_end", &T::loudness_end,
|
||||
"pitches", &T::pitches,
|
||||
"timbre", &T::timbre
|
||||
);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::AudioAnalysis> {
|
||||
using T = Spotify::AudioAnalysis;
|
||||
static constexpr auto value = object(
|
||||
"bars", &T::bars,
|
||||
"beats", &T::beats,
|
||||
"sections", &T::sections,
|
||||
"segments", &T::segments,
|
||||
"tatums", &T::tatums
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,77 @@
|
||||
#pragma once
|
||||
#include "Spotify/Types/Common.hpp"
|
||||
|
||||
namespace Spotify {
|
||||
|
||||
// ============================================================================
|
||||
// User Product Type
|
||||
// ============================================================================
|
||||
|
||||
enum class Product {
|
||||
Premium,
|
||||
Free,
|
||||
Open,
|
||||
Unknown
|
||||
};
|
||||
|
||||
inline auto StringToProductType(const std::string& str) -> Product {
|
||||
if (str == "premium") return Product::Premium;
|
||||
if (str == "free") return Product::Free;
|
||||
if (str == "open") return Product::Open;
|
||||
return Product::Unknown;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// User
|
||||
// ============================================================================
|
||||
|
||||
struct User {
|
||||
std::optional<std::string> country;
|
||||
std::optional<std::string> display_name;
|
||||
std::optional<std::string> email;
|
||||
std::optional<ExternalUrls> external_urls;
|
||||
std::optional<Followers> followers;
|
||||
std::string href;
|
||||
std::string id;
|
||||
std::optional<std::vector<Image>> images;
|
||||
std::optional<std::string> product;
|
||||
std::string type;
|
||||
std::string uri;
|
||||
|
||||
auto GetId() const -> const std::string& { return id; }
|
||||
auto GetDisplayName() const -> const std::optional<std::string>& { return display_name; }
|
||||
auto GetEmail() const -> const std::optional<std::string>& { return email; }
|
||||
auto GetUri() const -> const std::string& { return uri; }
|
||||
|
||||
auto GetProductType() const -> Product {
|
||||
if (!product) return Product::Unknown;
|
||||
return StringToProductType(*product);
|
||||
}
|
||||
|
||||
auto IsPremium() const -> bool {
|
||||
return GetProductType() == Product::Premium;
|
||||
}
|
||||
};
|
||||
} // namespace Spotify
|
||||
|
||||
// ============================================================================
|
||||
// Glaze Metadata
|
||||
// ============================================================================
|
||||
|
||||
template <>
|
||||
struct glz::meta<Spotify::User> {
|
||||
using T = Spotify::User;
|
||||
static constexpr auto value = object(
|
||||
"country", &T::country,
|
||||
"display_name", &T::display_name,
|
||||
"email", &T::email,
|
||||
"external_urls", &T::external_urls,
|
||||
"followers", &T::followers,
|
||||
"href", &T::href,
|
||||
"id", &T::id,
|
||||
"images", &T::images,
|
||||
"product", &T::product,
|
||||
"type", &T::type,
|
||||
"uri", &T::uri
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,274 @@
|
||||
#pragma once
|
||||
// Standard Library
|
||||
#include <expected>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Third Party
|
||||
#include "cpr/cprtypes.h"
|
||||
#include "cpr/parameters.h"
|
||||
#include <curl/curl.h>
|
||||
#include <glaze/glaze.hpp> // Assumed available per your reference
|
||||
#include <quickjs.h>
|
||||
// Project (Assuming similar structure to your Spotify bot)
|
||||
#include <ts6bot/Proxy.hpp>
|
||||
|
||||
#include <PluginDefinitions.hpp>
|
||||
|
||||
namespace YouTube {
|
||||
|
||||
// ============================================================================
|
||||
// Data Types (Simplified for immediate usage)
|
||||
// ============================================================================
|
||||
|
||||
struct Thumbnail {
|
||||
std::string url;
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
|
||||
struct Snippet {
|
||||
std::string publishedAt;
|
||||
std::string channelId;
|
||||
std::string title;
|
||||
std::string description;
|
||||
std::string channelTitle;
|
||||
std::map<std::string, Thumbnail> thumbnails;
|
||||
std::string liveBroadcastContent;
|
||||
std::string publishTime;
|
||||
};
|
||||
|
||||
struct ResourceId {
|
||||
std::string kind;
|
||||
std::string videoId;
|
||||
std::string channelId;
|
||||
std::string playlistId;
|
||||
};
|
||||
|
||||
// Search results use a wrapper for ID, Videos use a string ID
|
||||
struct SearchResultId {
|
||||
std::string kind;
|
||||
std::string videoId;
|
||||
std::string channelId;
|
||||
std::string playlistId;
|
||||
};
|
||||
|
||||
struct VideoContentDetails {
|
||||
std::string duration;
|
||||
std::string dimension;
|
||||
std::string definition;
|
||||
};
|
||||
|
||||
struct VideoStatistics {
|
||||
std::string viewCount;
|
||||
std::string likeCount;
|
||||
std::string commentCount;
|
||||
};
|
||||
|
||||
// Main Resource Types
|
||||
struct Video {
|
||||
std::string kind;
|
||||
std::string id;
|
||||
Snippet snippet;
|
||||
VideoContentDetails contentDetails;
|
||||
VideoStatistics statistics;
|
||||
};
|
||||
|
||||
struct SearchResult {
|
||||
std::string kind;
|
||||
std::string etag;
|
||||
SearchResultId id;
|
||||
Snippet snippet;
|
||||
};
|
||||
|
||||
// API Response Wrappers
|
||||
template <typename T> struct PageResult {
|
||||
std::string kind;
|
||||
std::string etag;
|
||||
std::string nextPageToken;
|
||||
std::string prevPageToken;
|
||||
std::string regionCode;
|
||||
struct PageInfo {
|
||||
int totalResults;
|
||||
int resultsPerPage;
|
||||
} pageInfo;
|
||||
std::vector<T> items;
|
||||
};
|
||||
// ============================================================================
|
||||
// InnerTube (Player) Data Types
|
||||
// ============================================================================
|
||||
|
||||
struct AudioFormat {
|
||||
int itag;
|
||||
std::string url; // Direct URL (if unencrypted)
|
||||
std::string signatureCipher; // Encrypted signature (if present, url is empty)
|
||||
std::string mimeType;
|
||||
int bitrate;
|
||||
std::string qualityLabel;
|
||||
};
|
||||
|
||||
struct StreamingData {
|
||||
std::string expiresInSeconds;
|
||||
std::vector<AudioFormat> formats; // Mixed video+audio
|
||||
std::vector<AudioFormat>
|
||||
adaptiveFormats; // Separate streams (we want audio from here)
|
||||
};
|
||||
|
||||
struct PlayerResponse {
|
||||
StreamingData streamingData;
|
||||
// ... other fields like playabilityStatus ignored for brevity
|
||||
};
|
||||
// ============================================================================
|
||||
// Error Handling
|
||||
// ============================================================================
|
||||
|
||||
struct ApiError {
|
||||
int status;
|
||||
std::string message;
|
||||
std::string reason;
|
||||
};
|
||||
struct GoogleError {
|
||||
struct Inner {
|
||||
int code;
|
||||
std::string message;
|
||||
} error;
|
||||
};
|
||||
template <typename T> using Result = std::expected<T, ApiError>;
|
||||
// ============================================================================
|
||||
// Request Parameters
|
||||
// ============================================================================
|
||||
|
||||
struct SearchParams {
|
||||
std::string q;
|
||||
std::vector<std::string> type = {"video"}; // video, channel, playlist
|
||||
std::string part = "snippet";
|
||||
int maxResults = 5;
|
||||
std::string order = "relevance";
|
||||
std::string pageToken = "";
|
||||
std::string videoDuration = "any"; // any, long, medium, short
|
||||
bool rawQuery = false; // Set to true to preserve -, |, etc. in query
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Main YouTube Client
|
||||
// ============================================================================
|
||||
|
||||
struct CurlDeleter {
|
||||
void operator()(CURL *ptr) const {
|
||||
if (ptr)
|
||||
curl_easy_cleanup(ptr);
|
||||
}
|
||||
};
|
||||
|
||||
enum class HttpMethod { GET, POST, PUT, DELETE };
|
||||
|
||||
class Client {
|
||||
public:
|
||||
// YouTube typically uses API Keys for public data, OAuth for user data.
|
||||
// Pass "" as accessToken if only using API Key.
|
||||
Client(std::string apiKey, std::string accessToken = "");
|
||||
~Client();
|
||||
auto GetBestStreams(const std::string &videoId)
|
||||
-> Result<::definitions::Streams>; // Configuration
|
||||
void SetVerbose(bool verbose) { m_Verbose = verbose; }
|
||||
void SetProxy(ProxyConfig config) { m_Proxy = std::move(config); }
|
||||
void SetAccessToken(std::string token) { m_AccessToken = std::move(token); }
|
||||
void SetApiKey(std::string key) { m_ApiKey = std::move(key); }
|
||||
|
||||
// ========================================================================
|
||||
// Search API
|
||||
// ========================================================================
|
||||
|
||||
// https://developers.google.com/youtube/v3/docs/search/list
|
||||
auto Search(const SearchParams ¶ms) -> Result<PageResult<SearchResult>>;
|
||||
|
||||
// ========================================================================
|
||||
// Videos API
|
||||
// ========================================================================
|
||||
|
||||
// https://developers.google.com/youtube/v3/docs/videos/list
|
||||
auto GetVideo(const std::string &id,
|
||||
const std::string &part = "snippet,contentDetails,statistics")
|
||||
-> Result<Video>;
|
||||
|
||||
auto GetVideos(const std::vector<std::string> &ids,
|
||||
const std::string &part = "snippet,contentDetails,statistics")
|
||||
-> Result<std::vector<Video>>;
|
||||
|
||||
// ========================================================================
|
||||
// Channels API
|
||||
// ========================================================================
|
||||
|
||||
// https://developers.google.com/youtube/v3/docs/channels/list
|
||||
auto GetChannel(const std::string &id,
|
||||
const std::string &part = "snippet,statistics")
|
||||
-> Result<std::string>; // Returns raw JSON for brevity in this example
|
||||
|
||||
// ========================================================================
|
||||
// Playlists API
|
||||
// ========================================================================
|
||||
|
||||
// https://developers.google.com/youtube/v3/docs/playlistItems/list
|
||||
auto GetPlaylistItems(const std::string &playlistId,
|
||||
const std::string &pageToken = "")
|
||||
-> Result<PageResult<SearchResult>>; // Reusing SearchResult as structure
|
||||
// is similar enough for snippet
|
||||
// ========================================================================
|
||||
// Player API (The "Extraction" Logic)
|
||||
// ========================================================================
|
||||
|
||||
// Returns a raw https://googlevideo.com/... URL for the audio stream.
|
||||
// Returns error if the video is region locked or requires signature
|
||||
// deciphering.
|
||||
auto GetAudioStreamUrl(const std::string &videoId) -> Result<std::string>;
|
||||
|
||||
auto ExtractVideoId(std::string_view url) const -> std::optional<std::string>;
|
||||
|
||||
private:
|
||||
std::string m_ApiKey;
|
||||
std::string m_AccessToken;
|
||||
ProxyConfig m_Proxy;
|
||||
bool m_Verbose = false;
|
||||
const std::string m_BaseUrl = "https://www.googleapis.com/youtube/v3";
|
||||
JSRuntime *m_rt;
|
||||
JSContext *m_ctx;
|
||||
std::string m_preprocessedPlayer;
|
||||
|
||||
// Helper methods for the solver logic
|
||||
void InitSolver();
|
||||
void SetPlayerJs(const std::string &js);
|
||||
std::string SolveChallenge(const std::string &challenge,
|
||||
const std::string &type);
|
||||
auto PerformRequest(
|
||||
const std::string &purl, const std::string &endpoint,
|
||||
const cpr::Parameters ¶ms = {},
|
||||
const cpr::Header &headers =
|
||||
{{"Content-Type", "application/json"},
|
||||
{"User-Agent",
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"}},
|
||||
HttpMethod method = HttpMethod::GET, const std::string &body = "")
|
||||
-> Result<std::string>;
|
||||
|
||||
auto PerformRequest(
|
||||
const std::string &endpoint, const cpr::Parameters ¶ms = {},
|
||||
const cpr::Header &headers =
|
||||
{{"Content-Type", "application/json"},
|
||||
{"User-Agent",
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"}},
|
||||
HttpMethod method = HttpMethod::GET, const std::string &body = "")
|
||||
-> Result<std::string>;
|
||||
// Helper specifically for the internal YouTube API (different Base URL)
|
||||
auto PerformInternalRequest(const std::string &endpoint,
|
||||
const std::string &jsonBody)
|
||||
-> Result<std::string>;
|
||||
static auto WriteCallback(void *contents, size_t size, size_t nmemb,
|
||||
std::string *out) -> size_t;
|
||||
auto UrlEncode(std::string_view value) const -> std::string;
|
||||
auto UrlEncodePreservingOperators(std::string_view query) const
|
||||
-> std::string;
|
||||
};
|
||||
|
||||
} // namespace YouTube
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <deque>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavformat/avformat.h>
|
||||
#include <libavutil/opt.h>
|
||||
#include <libswresample/swresample.h>
|
||||
}
|
||||
enum class DecodeStatus { Idle, Processing, Completed, Failed, Cancelled };
|
||||
class AudioDecoder {
|
||||
public:
|
||||
struct AudioData {
|
||||
std::vector<short> buffer;
|
||||
int samples = 0;
|
||||
int channels = 0;
|
||||
int sampleRate = 0;
|
||||
};
|
||||
std::deque<std::vector<short>> m_chunkQueue;
|
||||
std::mutex m_queueMtx;
|
||||
std::condition_variable m_cv;
|
||||
std::atomic<bool> m_isDecodingFinished{false};
|
||||
AudioDecoder();
|
||||
~AudioDecoder();
|
||||
void StartDecode(const std::string &url, int targetSampleRate);
|
||||
void Cancel() { m_cancelRequested = true; }
|
||||
DecodeStatus GetStatus() const { return m_status; }
|
||||
AudioData GetResult() { return std::move(m_result); }
|
||||
bool GetNextChunk(std::vector<short> &outChunk, bool blocking = false);
|
||||
bool IsFinished() const { return m_finished.load(); }
|
||||
|
||||
private:
|
||||
void Log(const std::string &msg) {
|
||||
std::lock_guard<std::mutex> lock(m_logMtx);
|
||||
std::cout << "[AudioDecoder] " << msg << std::endl;
|
||||
}
|
||||
void Cleanup();
|
||||
void InternalDecode(std::string url, int targetSampleRate);
|
||||
std::atomic<DecodeStatus> m_status{DecodeStatus::Idle};
|
||||
std::atomic<bool> m_cancelRequested{false};
|
||||
std::jthread m_thread;
|
||||
std::mutex m_logMtx;
|
||||
AudioData m_result;
|
||||
std::atomic<bool> m_finished{false};
|
||||
AVFormatContext *m_formatCtx = nullptr;
|
||||
AVCodecContext *m_codecCtx = nullptr;
|
||||
SwrContext *m_swrCtx = nullptr;
|
||||
};
|
||||
@@ -0,0 +1,118 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <singleton_atomic.hpp>
|
||||
#include <string>
|
||||
#include <ts6bot/Proxy.hpp>
|
||||
|
||||
#include <glaze/glaze.hpp>
|
||||
|
||||
namespace ts6bot {
|
||||
|
||||
enum class LogLevel { Critical, Error, Warning, Info, Trace };
|
||||
|
||||
struct ServerQueryConfig {
|
||||
std::string host{"127.0.0.1"};
|
||||
uint16_t port{
|
||||
10022}; // ServerQuery SSH default :contentReference[oaicite:6]{index=6}
|
||||
std::string username{"serveradmin"};
|
||||
std::string password{};
|
||||
int virtual_server_id{1};
|
||||
std::string nickname{"ts6bot"};
|
||||
};
|
||||
|
||||
struct AfkConfig {
|
||||
bool enabled{true};
|
||||
int idle_seconds{600};
|
||||
std::uint64_t afk_channel_id{0};
|
||||
int poll_interval_ms{5000};
|
||||
};
|
||||
|
||||
struct MusicConfig {
|
||||
bool enabled{true};
|
||||
std::string youtubeApiToken;
|
||||
};
|
||||
|
||||
struct ProxyConfiguration : public ProxyConfig {
|
||||
bool enabled{false};
|
||||
};
|
||||
|
||||
struct Config {
|
||||
std::string nickname;
|
||||
std::string host;
|
||||
std::string channel;
|
||||
std::string password;
|
||||
LogLevel loggingLevel;
|
||||
AfkConfig afk{};
|
||||
MusicConfig music{};
|
||||
ProxyConfiguration proxy{};
|
||||
};
|
||||
|
||||
class Configuration : public SingletonAtomic<Configuration> {
|
||||
public:
|
||||
const Config getConfig() const noexcept { return m_config; }
|
||||
|
||||
Configuration(std::string path) {
|
||||
auto config = Config();
|
||||
std::string buffer;
|
||||
auto ec = glz::read_file_json(config, path, buffer);
|
||||
if (ec) {
|
||||
std::string descriptive_error = glz::format_error(ec, buffer);
|
||||
std::cerr << "Not found configuration in " << path << " using default"
|
||||
<< std::endl;
|
||||
std::cerr << descriptive_error << std::endl;
|
||||
std::cerr << ec.ec << std::endl;
|
||||
m_config = Config();
|
||||
}
|
||||
this->m_config = config;
|
||||
}
|
||||
|
||||
Config m_config{};
|
||||
};
|
||||
|
||||
// Glaze meta (explicit, stable)
|
||||
|
||||
} // namespace ts6bot
|
||||
template <> struct glz::meta<ProxyType> {
|
||||
using enum ProxyType;
|
||||
static constexpr auto value = enumerate(HTTP, SOCKS5, SOCKS5_HOSTNAME);
|
||||
};
|
||||
template <> struct glz::meta<ts6bot::LogLevel> {
|
||||
using enum ts6bot::LogLevel;
|
||||
static constexpr auto value =
|
||||
enumerate(Critical, Error, Warning, Info, Trace);
|
||||
};
|
||||
template <> struct glz::meta<ts6bot::ServerQueryConfig> {
|
||||
using T = ts6bot::ServerQueryConfig;
|
||||
static constexpr auto value =
|
||||
object("host", &T::host, "port", &T::port, "username", &T::username,
|
||||
"password", &T::password, "virtual_server_id",
|
||||
&T::virtual_server_id, "nickname", &T::nickname);
|
||||
};
|
||||
|
||||
template <> struct glz::meta<ts6bot::AfkConfig> {
|
||||
using T = ts6bot::AfkConfig;
|
||||
static constexpr auto value =
|
||||
object("enabled", &T::enabled, "idle_seconds", &T::idle_seconds,
|
||||
"afk_channel_id", &T::afk_channel_id, "poll_interval_ms",
|
||||
&T::poll_interval_ms);
|
||||
};
|
||||
|
||||
template <> struct glz::meta<ts6bot::MusicConfig> {
|
||||
using T = ts6bot::MusicConfig;
|
||||
static constexpr auto value =
|
||||
object("enabled", &T::enabled, "youtubeApiToken", &T::youtubeApiToken);
|
||||
};
|
||||
template <> struct glz::meta<ts6bot::ProxyConfiguration> {
|
||||
using T = ts6bot::ProxyConfiguration;
|
||||
static constexpr auto value =
|
||||
object("url", &T::url, "username", &T::username, "password", &T::password,
|
||||
"type", &T::type, "enabled", &T::enabled);
|
||||
};
|
||||
template <> struct glz::meta<ts6bot::Config> {
|
||||
using T = ts6bot::Config;
|
||||
static constexpr auto value =
|
||||
object("nickname", &T::nickname, "host", &T::host, "channel", &T::channel,
|
||||
"password", &T::password, "loggingLevel", &T::loggingLevel, "afk",
|
||||
&T::afk, "music", &T::music, "proxy", &T::proxy);
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace ts6bot::crypto {
|
||||
|
||||
// RFC 7636: length 43..128, chars [A-Z a-z 0-9 - . _ ~]
|
||||
std::string GenerateCodeVerifier(std::size_t length = 64);
|
||||
|
||||
// Random state value (base64url, no padding).
|
||||
std::string GenerateState(std::size_t bytes = 16);
|
||||
|
||||
std::vector<std::uint8_t> Sha256(std::span<const std::uint8_t> data);
|
||||
std::vector<std::uint8_t> Sha256(std::span<const char> data);
|
||||
|
||||
// Base64url encode without padding.
|
||||
std::string Base64UrlEncode(std::span<const std::uint8_t> data);
|
||||
|
||||
} // namespace ts6bot::crypto
|
||||
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include <string_view>
|
||||
|
||||
#include "quill/Backend.h"
|
||||
#include "quill/Frontend.h"
|
||||
#include "quill/LogMacros.h"
|
||||
#include "quill/Logger.h"
|
||||
#include "quill/sinks/FileSink.h"
|
||||
#include "quill/sinks/ConsoleSink.h"
|
||||
|
||||
namespace ts6bot {
|
||||
|
||||
class Log {
|
||||
public:
|
||||
static void init(std::string_view file_path);
|
||||
static quill::Logger* logger();
|
||||
|
||||
private:
|
||||
static quill::Logger* g_logger;
|
||||
};
|
||||
|
||||
} // namespace ts6bot
|
||||
@@ -0,0 +1,100 @@
|
||||
#include <optional>
|
||||
|
||||
#include "PluginDefinitions.hpp"
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Youtube/Client.hpp"
|
||||
#include <atomic>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <set>
|
||||
#include <singleton_atomic.hpp>
|
||||
#include <string>
|
||||
#include <teamspeak/public_definitions.h>
|
||||
#include <thread>
|
||||
#include <ts3_functions.h>
|
||||
#include <ts6bot/AudioDecoder.hpp>
|
||||
#include <quill/Logger.h>
|
||||
#include <quill/LogMacros.h>
|
||||
#include <vector>
|
||||
class MusicManager {
|
||||
public:
|
||||
explicit MusicManager(std::shared_ptr<TS3Functions> functions, quill::Logger* logger, std::uint64_t serverConnectionHandlerID = 0);
|
||||
~MusicManager();
|
||||
|
||||
struct Music {
|
||||
std::string name;
|
||||
std::string videoId;
|
||||
std::string requestedBy;
|
||||
YouTube::Result<definitions::Streams> streams;
|
||||
};
|
||||
|
||||
// Playback Control
|
||||
void stop();
|
||||
void skip();
|
||||
void forceSkip();
|
||||
void setStopAfterCurrent(bool val) { m_stopAfterCurrent = val; }
|
||||
bool isIdle() const { return m_isIdle; }
|
||||
std::uint64_t getServerConnectionHandlerID() const
|
||||
{return m_serverConnectionHandlerID; }
|
||||
void setServerConnectionHandlerID(std::uint64_t id) { m_serverConnectionHandlerID = id; }
|
||||
// Subscription (Whisper) Management
|
||||
void subscribe(anyID id);
|
||||
void moveSubscriberToOffline(anyID id);
|
||||
void moveSubscriberToOnline(anyID id);
|
||||
void addSubscriberToOnline(anyID id);
|
||||
void addSubscriberToOffline(anyID id);
|
||||
void unSubscribe(anyID id);
|
||||
std::set<uint64_t> getOnlineSubscribers() const;
|
||||
std::set<uint64_t> getOfflineSubscribers() const;
|
||||
// Queue Management
|
||||
std::vector<Music> getQueue() const;
|
||||
std::optional<Music> getCurrent() const { return m_current; }
|
||||
void removeFromQueue(std::size_t index);
|
||||
void removeFromQueue(const std::string &name);
|
||||
void addToQueueDirect(const std::string& vid, const std::string& title, const std::string& req, std::optional<definitions::Streams> streams);
|
||||
void checkQueueAndPlay();
|
||||
|
||||
// Youtube / Search
|
||||
std::vector<definitions::SearchResultItem> search(std::string name, int maxResults = 5) const;
|
||||
void playUrl(std::string url, const std::string &requester = "");
|
||||
|
||||
// Selection Logic
|
||||
// Stores the results for a specific user to select later
|
||||
void storePendingSearch(anyID clientId,
|
||||
const std::vector<definitions::SearchResultItem> &results);
|
||||
bool selectSearchResult(anyID clientId, int index, const std::string& requesterName);
|
||||
|
||||
private:
|
||||
void loop(std::stop_token st);
|
||||
static std::string formatDuration(const std::string &isoDuration);
|
||||
void updateWhisperList();
|
||||
|
||||
quill::Logger* m_logger;
|
||||
std::shared_ptr<TS3Functions> m_functions{nullptr};
|
||||
std::unique_ptr<AudioDecoder> m_microphone{nullptr};
|
||||
std::unique_ptr<YouTube::Client> m_client{nullptr};
|
||||
|
||||
|
||||
std::atomic<bool> m_stopAfterCurrent{false};
|
||||
std::atomic<bool> m_isIdle{true};
|
||||
|
||||
std::deque<Music> m_queue{};
|
||||
mutable std::mutex m_queueMtx;
|
||||
std::condition_variable m_cv;
|
||||
|
||||
std::set<anyID> m_onlineSubscribers;
|
||||
std::set<anyID> m_offlineSubscribers;
|
||||
// Playback Control
|
||||
std::atomic_bool m_skipRequested{false};
|
||||
|
||||
std::atomic<float> m_volume{0.5f}; // Default 50%
|
||||
std::uint64_t m_serverConnectionHandlerID = 0;
|
||||
std::optional<Music> m_current;
|
||||
std::mutex m_subMtx;
|
||||
std::map<anyID, std::vector<definitions::SearchResultItem>> m_pendingSearches;
|
||||
std::mutex m_pendingMtx;
|
||||
std::jthread m_worker;
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
enum class ProxyType {
|
||||
HTTP,
|
||||
SOCKS5,
|
||||
SOCKS5_HOSTNAME // Use this to let the proxy resolve the DNS
|
||||
};
|
||||
struct ProxyConfig {
|
||||
std::string url;
|
||||
ProxyType type = ProxyType::SOCKS5_HOSTNAME;
|
||||
std::string username = "";
|
||||
std::string password = "";
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include <functional>
|
||||
#include <thread>
|
||||
|
||||
class SignalShutdown {
|
||||
public:
|
||||
explicit SignalShutdown(std::function<void()> onShutdown);
|
||||
~SignalShutdown();
|
||||
|
||||
SignalShutdown(const SignalShutdown&) = delete;
|
||||
SignalShutdown& operator=(const SignalShutdown&) = delete;
|
||||
|
||||
private:
|
||||
std::function<void()> m_OnShutdown;
|
||||
std::thread m_Thread;
|
||||
bool m_Running = true;
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace ts6bot::url {
|
||||
|
||||
// Percent-encode a string for use as a query parameter value.
|
||||
std::string EncodeComponent(const std::string& s);
|
||||
|
||||
struct HttpUrl {
|
||||
std::string host;
|
||||
uint16_t port{};
|
||||
std::string path; // begins with '/'
|
||||
};
|
||||
|
||||
// Minimal parser for redirect URIs.
|
||||
// Supports: http://<host>:<port>/<path>
|
||||
// Throws std::runtime_error on invalid input.
|
||||
HttpUrl ParseHttpUrl(const std::string& httpUrl);
|
||||
|
||||
} // namespace ts6bot::url
|
||||
@@ -0,0 +1,114 @@
|
||||
#pragma once
|
||||
|
||||
#include "Spotify/Client.hpp"
|
||||
#include <gst/gst.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <print>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
struct GstObjectDeleter {
|
||||
void operator()(gpointer ptr) const noexcept {
|
||||
if (ptr)
|
||||
gst_object_unref(ptr);
|
||||
}
|
||||
};
|
||||
|
||||
struct GstMessageDeleter {
|
||||
void operator()(GstMessage *msg) const noexcept {
|
||||
if (msg)
|
||||
gst_message_unref(msg);
|
||||
}
|
||||
};
|
||||
|
||||
class VirtualMicrophone {
|
||||
public:
|
||||
// micName: what apps will see/select (e.g. "StudioMic")
|
||||
explicit VirtualMicrophone(std::string micName, bool createNew);
|
||||
~VirtualMicrophone() noexcept;
|
||||
|
||||
// Play Spotify track via gstspotify spotifyaudiosrc and route into the
|
||||
// virtual microphone.
|
||||
void PlayUri(const std::string &trackUri, const std::string &token,
|
||||
const ProxyConfig &proxy);
|
||||
void PlayUri(const std::string &trackUri,
|
||||
const std::optional<ProxyConfig> proxy);
|
||||
// Playback control
|
||||
void Pause();
|
||||
void Resume();
|
||||
void StopPlayback(); // stops pipeline (does not destroy devices)
|
||||
void WaitUntilFinished(); // waits EOS or ERROR; throws on ERROR
|
||||
|
||||
// Device control (normally you don't call these directly)
|
||||
void DestroyDevices() noexcept;
|
||||
|
||||
// For debugging / integration
|
||||
[[nodiscard]] const std::string &MicName() const noexcept {
|
||||
return m_MicName;
|
||||
}
|
||||
[[nodiscard]] const std::string &BusSinkName() const noexcept {
|
||||
return m_BusSinkName;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_MicName; // virtual mic node name (Audio/Source/Virtual)
|
||||
std::string m_BusSinkName; // bus sink name (Audio/Sink)
|
||||
|
||||
// Pulse/PipeWire module ids
|
||||
uint32_t m_ModBusSink = 0;
|
||||
uint32_t m_ModVirtualMic = 0;
|
||||
|
||||
// pw-link ports we connected (for disconnection)
|
||||
std::optional<std::string> m_LinkOutFL;
|
||||
std::optional<std::string> m_LinkOutFR;
|
||||
std::optional<std::string> m_LinkInFL;
|
||||
std::optional<std::string> m_LinkInFR;
|
||||
|
||||
// GStreamer pipeline
|
||||
std::unique_ptr<GstElement, GstObjectDeleter> m_Pipeline;
|
||||
std::jthread m_BusThread;
|
||||
|
||||
// completion signalling
|
||||
std::mutex m_Mtx;
|
||||
std::condition_variable m_Cv;
|
||||
bool m_Finished = true;
|
||||
bool m_HadError = false;
|
||||
std::string m_LastError;
|
||||
|
||||
private:
|
||||
// startup behavior
|
||||
void CleanupStaleDevicesByName();
|
||||
|
||||
// create routing: bus sink + virtual mic + pw-link
|
||||
void CreateDevices();
|
||||
void CreateLinks();
|
||||
|
||||
// pipeline lifecycle
|
||||
void BuildAndStartPipeline(const std::string &pipelineDesc);
|
||||
void WatchBus(std::stop_token st);
|
||||
|
||||
// utilities
|
||||
static std::string RunCommandCapture(const std::string &cmd);
|
||||
static int RunCommandNoCapture(const std::string &cmd);
|
||||
static uint32_t ParseFirstUint(std::string_view s);
|
||||
|
||||
static std::vector<std::string> SplitLines(const std::string &s);
|
||||
static bool Contains(std::string_view hay, std::string_view needle);
|
||||
|
||||
// pw-link helpers
|
||||
static std::vector<std::string> PwLinkListOutputs();
|
||||
static std::vector<std::string> PwLinkListInputs();
|
||||
static std::optional<std::string>
|
||||
FindPortPrefix(const std::vector<std::string> &list, std::string_view prefix,
|
||||
std::string_view suffix);
|
||||
};
|
||||
Reference in new issue
Block a user