Initial commit

This commit is contained in:
faumaray committed 2026-01-18 18:22:09 +03:00
commit f6c5bcca39
52 files changed
+55449

No files matched your search

+332
View File
@@ -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 &params = {})
-> Result<PagingObject<SimplifiedTrack>>;
auto GetSavedAlbums(const Request::PaginationParams &params = {})
-> 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 &params = {})
-> 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 &params = {})
-> 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 &params = {})
-> 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 &params)
-> Result<Recommendations>;
// ========================================================================
// Search API
// ========================================================================
auto Search(const Request::SearchParams &params) -> Result<SearchResults>;
auto SearchTracks(const Request::TrackSearchFilters &filters,
const Request::PaginationParams &params = {})
-> Result<PagingObject<Track>>;
auto SearchAlbums(const Request::AlbumSearchFilters &filters,
const Request::PaginationParams &params = {})
-> Result<PagingObject<SimplifiedAlbum>>;
auto SearchArtists(const Request::ArtistSearchFilters &filters,
const Request::PaginationParams &params = {})
-> 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 &params = {})
-> Result<PagingObject<PlaylistTrack>>;
auto CreatePlaylist(const std::string &user_id,
const Request::CreatePlaylistParams &params)
-> Result<Playlist>;
auto UpdatePlaylist(const std::string &id,
const Request::UpdatePlaylistParams &params)
-> Result<void>;
auto AddTracksToPlaylist(const std::string &id,
const Request::AddTracksToPlaylistParams &params)
-> Result<std::string>;
auto RemoveTracksFromPlaylist(
const std::string &id,
const Request::RemoveTracksFromPlaylistParams &params)
-> Result<std::string>;
auto ReorderPlaylistTracks(const std::string &id,
const Request::ReorderPlaylistParams &params)
-> Result<std::string>;
auto ReplacePlaylistTracks(const std::string &id,
const Request::ReplacePlaylistTracksParams &params)
-> Result<void>;
auto GetCurrentUserPlaylists(const Request::PaginationParams &params = {})
-> Result<PagingObject<SimplifiedPlaylist>>;
auto GetUserPlaylists(const std::string &user_id,
const Request::PaginationParams &params = {})
-> Result<PagingObject<SimplifiedPlaylist>>;
auto GetFeaturedPlaylists(const Request::PaginationParams &params = {})
-> Result<PagingObject<SimplifiedPlaylist>>;
auto GetCategoryPlaylists(const std::string &category_id,
const Request::PaginationParams &params = {})
-> Result<PagingObject<SimplifiedPlaylist>>;
// ========================================================================
// User API
// ========================================================================
auto GetCurrentUser() -> Result<User>;
auto GetUser(const std::string &user_id) -> Result<User>;
auto GetTopArtists(const Request::TopItemsParams &params = {})
-> Result<PagingObject<Artist>>;
auto GetTopTracks(const Request::TopItemsParams &params = {})
-> Result<PagingObject<Track>>;
// ========================================================================
// Follow API
// ========================================================================
auto FollowArtistsOrUsers(const Request::FollowParams &params)
-> Result<void>;
auto UnfollowArtistsOrUsers(const Request::UnfollowParams &params)
-> Result<void>;
auto CheckFollowingArtistsOrUsers(const Request::CheckFollowingParams &params)
-> 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 &params = {})
-> 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 &params,
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 &params)
-> Result<void>;
auto AddToQueue(const Request::QueueParams &params) -> 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 &params = {})
-> 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> &params = {}) const
-> std::string;
auto BuildUrl(const std::string &endpoint,
const Request::RequestParams &params) 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
+57
View File
@@ -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
+496
View File
@@ -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
+178
View File
@@ -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
);
};
+84
View File
@@ -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
);
};
+185
View File
@@ -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
);
};
+133
View File
@@ -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
);
};
+218
View File
@@ -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
);
};
+139
View File
@@ -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
);
};
+318
View File
@@ -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
);
};
+77
View File
@@ -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
);
};