#pragma once // Standard Library #include #include #include #include #include // Third Party #include "cpr/cprtypes.h" #include "cpr/parameters.h" #include #include // Assumed available per your reference #include // Project (Assuming similar structure to your Spotify bot) #include #include #include namespace YouTube { // ============================================================================ // Data Types (Simplified for immediate usage) // ============================================================================ struct Thumbnail { std::string url; int width; int height; }; struct Snippet { std::string publishedAt; std::string channelId; std::string title; std::string description; std::string channelTitle; std::map thumbnails; std::string liveBroadcastContent; std::string publishTime; }; struct PlayListResourceId { std::string kind; std::string videoId; }; struct PlayListSnippet { std::string publishedAt; std::string channelId; std::string title; std::string description; std::map thumbnails; std::string channelTitle; std::string playlistId; int position; PlayListResourceId resourceId; std::string videoOwnerChannelTitle; std::string videoOwnerChannelId; }; struct ResourceId { std::string kind; std::string videoId; std::string channelId; std::string playlistId; }; // Search results use a wrapper for ID, Videos use a string ID struct SearchResultId { std::string kind; std::string videoId; std::string channelId; std::string playlistId; }; struct VideoContentDetails { std::string duration; std::string dimension; std::string definition; }; struct VideoStatistics { std::string viewCount; std::string likeCount; std::string commentCount; }; // Main Resource Types struct Video { std::string kind; std::string id; Snippet snippet; VideoContentDetails contentDetails; VideoStatistics statistics; }; struct SearchResult { std::string kind; std::string etag; SearchResultId id; Snippet snippet; }; struct SearchPlaylistResult { std::string kind; std::string etag; std::string id; PlayListSnippet snippet; }; // API Response Wrappers template struct PageResult { std::string kind; std::string etag; std::string nextPageToken; std::string prevPageToken; std::string regionCode; struct PageInfo { int totalResults; int resultsPerPage; } pageInfo; std::vector items; }; // ============================================================================ // InnerTube (Player) Data Types // ============================================================================ struct AudioFormat { int itag; std::string url; // Direct URL (if unencrypted) std::string signatureCipher; // Encrypted signature (if present, url // is empty) std::string mimeType; int bitrate; std::string qualityLabel; }; struct StreamingData { std::string expiresInSeconds; std::vector formats; // Mixed video+audio std::vector adaptiveFormats; // Separate streams (we want audio from here) }; struct PlayerResponse { StreamingData streamingData; // ... other fields like playabilityStatus ignored for brevity }; // ============================================================================ // Error Handling // ============================================================================ struct ApiError { int status; std::string message; std::string reason; }; struct GoogleError { struct Inner { int code; std::string message; } error; }; template using Result = std::expected; // ============================================================================ // Request Parameters // ============================================================================ struct SearchParams { std::string q; std::vector type = { "video"}; // video, channel, playlist std::string part = "snippet"; int maxResults = 5; std::string order = "relevance"; std::string pageToken = ""; std::string videoDuration = "any"; // any, long, medium, short bool rawQuery = false; // Set to true to preserve -, |, etc. in query }; struct ShortenResponse { std::string shortUrl; }; // ============================================================================ // Main YouTube Client // ============================================================================ struct CurlDeleter { void operator()(CURL *ptr) const { if (ptr) { curl_easy_cleanup(ptr); } } }; enum class HttpMethod { GET, POST, PUT, DELETE }; class Client { public: // YouTube typically uses API Keys for public data, OAuth for user // data. Pass "" as accessToken if only using API Key. Client(std::string apiKey, std::string accessToken = ""); ~Client(); auto GetBestStreams(const std::string &videoId) -> Result<::definitions::Streams>; // Configuration void SetVerbose(bool verbose) { m_Verbose = verbose; } void SetProxy(ProxyConfig config) { m_Proxy = std::move(config); } void SetAccessToken(std::string token) { m_AccessToken = std::move(token); } void SetApiKey(std::string key) { m_ApiKey = std::move(key); } auto ShortUrl(const std::string &url) const -> Result; // ======================================================================== // Search API // ======================================================================== // https://developers.google.com/youtube/v3/docs/search/list auto Search(const SearchParams ¶ms) -> Result>; // ======================================================================== // Videos API // ======================================================================== // https://developers.google.com/youtube/v3/docs/videos/list auto GetVideo( const std::string &id, const std::string &part = "snippet,contentDetails,statistics") -> Result