Format and .clang-format
This commit is contained in:
1 parent
6aed7b0027
commit
b94b634a87
47 files changed
+42341
-39711
No files matched your search
+262
-223
@@ -14,319 +14,358 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace Spotify {
|
||||
namespace Spotify
|
||||
{
|
||||
|
||||
// ============================================================================
|
||||
// Error Handling
|
||||
// ============================================================================
|
||||
// ============================================================================
|
||||
// Error Handling
|
||||
// ============================================================================
|
||||
|
||||
struct ApiError {
|
||||
int status;
|
||||
std::string message;
|
||||
std::string reason;
|
||||
struct ApiError {
|
||||
int status;
|
||||
std::string message;
|
||||
std::string reason;
|
||||
|
||||
auto GetStatus() const -> int { return status; }
|
||||
auto GetMessage() const -> const std::string & { return message; }
|
||||
};
|
||||
auto GetStatus() const -> int { return status; }
|
||||
auto GetMessage() const -> const std::string & { return message; }
|
||||
};
|
||||
|
||||
template <typename T> using Result = std::expected<T, ApiError>;
|
||||
template <typename T> using Result = std::expected<T, ApiError>;
|
||||
|
||||
// ============================================================================
|
||||
// HTTP Client Implementation Details
|
||||
// ============================================================================
|
||||
// ============================================================================
|
||||
// HTTP Client Implementation Details
|
||||
// ============================================================================
|
||||
|
||||
struct CurlDeleter {
|
||||
void operator()(CURL *ptr) const {
|
||||
if (ptr)
|
||||
curl_easy_cleanup(ptr);
|
||||
}
|
||||
};
|
||||
struct CurlDeleter {
|
||||
void operator()(CURL *ptr) const
|
||||
{
|
||||
if (ptr) {
|
||||
curl_easy_cleanup(ptr);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
enum class HttpMethod { GET, POST, PUT, DELETE };
|
||||
enum class HttpMethod { GET, POST, PUT, DELETE };
|
||||
|
||||
// ============================================================================
|
||||
// Main Spotify Client
|
||||
// ============================================================================
|
||||
// ============================================================================
|
||||
// Main Spotify Client
|
||||
// ============================================================================
|
||||
|
||||
class Client {
|
||||
public:
|
||||
Client(std::string accessToken);
|
||||
~Client() = default;
|
||||
class Client
|
||||
{
|
||||
public:
|
||||
|
||||
// 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); }
|
||||
Client(std::string accessToken);
|
||||
~Client() = default;
|
||||
|
||||
// ========================================================================
|
||||
// Albums API
|
||||
// ========================================================================
|
||||
// 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);
|
||||
}
|
||||
|
||||
auto GetAlbum(const std::string &id, std::optional<std::string> market = {})
|
||||
-> Result<Album>;
|
||||
// ========================================================================
|
||||
// Albums API
|
||||
// ========================================================================
|
||||
|
||||
auto GetAlbums(const std::vector<std::string> &ids,
|
||||
std::optional<std::string> market = {})
|
||||
-> Result<std::vector<Album>>;
|
||||
auto GetAlbum(const std::string &id,
|
||||
std::optional<std::string> market = {})
|
||||
-> Result<Album>;
|
||||
|
||||
auto GetAlbumTracks(const std::string &id,
|
||||
const Request::AlbumTracksParams ¶ms = {})
|
||||
-> Result<PagingObject<SimplifiedTrack>>;
|
||||
auto GetAlbums(const std::vector<std::string> &ids,
|
||||
std::optional<std::string> market = {})
|
||||
-> Result<std::vector<Album>>;
|
||||
|
||||
auto GetSavedAlbums(const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<SavedAlbum>>;
|
||||
auto GetAlbumTracks(const std::string &id,
|
||||
const Request::AlbumTracksParams ¶ms = {})
|
||||
-> Result<PagingObject<SimplifiedTrack>>;
|
||||
|
||||
auto SaveAlbums(const std::vector<std::string> &ids) -> Result<void>;
|
||||
auto GetSavedAlbums(const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<SavedAlbum>>;
|
||||
|
||||
auto RemoveSavedAlbums(const std::vector<std::string> &ids) -> Result<void>;
|
||||
auto SaveAlbums(const std::vector<std::string> &ids)
|
||||
-> Result<void>;
|
||||
|
||||
auto CheckSavedAlbums(const std::vector<std::string> &ids)
|
||||
-> Result<std::vector<bool>>;
|
||||
auto RemoveSavedAlbums(const std::vector<std::string> &ids)
|
||||
-> Result<void>;
|
||||
|
||||
auto GetNewReleases(const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<SimplifiedAlbum>>;
|
||||
auto CheckSavedAlbums(const std::vector<std::string> &ids)
|
||||
-> Result<std::vector<bool>>;
|
||||
|
||||
// ========================================================================
|
||||
// Artists API
|
||||
// ========================================================================
|
||||
auto GetNewReleases(const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<SimplifiedAlbum>>;
|
||||
|
||||
auto GetArtist(const std::string &id) -> Result<Artist>;
|
||||
// ========================================================================
|
||||
// Artists API
|
||||
// ========================================================================
|
||||
|
||||
auto GetArtists(const std::vector<std::string> &ids)
|
||||
-> Result<std::vector<Artist>>;
|
||||
auto GetArtist(const std::string &id) -> Result<Artist>;
|
||||
|
||||
auto GetArtistAlbums(const std::string &id,
|
||||
const Request::ArtistAlbumsParams ¶ms = {})
|
||||
-> Result<PagingObject<SimplifiedAlbum>>;
|
||||
auto GetArtists(const std::vector<std::string> &ids)
|
||||
-> Result<std::vector<Artist>>;
|
||||
|
||||
auto GetArtistTopTracks(const std::string &id, const std::string &market)
|
||||
-> Result<std::vector<Track>>;
|
||||
auto GetArtistAlbums(const std::string &id,
|
||||
const Request::ArtistAlbumsParams ¶ms = {})
|
||||
-> Result<PagingObject<SimplifiedAlbum>>;
|
||||
|
||||
auto GetArtistRelatedArtists(const std::string &id)
|
||||
-> Result<std::vector<Artist>>;
|
||||
auto GetArtistTopTracks(const std::string &id,
|
||||
const std::string &market)
|
||||
-> Result<std::vector<Track>>;
|
||||
|
||||
// ========================================================================
|
||||
// Tracks API
|
||||
// ========================================================================
|
||||
auto GetArtistRelatedArtists(const std::string &id)
|
||||
-> Result<std::vector<Artist>>;
|
||||
|
||||
auto GetTrack(const std::string &id, std::optional<std::string> market = {})
|
||||
-> Result<Track>;
|
||||
// ========================================================================
|
||||
// Tracks API
|
||||
// ========================================================================
|
||||
|
||||
auto GetTracks(const std::vector<std::string> &ids,
|
||||
std::optional<std::string> market = {})
|
||||
-> Result<std::vector<Track>>;
|
||||
auto GetTrack(const std::string &id,
|
||||
std::optional<std::string> market = {})
|
||||
-> Result<Track>;
|
||||
|
||||
auto GetSavedTracks(const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<SavedTrack>>;
|
||||
auto GetTracks(const std::vector<std::string> &ids,
|
||||
std::optional<std::string> market = {})
|
||||
-> Result<std::vector<Track>>;
|
||||
|
||||
auto SaveTracks(const std::vector<std::string> &ids) -> Result<void>;
|
||||
auto GetSavedTracks(const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<SavedTrack>>;
|
||||
|
||||
auto RemoveSavedTracks(const std::vector<std::string> &ids) -> Result<void>;
|
||||
auto SaveTracks(const std::vector<std::string> &ids)
|
||||
-> Result<void>;
|
||||
|
||||
auto CheckSavedTracks(const std::vector<std::string> &ids)
|
||||
-> Result<std::vector<bool>>;
|
||||
auto RemoveSavedTracks(const std::vector<std::string> &ids)
|
||||
-> Result<void>;
|
||||
|
||||
auto GetAudioFeatures(const std::string &id) -> Result<AudioFeatures>;
|
||||
auto CheckSavedTracks(const std::vector<std::string> &ids)
|
||||
-> Result<std::vector<bool>>;
|
||||
|
||||
auto GetAudioFeaturesForTracks(const std::vector<std::string> &ids)
|
||||
-> Result<std::vector<AudioFeatures>>;
|
||||
auto GetAudioFeatures(const std::string &id)
|
||||
-> Result<AudioFeatures>;
|
||||
|
||||
auto GetAudioAnalysis(const std::string &id) -> Result<AudioAnalysis>;
|
||||
auto GetAudioFeaturesForTracks(const std::vector<std::string> &ids)
|
||||
-> Result<std::vector<AudioFeatures>>;
|
||||
|
||||
auto GetRecommendations(const Request::RecommendationParams ¶ms)
|
||||
-> Result<Recommendations>;
|
||||
auto GetAudioAnalysis(const std::string &id)
|
||||
-> Result<AudioAnalysis>;
|
||||
|
||||
// ========================================================================
|
||||
// Search API
|
||||
// ========================================================================
|
||||
auto GetRecommendations(const Request::RecommendationParams ¶ms)
|
||||
-> Result<Recommendations>;
|
||||
|
||||
auto Search(const Request::SearchParams ¶ms) -> Result<SearchResults>;
|
||||
// ========================================================================
|
||||
// Search API
|
||||
// ========================================================================
|
||||
|
||||
auto SearchTracks(const Request::TrackSearchFilters &filters,
|
||||
const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<Track>>;
|
||||
auto Search(const Request::SearchParams ¶ms)
|
||||
-> Result<SearchResults>;
|
||||
|
||||
auto SearchAlbums(const Request::AlbumSearchFilters &filters,
|
||||
const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<SimplifiedAlbum>>;
|
||||
auto SearchTracks(const Request::TrackSearchFilters &filters,
|
||||
const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<Track>>;
|
||||
|
||||
auto SearchArtists(const Request::ArtistSearchFilters &filters,
|
||||
const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<Artist>>;
|
||||
auto SearchAlbums(const Request::AlbumSearchFilters &filters,
|
||||
const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<SimplifiedAlbum>>;
|
||||
|
||||
// ========================================================================
|
||||
// Playlists API
|
||||
// ========================================================================
|
||||
auto SearchArtists(const Request::ArtistSearchFilters &filters,
|
||||
const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<Artist>>;
|
||||
|
||||
auto GetPlaylist(const std::string &id,
|
||||
std::optional<std::string> market = {}) -> Result<Playlist>;
|
||||
// ========================================================================
|
||||
// Playlists API
|
||||
// ========================================================================
|
||||
|
||||
auto GetPlaylistTracks(const std::string &id,
|
||||
const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<PlaylistTrack>>;
|
||||
auto GetPlaylist(const std::string &id,
|
||||
std::optional<std::string> market = {})
|
||||
-> Result<Playlist>;
|
||||
|
||||
auto CreatePlaylist(const std::string &user_id,
|
||||
const Request::CreatePlaylistParams ¶ms)
|
||||
-> Result<Playlist>;
|
||||
auto GetPlaylistTracks(const std::string &id,
|
||||
const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<PlaylistTrack>>;
|
||||
|
||||
auto UpdatePlaylist(const std::string &id,
|
||||
const Request::UpdatePlaylistParams ¶ms)
|
||||
-> Result<void>;
|
||||
auto CreatePlaylist(const std::string &user_id,
|
||||
const Request::CreatePlaylistParams ¶ms)
|
||||
-> Result<Playlist>;
|
||||
|
||||
auto AddTracksToPlaylist(const std::string &id,
|
||||
const Request::AddTracksToPlaylistParams ¶ms)
|
||||
-> Result<std::string>;
|
||||
auto UpdatePlaylist(const std::string &id,
|
||||
const Request::UpdatePlaylistParams ¶ms)
|
||||
-> Result<void>;
|
||||
|
||||
auto RemoveTracksFromPlaylist(
|
||||
const std::string &id,
|
||||
const Request::RemoveTracksFromPlaylistParams ¶ms)
|
||||
-> Result<std::string>;
|
||||
auto AddTracksToPlaylist(
|
||||
const std::string &id,
|
||||
const Request::AddTracksToPlaylistParams ¶ms)
|
||||
-> Result<std::string>;
|
||||
|
||||
auto ReorderPlaylistTracks(const std::string &id,
|
||||
const Request::ReorderPlaylistParams ¶ms)
|
||||
-> Result<std::string>;
|
||||
auto RemoveTracksFromPlaylist(
|
||||
const std::string &id,
|
||||
const Request::RemoveTracksFromPlaylistParams ¶ms)
|
||||
-> Result<std::string>;
|
||||
|
||||
auto ReplacePlaylistTracks(const std::string &id,
|
||||
const Request::ReplacePlaylistTracksParams ¶ms)
|
||||
-> Result<void>;
|
||||
auto ReorderPlaylistTracks(
|
||||
const std::string &id,
|
||||
const Request::ReorderPlaylistParams ¶ms)
|
||||
-> Result<std::string>;
|
||||
|
||||
auto GetCurrentUserPlaylists(const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<SimplifiedPlaylist>>;
|
||||
auto ReplacePlaylistTracks(
|
||||
const std::string &id,
|
||||
const Request::ReplacePlaylistTracksParams ¶ms)
|
||||
-> Result<void>;
|
||||
|
||||
auto GetUserPlaylists(const std::string &user_id,
|
||||
const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<SimplifiedPlaylist>>;
|
||||
auto GetCurrentUserPlaylists(
|
||||
const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<SimplifiedPlaylist>>;
|
||||
|
||||
auto GetFeaturedPlaylists(const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<SimplifiedPlaylist>>;
|
||||
auto GetUserPlaylists(const std::string &user_id,
|
||||
const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<SimplifiedPlaylist>>;
|
||||
|
||||
auto GetCategoryPlaylists(const std::string &category_id,
|
||||
const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<SimplifiedPlaylist>>;
|
||||
auto GetFeaturedPlaylists(
|
||||
const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<SimplifiedPlaylist>>;
|
||||
|
||||
// ========================================================================
|
||||
// User API
|
||||
// ========================================================================
|
||||
auto GetCategoryPlaylists(
|
||||
const std::string &category_id,
|
||||
const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<SimplifiedPlaylist>>;
|
||||
|
||||
auto GetCurrentUser() -> Result<User>;
|
||||
// ========================================================================
|
||||
// User API
|
||||
// ========================================================================
|
||||
|
||||
auto GetUser(const std::string &user_id) -> Result<User>;
|
||||
auto GetCurrentUser() -> Result<User>;
|
||||
|
||||
auto GetTopArtists(const Request::TopItemsParams ¶ms = {})
|
||||
-> Result<PagingObject<Artist>>;
|
||||
auto GetUser(const std::string &user_id) -> Result<User>;
|
||||
|
||||
auto GetTopTracks(const Request::TopItemsParams ¶ms = {})
|
||||
-> Result<PagingObject<Track>>;
|
||||
auto GetTopArtists(const Request::TopItemsParams ¶ms = {})
|
||||
-> Result<PagingObject<Artist>>;
|
||||
|
||||
// ========================================================================
|
||||
// Follow API
|
||||
// ========================================================================
|
||||
auto GetTopTracks(const Request::TopItemsParams ¶ms = {})
|
||||
-> Result<PagingObject<Track>>;
|
||||
|
||||
auto FollowArtistsOrUsers(const Request::FollowParams ¶ms)
|
||||
-> Result<void>;
|
||||
// ========================================================================
|
||||
// Follow API
|
||||
// ========================================================================
|
||||
|
||||
auto UnfollowArtistsOrUsers(const Request::UnfollowParams ¶ms)
|
||||
-> Result<void>;
|
||||
auto FollowArtistsOrUsers(const Request::FollowParams ¶ms)
|
||||
-> Result<void>;
|
||||
|
||||
auto CheckFollowingArtistsOrUsers(const Request::CheckFollowingParams ¶ms)
|
||||
-> Result<std::vector<bool>>;
|
||||
auto UnfollowArtistsOrUsers(const Request::UnfollowParams ¶ms)
|
||||
-> Result<void>;
|
||||
|
||||
auto GetFollowedArtists(std::optional<int> limit = {},
|
||||
std::optional<std::string> after = {})
|
||||
-> Result<CursorPagingObject<Artist>>;
|
||||
auto CheckFollowingArtistsOrUsers(
|
||||
const Request::CheckFollowingParams ¶ms)
|
||||
-> Result<std::vector<bool>>;
|
||||
|
||||
auto FollowPlaylist(const std::string &playlist_id,
|
||||
const Request::FollowPlaylistParams ¶ms = {})
|
||||
-> Result<void>;
|
||||
auto GetFollowedArtists(std::optional<int> limit = {},
|
||||
std::optional<std::string> after = {})
|
||||
-> Result<CursorPagingObject<Artist>>;
|
||||
|
||||
auto UnfollowPlaylist(const std::string &playlist_id) -> Result<void>;
|
||||
auto
|
||||
FollowPlaylist(const std::string &playlist_id,
|
||||
const Request::FollowPlaylistParams ¶ms = {})
|
||||
-> Result<void>;
|
||||
|
||||
auto CheckFollowingPlaylist(const std::string &playlist_id,
|
||||
const std::vector<std::string> &user_ids)
|
||||
-> Result<std::vector<bool>>;
|
||||
auto UnfollowPlaylist(const std::string &playlist_id)
|
||||
-> Result<void>;
|
||||
|
||||
// ========================================================================
|
||||
// Player API
|
||||
// ========================================================================
|
||||
auto
|
||||
CheckFollowingPlaylist(const std::string &playlist_id,
|
||||
const std::vector<std::string> &user_ids)
|
||||
-> Result<std::vector<bool>>;
|
||||
|
||||
auto GetPlaybackState(std::optional<std::string> market = {})
|
||||
-> Result<PlaybackState>;
|
||||
// ========================================================================
|
||||
// Player API
|
||||
// ========================================================================
|
||||
|
||||
auto GetAvailableDevices() -> Result<std::vector<Device>>;
|
||||
auto GetPlaybackState(std::optional<std::string> market = {})
|
||||
-> Result<PlaybackState>;
|
||||
|
||||
auto GetCurrentlyPlayingTrack(std::optional<std::string> market = {})
|
||||
-> Result<PlaybackState>;
|
||||
auto GetAvailableDevices() -> Result<std::vector<Device>>;
|
||||
|
||||
auto StartOrResumePlayback(const Request::PlayParams ¶ms,
|
||||
std::optional<std::string> device_id = {})
|
||||
-> Result<void>;
|
||||
auto
|
||||
GetCurrentlyPlayingTrack(std::optional<std::string> market = {})
|
||||
-> Result<PlaybackState>;
|
||||
|
||||
auto PausePlayback(std::optional<std::string> device_id = {}) -> Result<void>;
|
||||
auto
|
||||
StartOrResumePlayback(const Request::PlayParams ¶ms,
|
||||
std::optional<std::string> device_id = {})
|
||||
-> Result<void>;
|
||||
|
||||
auto SkipToNext(std::optional<std::string> device_id = {}) -> Result<void>;
|
||||
auto PausePlayback(std::optional<std::string> device_id = {})
|
||||
-> Result<void>;
|
||||
|
||||
auto SkipToPrevious(std::optional<std::string> device_id = {})
|
||||
-> Result<void>;
|
||||
auto SkipToNext(std::optional<std::string> device_id = {})
|
||||
-> Result<void>;
|
||||
|
||||
auto SeekToPosition(int position_ms,
|
||||
std::optional<std::string> device_id = {})
|
||||
-> Result<void>;
|
||||
auto SkipToPrevious(std::optional<std::string> device_id = {})
|
||||
-> Result<void>;
|
||||
|
||||
auto SetRepeatMode(RepeatMode mode, std::optional<std::string> device_id = {})
|
||||
-> Result<void>;
|
||||
auto SeekToPosition(int position_ms,
|
||||
std::optional<std::string> device_id = {})
|
||||
-> Result<void>;
|
||||
|
||||
auto SetPlaybackVolume(int volume_percent,
|
||||
std::optional<std::string> device_id = {})
|
||||
-> Result<void>;
|
||||
auto SetRepeatMode(RepeatMode mode,
|
||||
std::optional<std::string> device_id = {})
|
||||
-> Result<void>;
|
||||
|
||||
auto TogglePlaybackShuffle(bool state,
|
||||
std::optional<std::string> device_id = {})
|
||||
-> Result<void>;
|
||||
auto SetPlaybackVolume(int volume_percent,
|
||||
std::optional<std::string> device_id = {})
|
||||
-> Result<void>;
|
||||
|
||||
auto TransferPlayback(const Request::TransferPlaybackParams ¶ms)
|
||||
-> Result<void>;
|
||||
auto
|
||||
TogglePlaybackShuffle(bool state,
|
||||
std::optional<std::string> device_id = {})
|
||||
-> Result<void>;
|
||||
|
||||
auto AddToQueue(const Request::QueueParams ¶ms) -> Result<void>;
|
||||
auto TransferPlayback(const Request::TransferPlaybackParams ¶ms)
|
||||
-> Result<void>;
|
||||
|
||||
auto GetRecentlyPlayedTracks(std::optional<int> limit = {},
|
||||
std::optional<int64_t> after = {},
|
||||
std::optional<int64_t> before = {})
|
||||
-> Result<CursorPagingObject<PlaylistTrack>>;
|
||||
auto AddToQueue(const Request::QueueParams ¶ms) -> Result<void>;
|
||||
|
||||
// ========================================================================
|
||||
// Browse API
|
||||
// ========================================================================
|
||||
auto GetRecentlyPlayedTracks(std::optional<int> limit = {},
|
||||
std::optional<int64_t> after = {},
|
||||
std::optional<int64_t> before = {})
|
||||
-> Result<CursorPagingObject<PlaylistTrack>>;
|
||||
|
||||
auto GetCategories(const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<Category>>;
|
||||
// ========================================================================
|
||||
// Browse API
|
||||
// ========================================================================
|
||||
|
||||
auto GetCategory(const std::string &category_id,
|
||||
std::optional<std::string> locale = {}) -> Result<Category>;
|
||||
auto GetCategories(const Request::PaginationParams ¶ms = {})
|
||||
-> Result<PagingObject<Category>>;
|
||||
|
||||
auto GetAvailableGenreSeeds() -> Result<std::vector<std::string>>;
|
||||
auto GetCategory(const std::string &category_id,
|
||||
std::optional<std::string> locale = {})
|
||||
-> Result<Category>;
|
||||
|
||||
auto GetAvailableMarkets() -> Result<std::vector<std::string>>;
|
||||
auto GetAvailableGenreSeeds() -> Result<std::vector<std::string>>;
|
||||
|
||||
private:
|
||||
std::string m_AccessToken;
|
||||
ProxyConfig m_Proxy;
|
||||
bool m_Verbose = false;
|
||||
auto GetAvailableMarkets() -> Result<std::vector<std::string>>;
|
||||
|
||||
auto PerformRequest(const std::string &url,
|
||||
HttpMethod method = HttpMethod::GET,
|
||||
const std::string &body = "",
|
||||
const std::vector<std::string> &extra_headers = {})
|
||||
-> Result<std::string>;
|
||||
private:
|
||||
|
||||
static auto WriteCallback(void *contents, size_t size, size_t nmemb,
|
||||
std::string *out) -> size_t;
|
||||
std::string m_AccessToken;
|
||||
ProxyConfig m_Proxy;
|
||||
bool m_Verbose = false;
|
||||
|
||||
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;
|
||||
};
|
||||
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
|
||||
@@ -4,25 +4,32 @@
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace Spotify {
|
||||
namespace Spotify
|
||||
{
|
||||
|
||||
struct CallbackResult {
|
||||
std::string code;
|
||||
std::string state;
|
||||
std::string error;
|
||||
};
|
||||
struct CallbackResult {
|
||||
std::string code;
|
||||
std::string state;
|
||||
std::string error;
|
||||
};
|
||||
|
||||
class HttpCallbackServer {
|
||||
public:
|
||||
HttpCallbackServer(std::string host, uint16_t port, std::string path);
|
||||
class HttpCallbackServer
|
||||
{
|
||||
public:
|
||||
|
||||
// Wait for one callback request or timeout. Returns std::nullopt on timeout.
|
||||
std::optional<CallbackResult> WaitForCallback(std::chrono::milliseconds timeout);
|
||||
HttpCallbackServer(std::string host, uint16_t port,
|
||||
std::string path);
|
||||
|
||||
private:
|
||||
std::string m_Host;
|
||||
uint16_t m_Port;
|
||||
std::string m_Path;
|
||||
};
|
||||
// Wait for one callback request or timeout. Returns std::nullopt on
|
||||
// timeout.
|
||||
std::optional<CallbackResult>
|
||||
WaitForCallback(std::chrono::milliseconds timeout);
|
||||
|
||||
} // namespace ts6bot
|
||||
private:
|
||||
|
||||
std::string m_Host;
|
||||
uint16_t m_Port;
|
||||
std::string m_Path;
|
||||
};
|
||||
|
||||
} // namespace Spotify
|
||||
@@ -11,47 +11,57 @@
|
||||
|
||||
#include <Spotify/Client.hpp> // for ProxyConfig + CurlDeleter + ProxyType
|
||||
|
||||
namespace Spotify {
|
||||
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
|
||||
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;
|
||||
};
|
||||
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);
|
||||
class PkceAuth
|
||||
{
|
||||
public:
|
||||
|
||||
void SetProxy(ProxyConfig p) { m_Proxy = std::move(p); }
|
||||
void SetVerbose(bool v) { m_Verbose = v; }
|
||||
PkceAuth(std::string clientId,
|
||||
std::string redirectUri,
|
||||
std::filesystem::path tokenCachePath);
|
||||
|
||||
// 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));
|
||||
void SetProxy(ProxyConfig p) { m_Proxy = std::move(p); }
|
||||
void SetVerbose(bool v) { m_Verbose = v; }
|
||||
|
||||
// Headless: load from cache and refresh if needed.
|
||||
TokenSet LoadOrRefresh();
|
||||
// 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));
|
||||
|
||||
private:
|
||||
std::string m_ClientId;
|
||||
std::string m_RedirectUri;
|
||||
std::filesystem::path m_TokenCachePath;
|
||||
ProxyConfig m_Proxy;
|
||||
bool m_Verbose = false;
|
||||
// Headless: load from cache and refresh if needed.
|
||||
TokenSet LoadOrRefresh();
|
||||
|
||||
TokenSet ExchangeCodeForToken(const std::string& code, const std::string& codeVerifier);
|
||||
TokenSet RefreshAccessToken(const TokenSet& current);
|
||||
private:
|
||||
|
||||
void Save(const TokenSet& t) const;
|
||||
std::optional<TokenSet> Load() const;
|
||||
std::string m_ClientId;
|
||||
std::string m_RedirectUri;
|
||||
std::filesystem::path m_TokenCachePath;
|
||||
ProxyConfig m_Proxy;
|
||||
bool m_Verbose = false;
|
||||
|
||||
static std::int64_t NowUnixSeconds();
|
||||
friend TokenSet;
|
||||
};
|
||||
TokenSet ExchangeCodeForToken(const std::string& code,
|
||||
const std::string& codeVerifier);
|
||||
TokenSet RefreshAccessToken(const TokenSet& current);
|
||||
|
||||
} // namespace ts6bot
|
||||
void Save(const TokenSet& t) const;
|
||||
std::optional<TokenSet> Load() const;
|
||||
|
||||
static std::int64_t NowUnixSeconds();
|
||||
friend TokenSet;
|
||||
};
|
||||
|
||||
} // namespace Spotify
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,178 +1,169 @@
|
||||
#pragma once
|
||||
#include "Spotify/Types/Common.hpp"
|
||||
#include "Spotify/Types/Artist.hpp"
|
||||
#include "Spotify/Types/Common.hpp"
|
||||
|
||||
namespace Spotify {
|
||||
namespace Spotify
|
||||
{
|
||||
|
||||
// ============================================================================
|
||||
// Album Group Enum
|
||||
// ============================================================================
|
||||
// ============================================================================
|
||||
// Album Group Enum
|
||||
// ============================================================================
|
||||
|
||||
enum class AlbumGroup {
|
||||
Album,
|
||||
Single,
|
||||
AppearsOn,
|
||||
Compilation
|
||||
};
|
||||
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 "";
|
||||
}
|
||||
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
|
||||
// ============================================================================
|
||||
// ============================================================================
|
||||
// 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;
|
||||
}
|
||||
};
|
||||
class AlbumBase
|
||||
{
|
||||
public:
|
||||
|
||||
// ============================================================================
|
||||
// Simplified Album
|
||||
// ============================================================================
|
||||
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;
|
||||
|
||||
struct SimplifiedAlbum : AlbumBase {
|
||||
};
|
||||
virtual ~AlbumBase() = default;
|
||||
|
||||
// ============================================================================
|
||||
// Full Album
|
||||
// ============================================================================
|
||||
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; }
|
||||
|
||||
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; }
|
||||
};
|
||||
auto GetAlbumType() const -> AlbumType
|
||||
{
|
||||
if (album_type == "album") {
|
||||
return AlbumType::Album;
|
||||
}
|
||||
if (album_type == "single") {
|
||||
return AlbumType::Single;
|
||||
}
|
||||
return AlbumType::Compilation;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Saved Album
|
||||
// ============================================================================
|
||||
auto GetReleaseDatePrecision() const -> ReleaseDatePrecision
|
||||
{
|
||||
if (release_date_precision == "year") {
|
||||
return ReleaseDatePrecision::Year;
|
||||
}
|
||||
if (release_date_precision == "month") {
|
||||
return ReleaseDatePrecision::Month;
|
||||
}
|
||||
return ReleaseDatePrecision::Day;
|
||||
}
|
||||
};
|
||||
|
||||
struct SavedAlbum {
|
||||
std::string added_at;
|
||||
Album album;
|
||||
|
||||
auto GetAlbum() const -> const Album& { return album; }
|
||||
auto GetAddedAt() const -> const std::string& { return added_at; }
|
||||
};
|
||||
// ============================================================================
|
||||
// Simplified Album
|
||||
// ============================================================================
|
||||
|
||||
struct AlbumsResponse {
|
||||
std::vector<Album> albums;
|
||||
};
|
||||
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::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::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::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
|
||||
);
|
||||
template <> struct glz::meta<Spotify::SavedAlbum> {
|
||||
using T = Spotify::SavedAlbum;
|
||||
static constexpr auto value =
|
||||
object("added_at", &T::added_at, "album", &T::album);
|
||||
};
|
||||
@@ -1,84 +1,76 @@
|
||||
#pragma once
|
||||
#include "Spotify/Types/Common.hpp"
|
||||
|
||||
namespace Spotify {
|
||||
namespace Spotify
|
||||
{
|
||||
|
||||
// ============================================================================
|
||||
// Artist Base
|
||||
// ============================================================================
|
||||
// ============================================================================
|
||||
// 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; }
|
||||
};
|
||||
class ArtistBase
|
||||
{
|
||||
public:
|
||||
|
||||
// ============================================================================
|
||||
// Simplified Artist
|
||||
// ============================================================================
|
||||
ExternalUrls external_urls;
|
||||
std::string href;
|
||||
std::string id;
|
||||
std::string name;
|
||||
std::string type;
|
||||
std::string uri;
|
||||
|
||||
struct SimplifiedArtist : ArtistBase {
|
||||
};
|
||||
virtual ~ArtistBase() = default;
|
||||
|
||||
// ============================================================================
|
||||
// Full Artist
|
||||
// ============================================================================
|
||||
auto GetId() const -> const std::string & { return id; }
|
||||
auto GetName() const -> const std::string & { return name; }
|
||||
auto GetUri() const -> const std::string & { return uri; }
|
||||
};
|
||||
|
||||
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; }
|
||||
};
|
||||
// ============================================================================
|
||||
// Simplified Artist
|
||||
// ============================================================================
|
||||
|
||||
struct ArtistsResponse {
|
||||
std::vector<Artist> artists;
|
||||
};
|
||||
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::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
|
||||
);
|
||||
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);
|
||||
};
|
||||
@@ -1,185 +1,152 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
#include <glaze/glaze.hpp>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Spotify {
|
||||
namespace Spotify
|
||||
{
|
||||
|
||||
// ============================================================================
|
||||
// Common Enums
|
||||
// ============================================================================
|
||||
// ============================================================================
|
||||
// Common Enums
|
||||
// ============================================================================
|
||||
|
||||
enum class AlbumType {
|
||||
Album,
|
||||
Single,
|
||||
Compilation
|
||||
};
|
||||
enum class AlbumType { Album, Single, Compilation };
|
||||
|
||||
enum class ReleaseDatePrecision {
|
||||
Year,
|
||||
Month,
|
||||
Day
|
||||
};
|
||||
enum class ReleaseDatePrecision { Year, Month, Day };
|
||||
|
||||
enum class CopyrightType {
|
||||
Copyright, // "C"
|
||||
Performance // "P"
|
||||
};
|
||||
enum class CopyrightType {
|
||||
Copyright, // "C"
|
||||
Performance // "P"
|
||||
};
|
||||
|
||||
enum class RestrictionReason {
|
||||
Market,
|
||||
Product,
|
||||
Explicit
|
||||
};
|
||||
enum class RestrictionReason { Market, Product, Explicit };
|
||||
|
||||
// ============================================================================
|
||||
// Core Structures
|
||||
// ============================================================================
|
||||
// ============================================================================
|
||||
// Core Structures
|
||||
// ============================================================================
|
||||
|
||||
struct Image {
|
||||
std::string url;
|
||||
std::optional<int> height;
|
||||
std::optional<int> width;
|
||||
};
|
||||
struct Image {
|
||||
std::string url;
|
||||
std::optional<int> height;
|
||||
std::optional<int> width;
|
||||
};
|
||||
|
||||
struct ExternalUrls {
|
||||
std::string spotify;
|
||||
};
|
||||
struct ExternalUrls {
|
||||
std::string spotify;
|
||||
};
|
||||
|
||||
struct ExternalIds {
|
||||
std::optional<std::string> isrc;
|
||||
std::optional<std::string> ean;
|
||||
std::optional<std::string> upc;
|
||||
};
|
||||
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 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 Copyright {
|
||||
std::string text;
|
||||
std::string type;
|
||||
|
||||
struct Restrictions {
|
||||
std::string reason;
|
||||
|
||||
auto GetReason() const -> RestrictionReason {
|
||||
if (reason == "market") return RestrictionReason::Market;
|
||||
if (reason == "product") return RestrictionReason::Product;
|
||||
return RestrictionReason::Explicit;
|
||||
}
|
||||
};
|
||||
auto GetType() const -> CopyrightType
|
||||
{
|
||||
return type == "C" ? CopyrightType::Copyright
|
||||
: CopyrightType::Performance;
|
||||
}
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Paging Objects
|
||||
// ============================================================================
|
||||
struct Restrictions {
|
||||
std::string reason;
|
||||
|
||||
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;
|
||||
};
|
||||
auto GetReason() const -> RestrictionReason
|
||||
{
|
||||
if (reason == "market") {
|
||||
return RestrictionReason::Market;
|
||||
}
|
||||
if (reason == "product") {
|
||||
return RestrictionReason::Product;
|
||||
}
|
||||
return RestrictionReason::Explicit;
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
// ============================================================================
|
||||
// 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::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::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::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::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::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 <> 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::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
|
||||
);
|
||||
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);
|
||||
};
|
||||
@@ -1,133 +1,140 @@
|
||||
#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/Artist.hpp"
|
||||
#include "Spotify/Types/Common.hpp"
|
||||
#include "Spotify/Types/Playlist.hpp"
|
||||
#include "Spotify/Types/Track.hpp"
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Spotify {
|
||||
namespace Spotify
|
||||
{
|
||||
|
||||
// ============================================================================
|
||||
// Category
|
||||
// ============================================================================
|
||||
// ============================================================================
|
||||
// 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; }
|
||||
};
|
||||
struct Category {
|
||||
std::string href;
|
||||
std::vector<Image> icons;
|
||||
std::string id;
|
||||
std::string name;
|
||||
|
||||
// ============================================================================
|
||||
// Recommendation Seed
|
||||
// ============================================================================
|
||||
auto GetId() const -> const std::string& { return id; }
|
||||
auto GetName() const -> const std::string& { return name; }
|
||||
};
|
||||
|
||||
enum class SeedType {
|
||||
Artist,
|
||||
Track,
|
||||
Genre
|
||||
};
|
||||
// ============================================================================
|
||||
// Recommendation Seed
|
||||
// ============================================================================
|
||||
|
||||
inline auto StringToSeedType(const std::string& str) -> SeedType {
|
||||
if (str == "ARTIST") return SeedType::Artist;
|
||||
if (str == "TRACK") return SeedType::Track;
|
||||
return SeedType::Genre;
|
||||
}
|
||||
enum class SeedType { Artist, Track, 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);
|
||||
}
|
||||
};
|
||||
inline auto StringToSeedType(const std::string& str) -> SeedType
|
||||
{
|
||||
if (str == "ARTIST") {
|
||||
return SeedType::Artist;
|
||||
}
|
||||
if (str == "TRACK") {
|
||||
return SeedType::Track;
|
||||
}
|
||||
return SeedType::Genre;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Recommendations Response
|
||||
// ============================================================================
|
||||
struct RecommendationSeed {
|
||||
int afterFilteringSize;
|
||||
int afterRelinkingSize;
|
||||
std::optional<std::string> href;
|
||||
std::string id;
|
||||
int initialPoolSize;
|
||||
std::string type;
|
||||
|
||||
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; }
|
||||
};
|
||||
auto GetId() const -> const std::string& { return id; }
|
||||
auto GetSeedType() const -> SeedType
|
||||
{
|
||||
return StringToSeedType(type);
|
||||
}
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Search Results
|
||||
// ============================================================================
|
||||
// ============================================================================
|
||||
// Recommendations Response
|
||||
// ============================================================================
|
||||
|
||||
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; }
|
||||
};
|
||||
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::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::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::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
|
||||
);
|
||||
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);
|
||||
};
|
||||
|
||||
@@ -2,217 +2,246 @@
|
||||
#include "Spotify/Types/Common.hpp"
|
||||
#include "Spotify/Types/Track.hpp"
|
||||
|
||||
namespace Spotify {
|
||||
namespace Spotify
|
||||
{
|
||||
|
||||
// ============================================================================
|
||||
// Device Type Enum
|
||||
// ============================================================================
|
||||
// ============================================================================
|
||||
// Device Type Enum
|
||||
// ============================================================================
|
||||
|
||||
enum class DeviceType {
|
||||
Computer,
|
||||
Smartphone,
|
||||
Speaker,
|
||||
TV,
|
||||
AVR,
|
||||
STB,
|
||||
AudioDongle,
|
||||
GameConsole,
|
||||
CastVideo,
|
||||
CastAudio,
|
||||
Automobile,
|
||||
Unknown
|
||||
};
|
||||
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;
|
||||
}
|
||||
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
|
||||
// ============================================================================
|
||||
// ============================================================================
|
||||
// Repeat Mode Enum
|
||||
// ============================================================================
|
||||
|
||||
enum class RepeatMode {
|
||||
Off,
|
||||
Track,
|
||||
Context
|
||||
};
|
||||
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 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;
|
||||
}
|
||||
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
|
||||
// ============================================================================
|
||||
// ============================================================================
|
||||
// Context Type Enum
|
||||
// ============================================================================
|
||||
|
||||
enum class ContextType {
|
||||
Artist,
|
||||
Playlist,
|
||||
Album,
|
||||
Show,
|
||||
Collection
|
||||
};
|
||||
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;
|
||||
}
|
||||
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
|
||||
// ============================================================================
|
||||
// ============================================================================
|
||||
// Currently Playing Type Enum
|
||||
// ============================================================================
|
||||
|
||||
enum class CurrentlyPlayingType {
|
||||
Track,
|
||||
Episode,
|
||||
Ad,
|
||||
Unknown
|
||||
};
|
||||
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;
|
||||
}
|
||||
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
|
||||
// ============================================================================
|
||||
// ============================================================================
|
||||
// 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);
|
||||
}
|
||||
};
|
||||
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;
|
||||
|
||||
// ============================================================================
|
||||
// Context
|
||||
// ============================================================================
|
||||
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; }
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
auto GetDeviceType() const -> DeviceType
|
||||
{
|
||||
return StringToDeviceType(type);
|
||||
}
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Playback State
|
||||
// ============================================================================
|
||||
// ============================================================================
|
||||
// Context
|
||||
// ============================================================================
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
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::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::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
|
||||
);
|
||||
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);
|
||||
};
|
||||
@@ -1,139 +1,121 @@
|
||||
#pragma once
|
||||
#include "Spotify/Types/Common.hpp"
|
||||
#include "Spotify/Types/Artist.hpp"
|
||||
#include "Spotify/Types/Common.hpp"
|
||||
#include "Spotify/Types/Track.hpp"
|
||||
|
||||
namespace Spotify {
|
||||
namespace Spotify
|
||||
{
|
||||
|
||||
// ============================================================================
|
||||
// Playlist Track
|
||||
// ============================================================================
|
||||
// ============================================================================
|
||||
// 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; }
|
||||
};
|
||||
struct PlaylistTrack {
|
||||
std::optional<std::string> added_at;
|
||||
std::optional<SimplifiedArtist> added_by;
|
||||
bool is_local;
|
||||
Track track;
|
||||
|
||||
// ============================================================================
|
||||
// Playlist Base
|
||||
// ============================================================================
|
||||
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; }
|
||||
};
|
||||
|
||||
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; }
|
||||
};
|
||||
// ============================================================================
|
||||
// Playlist Base
|
||||
// ============================================================================
|
||||
|
||||
// ============================================================================
|
||||
// Simplified Playlist
|
||||
// ============================================================================
|
||||
class PlaylistBase
|
||||
{
|
||||
public:
|
||||
|
||||
struct SimplifiedPlaylist : PlaylistBase {
|
||||
struct TracksInfo {
|
||||
std::string href;
|
||||
int total;
|
||||
} tracks;
|
||||
|
||||
auto GetTotalTracks() const -> int { return tracks.total; }
|
||||
};
|
||||
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;
|
||||
|
||||
// ============================================================================
|
||||
// Full Playlist
|
||||
// ============================================================================
|
||||
virtual ~PlaylistBase() = default;
|
||||
|
||||
struct Playlist : PlaylistBase {
|
||||
Followers followers;
|
||||
|
||||
auto GetFollowers() const -> const Followers& { return followers; }
|
||||
};
|
||||
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::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::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::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
|
||||
);
|
||||
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);
|
||||
};
|
||||
@@ -1,318 +1,285 @@
|
||||
#pragma once
|
||||
#include "Spotify/Types/Common.hpp"
|
||||
#include "Spotify/Types/Artist.hpp"
|
||||
#include "Spotify/Types/Album.hpp"
|
||||
#include "Spotify/Types/Artist.hpp"
|
||||
#include "Spotify/Types/Common.hpp"
|
||||
|
||||
namespace Spotify {
|
||||
namespace Spotify
|
||||
{
|
||||
|
||||
// ============================================================================
|
||||
// Track Base
|
||||
// ============================================================================
|
||||
// ============================================================================
|
||||
// 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; }
|
||||
};
|
||||
class TrackBase
|
||||
{
|
||||
public:
|
||||
|
||||
// ============================================================================
|
||||
// Simplified Track
|
||||
// ============================================================================
|
||||
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;
|
||||
|
||||
struct SimplifiedTrack : TrackBase {
|
||||
};
|
||||
virtual ~TrackBase() = default;
|
||||
|
||||
// ============================================================================
|
||||
// Full Track
|
||||
// ============================================================================
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
struct Track : TrackBase {
|
||||
SimplifiedAlbum album;
|
||||
ExternalIds external_ids;
|
||||
int popularity;
|
||||
|
||||
auto GetAlbum() const -> const SimplifiedAlbum& { return album; }
|
||||
auto GetPopularity() const -> int { return popularity; }
|
||||
};
|
||||
// ============================================================================
|
||||
// Simplified Track
|
||||
// ============================================================================
|
||||
|
||||
// ============================================================================
|
||||
// Saved Track
|
||||
// ============================================================================
|
||||
struct SimplifiedTrack : TrackBase {
|
||||
};
|
||||
|
||||
struct SavedTrack {
|
||||
std::string added_at;
|
||||
Track track;
|
||||
|
||||
auto GetTrack() const -> const Track& { return track; }
|
||||
auto GetAddedAt() const -> const std::string& { return added_at; }
|
||||
};
|
||||
// ============================================================================
|
||||
// Full Track
|
||||
// ============================================================================
|
||||
|
||||
// ============================================================================
|
||||
// Audio Features
|
||||
// ============================================================================
|
||||
struct Track : TrackBase {
|
||||
SimplifiedAlbum album;
|
||||
ExternalIds external_ids;
|
||||
int popularity;
|
||||
|
||||
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
|
||||
};
|
||||
auto GetAlbum() const -> const SimplifiedAlbum & { return album; }
|
||||
auto GetPopularity() const -> int { return popularity; }
|
||||
};
|
||||
|
||||
enum class MusicalMode {
|
||||
Minor = 0,
|
||||
Major = 1
|
||||
};
|
||||
// ============================================================================
|
||||
// Saved Track
|
||||
// ============================================================================
|
||||
|
||||
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; }
|
||||
};
|
||||
struct SavedTrack {
|
||||
std::string added_at;
|
||||
Track track;
|
||||
|
||||
// ============================================================================
|
||||
// Audio Analysis
|
||||
// ============================================================================
|
||||
auto GetTrack() const -> const Track & { return track; }
|
||||
auto GetAddedAt() const -> const std::string & { return added_at; }
|
||||
};
|
||||
|
||||
struct TimeInterval {
|
||||
float start;
|
||||
float duration;
|
||||
float confidence;
|
||||
};
|
||||
// ============================================================================
|
||||
// Audio Features
|
||||
// ============================================================================
|
||||
|
||||
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;
|
||||
};
|
||||
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
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
enum class MusicalMode { Minor = 0, Major = 1 };
|
||||
|
||||
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 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;
|
||||
|
||||
struct TracksResponse {
|
||||
std::vector<Track> tracks;
|
||||
};
|
||||
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::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::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::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::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::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::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::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
|
||||
);
|
||||
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);
|
||||
};
|
||||
@@ -1,77 +1,81 @@
|
||||
#pragma once
|
||||
#include "Spotify/Types/Common.hpp"
|
||||
|
||||
namespace Spotify {
|
||||
namespace Spotify
|
||||
{
|
||||
|
||||
// ============================================================================
|
||||
// User Product Type
|
||||
// ============================================================================
|
||||
// ============================================================================
|
||||
// User Product Type
|
||||
// ============================================================================
|
||||
|
||||
enum class Product {
|
||||
Premium,
|
||||
Free,
|
||||
Open,
|
||||
Unknown
|
||||
};
|
||||
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;
|
||||
}
|
||||
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
|
||||
// ============================================================================
|
||||
// ============================================================================
|
||||
// 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;
|
||||
}
|
||||
};
|
||||
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
|
||||
);
|
||||
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);
|
||||
};
|
||||
Reference in new issue
Block a user