Format and .clang-format
This commit is contained in:
1 parent
6aed7b0027
commit
b94b634a87
47 files changed
+42341
-39711
No files matched your search
+270
-248
@@ -14,290 +14,312 @@
|
||||
#include <glaze/glaze.hpp> // Assumed available per your reference
|
||||
#include <quickjs.h>
|
||||
// Project (Assuming similar structure to your Spotify bot)
|
||||
#include <ts6bot/Proxy.hpp>
|
||||
#include <Logger.hpp>
|
||||
#include <PluginDefinitions.hpp>
|
||||
#include <ts6bot/Proxy.hpp>
|
||||
|
||||
namespace YouTube {
|
||||
namespace YouTube
|
||||
{
|
||||
|
||||
// ============================================================================
|
||||
// Data Types (Simplified for immediate usage)
|
||||
// ============================================================================
|
||||
// ============================================================================
|
||||
// Data Types (Simplified for immediate usage)
|
||||
// ============================================================================
|
||||
|
||||
struct Thumbnail {
|
||||
std::string url;
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
struct Thumbnail {
|
||||
std::string url;
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
|
||||
struct Snippet {
|
||||
std::string publishedAt;
|
||||
std::string channelId;
|
||||
std::string title;
|
||||
std::string description;
|
||||
std::string channelTitle;
|
||||
std::map<std::string, Thumbnail> thumbnails;
|
||||
std::string liveBroadcastContent;
|
||||
std::string publishTime;
|
||||
};
|
||||
struct PlayListResourceId {
|
||||
std::string kind;
|
||||
std::string videoId;
|
||||
};
|
||||
struct PlayListSnippet{
|
||||
std::string publishedAt;
|
||||
std::string channelId;
|
||||
std::string title;
|
||||
std::string description;
|
||||
std::map<std::string, Thumbnail> thumbnails;
|
||||
std::string channelTitle;
|
||||
std::string playlistId;
|
||||
int position;
|
||||
PlayListResourceId resourceId;
|
||||
std::string videoOwnerChannelTitle;
|
||||
std::string videoOwnerChannelId;
|
||||
};
|
||||
struct Snippet {
|
||||
std::string publishedAt;
|
||||
std::string channelId;
|
||||
std::string title;
|
||||
std::string description;
|
||||
std::string channelTitle;
|
||||
std::map<std::string, Thumbnail> thumbnails;
|
||||
std::string liveBroadcastContent;
|
||||
std::string publishTime;
|
||||
};
|
||||
struct PlayListResourceId {
|
||||
std::string kind;
|
||||
std::string videoId;
|
||||
};
|
||||
struct PlayListSnippet {
|
||||
std::string publishedAt;
|
||||
std::string channelId;
|
||||
std::string title;
|
||||
std::string description;
|
||||
std::map<std::string, Thumbnail> 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;
|
||||
};
|
||||
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;
|
||||
};
|
||||
// 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 VideoContentDetails {
|
||||
std::string duration;
|
||||
std::string dimension;
|
||||
std::string definition;
|
||||
};
|
||||
|
||||
struct VideoStatistics {
|
||||
std::string viewCount;
|
||||
std::string likeCount;
|
||||
std::string commentCount;
|
||||
};
|
||||
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;
|
||||
};
|
||||
// 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 SearchResult {
|
||||
std::string kind;
|
||||
std::string etag;
|
||||
SearchResultId id;
|
||||
Snippet snippet;
|
||||
};
|
||||
|
||||
struct SearchPlaylistResult {
|
||||
std::string kind;
|
||||
std::string etag;
|
||||
std::string id;
|
||||
PlayListSnippet snippet;
|
||||
};
|
||||
struct SearchPlaylistResult {
|
||||
std::string kind;
|
||||
std::string etag;
|
||||
std::string id;
|
||||
PlayListSnippet snippet;
|
||||
};
|
||||
|
||||
// API Response Wrappers
|
||||
template <typename T> struct PageResult {
|
||||
std::string kind;
|
||||
std::string etag;
|
||||
std::string nextPageToken;
|
||||
std::string prevPageToken;
|
||||
std::string regionCode;
|
||||
struct PageInfo {
|
||||
int totalResults;
|
||||
int resultsPerPage;
|
||||
} pageInfo;
|
||||
std::vector<T> items;
|
||||
};
|
||||
// ============================================================================
|
||||
// InnerTube (Player) Data Types
|
||||
// ============================================================================
|
||||
// API Response Wrappers
|
||||
template <typename T> struct PageResult {
|
||||
std::string kind;
|
||||
std::string etag;
|
||||
std::string nextPageToken;
|
||||
std::string prevPageToken;
|
||||
std::string regionCode;
|
||||
struct PageInfo {
|
||||
int totalResults;
|
||||
int resultsPerPage;
|
||||
} pageInfo;
|
||||
std::vector<T> items;
|
||||
};
|
||||
// ============================================================================
|
||||
// InnerTube (Player) Data Types
|
||||
// ============================================================================
|
||||
|
||||
struct AudioFormat {
|
||||
int itag;
|
||||
std::string url; // Direct URL (if unencrypted)
|
||||
std::string signatureCipher; // Encrypted signature (if present, url is empty)
|
||||
std::string mimeType;
|
||||
int bitrate;
|
||||
std::string qualityLabel;
|
||||
};
|
||||
struct AudioFormat {
|
||||
int itag;
|
||||
std::string url; // Direct URL (if unencrypted)
|
||||
std::string signatureCipher; // Encrypted signature (if present, url
|
||||
// is empty)
|
||||
std::string mimeType;
|
||||
int bitrate;
|
||||
std::string qualityLabel;
|
||||
};
|
||||
|
||||
struct StreamingData {
|
||||
std::string expiresInSeconds;
|
||||
std::vector<AudioFormat> formats; // Mixed video+audio
|
||||
std::vector<AudioFormat>
|
||||
adaptiveFormats; // Separate streams (we want audio from here)
|
||||
};
|
||||
struct StreamingData {
|
||||
std::string expiresInSeconds;
|
||||
std::vector<AudioFormat> formats; // Mixed video+audio
|
||||
std::vector<AudioFormat>
|
||||
adaptiveFormats; // Separate streams (we want audio from here)
|
||||
};
|
||||
|
||||
struct PlayerResponse {
|
||||
StreamingData streamingData;
|
||||
// ... other fields like playabilityStatus ignored for brevity
|
||||
};
|
||||
// ============================================================================
|
||||
// Error Handling
|
||||
// ============================================================================
|
||||
struct PlayerResponse {
|
||||
StreamingData streamingData;
|
||||
// ... other fields like playabilityStatus ignored for brevity
|
||||
};
|
||||
// ============================================================================
|
||||
// Error Handling
|
||||
// ============================================================================
|
||||
|
||||
struct ApiError {
|
||||
int status;
|
||||
std::string message;
|
||||
std::string reason;
|
||||
};
|
||||
struct GoogleError {
|
||||
struct Inner {
|
||||
int code;
|
||||
std::string message;
|
||||
} error;
|
||||
};
|
||||
template <typename T> using Result = std::expected<T, ApiError>;
|
||||
// ============================================================================
|
||||
// Request Parameters
|
||||
// ============================================================================
|
||||
struct ApiError {
|
||||
int status;
|
||||
std::string message;
|
||||
std::string reason;
|
||||
};
|
||||
struct GoogleError {
|
||||
struct Inner {
|
||||
int code;
|
||||
std::string message;
|
||||
} error;
|
||||
};
|
||||
template <typename T> using Result = std::expected<T, ApiError>;
|
||||
// ============================================================================
|
||||
// Request Parameters
|
||||
// ============================================================================
|
||||
|
||||
struct SearchParams {
|
||||
std::string q;
|
||||
std::vector<std::string> type = {"video"}; // video, channel, playlist
|
||||
std::string part = "snippet";
|
||||
int maxResults = 5;
|
||||
std::string order = "relevance";
|
||||
std::string pageToken = "";
|
||||
std::string videoDuration = "any"; // any, long, medium, short
|
||||
bool rawQuery = false; // Set to true to preserve -, |, etc. in query
|
||||
};
|
||||
struct ShortenResponse {
|
||||
std::string shortUrl;
|
||||
};
|
||||
// ============================================================================
|
||||
// Main YouTube Client
|
||||
// ============================================================================
|
||||
struct SearchParams {
|
||||
std::string q;
|
||||
std::vector<std::string> type = {
|
||||
"video"}; // video, channel, playlist
|
||||
std::string part = "snippet";
|
||||
int maxResults = 5;
|
||||
std::string order = "relevance";
|
||||
std::string pageToken = "";
|
||||
std::string videoDuration = "any"; // any, long, medium, short
|
||||
bool rawQuery =
|
||||
false; // Set to true to preserve -, |, etc. in query
|
||||
};
|
||||
struct ShortenResponse {
|
||||
std::string shortUrl;
|
||||
};
|
||||
// ============================================================================
|
||||
// Main YouTube Client
|
||||
// ============================================================================
|
||||
|
||||
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 };
|
||||
|
||||
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); }
|
||||
class Client
|
||||
{
|
||||
public:
|
||||
|
||||
auto ShortUrl(const std::string& url) const -> Result<std::string>;
|
||||
// YouTube typically uses API Keys for public data, OAuth for user
|
||||
// data. Pass "" as accessToken if only using API Key.
|
||||
Client(std::string apiKey, std::string accessToken = "");
|
||||
~Client();
|
||||
auto GetBestStreams(const std::string &videoId)
|
||||
-> Result<::definitions::Streams>; // Configuration
|
||||
void SetVerbose(bool verbose) { m_Verbose = verbose; }
|
||||
void SetProxy(ProxyConfig config) { m_Proxy = std::move(config); }
|
||||
void SetAccessToken(std::string token)
|
||||
{
|
||||
m_AccessToken = std::move(token);
|
||||
}
|
||||
void SetApiKey(std::string key) { m_ApiKey = std::move(key); }
|
||||
|
||||
// ========================================================================
|
||||
// Search API
|
||||
// ========================================================================
|
||||
auto ShortUrl(const std::string &url) const -> Result<std::string>;
|
||||
|
||||
// https://developers.google.com/youtube/v3/docs/search/list
|
||||
auto Search(const SearchParams ¶ms) -> Result<PageResult<SearchResult>>;
|
||||
// ========================================================================
|
||||
// Search API
|
||||
// ========================================================================
|
||||
|
||||
// ========================================================================
|
||||
// Videos API
|
||||
// ========================================================================
|
||||
// https://developers.google.com/youtube/v3/docs/search/list
|
||||
auto Search(const SearchParams ¶ms)
|
||||
-> Result<PageResult<SearchResult>>;
|
||||
|
||||
// https://developers.google.com/youtube/v3/docs/videos/list
|
||||
auto GetVideo(const std::string &id,
|
||||
const std::string &part = "snippet,contentDetails,statistics")
|
||||
-> Result<Video>;
|
||||
// ========================================================================
|
||||
// Videos API
|
||||
// ========================================================================
|
||||
|
||||
auto GetVideos(const std::vector<std::string> &ids,
|
||||
const std::string &part = "snippet,contentDetails,statistics")
|
||||
-> Result<std::vector<Video>>;
|
||||
// https://developers.google.com/youtube/v3/docs/videos/list
|
||||
auto GetVideo(
|
||||
const std::string &id,
|
||||
const std::string &part = "snippet,contentDetails,statistics")
|
||||
-> Result<Video>;
|
||||
|
||||
// ========================================================================
|
||||
// Channels API
|
||||
// ========================================================================
|
||||
auto GetVideos(
|
||||
const std::vector<std::string> &ids,
|
||||
const std::string &part = "snippet,contentDetails,statistics")
|
||||
-> Result<std::vector<Video>>;
|
||||
|
||||
// https://developers.google.com/youtube/v3/docs/channels/list
|
||||
auto GetChannel(const std::string &id,
|
||||
const std::string &part = "snippet,statistics")
|
||||
-> Result<std::string>; // Returns raw JSON for brevity in this example
|
||||
// ========================================================================
|
||||
// Channels API
|
||||
// ========================================================================
|
||||
|
||||
// ========================================================================
|
||||
// Playlists API
|
||||
// ========================================================================
|
||||
// https://developers.google.com/youtube/v3/docs/channels/list
|
||||
auto GetChannel(const std::string &id,
|
||||
const std::string &part = "snippet,statistics")
|
||||
-> Result<std::string>; // Returns raw JSON for brevity in this
|
||||
// example
|
||||
|
||||
// https://developers.google.com/youtube/v3/docs/playlistItems/list
|
||||
auto GetPlaylistItems(const std::string &playlistId,
|
||||
const std::string &pageToken = "")
|
||||
-> Result<PageResult<SearchPlaylistResult>>; // Reusing SearchResult as structure
|
||||
// is similar enough for snippet
|
||||
auto GetPlaylistVideos(const std::string& playlistId) -> Result<std::vector<Video>>;
|
||||
// ========================================================================
|
||||
// Player API (The "Extraction" Logic)
|
||||
// ========================================================================
|
||||
// ========================================================================
|
||||
// Playlists API
|
||||
// ========================================================================
|
||||
|
||||
// Returns a raw https://googlevideo.com/... URL for the audio stream.
|
||||
// Returns error if the video is region locked or requires signature
|
||||
// deciphering.
|
||||
auto GetAudioStreamUrl(const std::string &videoId) -> Result<std::string>;
|
||||
// https://developers.google.com/youtube/v3/docs/playlistItems/list
|
||||
auto GetPlaylistItems(const std::string &playlistId,
|
||||
const std::string &pageToken = "")
|
||||
-> Result<PageResult<
|
||||
SearchPlaylistResult>>; // Reusing SearchResult as structure
|
||||
// is similar enough for snippet
|
||||
auto GetPlaylistVideos(const std::string &playlistId)
|
||||
-> Result<std::vector<Video>>;
|
||||
// ========================================================================
|
||||
// Player API (The "Extraction" Logic)
|
||||
// ========================================================================
|
||||
|
||||
auto ExtractVideoId(std::string_view url) const -> std::optional<std::string>;
|
||||
// Returns a raw https://googlevideo.com/... URL for the audio
|
||||
// stream. Returns error if the video is region locked or requires
|
||||
// signature deciphering.
|
||||
auto GetAudioStreamUrl(const std::string &videoId)
|
||||
-> Result<std::string>;
|
||||
|
||||
private:
|
||||
std::string m_ApiKey;
|
||||
std::string m_AccessToken;
|
||||
ProxyConfig m_Proxy;
|
||||
bool m_Verbose = false;
|
||||
const std::string m_BaseUrl = "https://www.googleapis.com/youtube/v3";
|
||||
JSRuntime *m_rt;
|
||||
JSContext *m_ctx;
|
||||
std::string m_preprocessedPlayer;
|
||||
auto ExtractVideoId(std::string_view url) const
|
||||
-> std::optional<std::string>;
|
||||
|
||||
// Helper methods for the solver logic
|
||||
void InitSolver();
|
||||
void SetPlayerJs(const std::string &js);
|
||||
std::string SolveChallenge(const std::string &challenge,
|
||||
const std::string &type);
|
||||
auto PerformRequest(
|
||||
const std::string &purl, const std::string &endpoint,
|
||||
const cpr::Parameters ¶ms = {},
|
||||
const cpr::Header &headers =
|
||||
{{"Content-Type", "application/json"},
|
||||
{"User-Agent",
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"}},
|
||||
HttpMethod method = HttpMethod::GET, const std::string &body = "")
|
||||
-> Result<std::string>;
|
||||
private:
|
||||
|
||||
auto PerformRequest(
|
||||
const std::string &endpoint, const cpr::Parameters ¶ms = {},
|
||||
const cpr::Header &headers =
|
||||
{{"Content-Type", "application/json"},
|
||||
{"User-Agent",
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"}},
|
||||
HttpMethod method = HttpMethod::GET, const std::string &body = "")
|
||||
-> Result<std::string>;
|
||||
// Helper specifically for the internal YouTube API (different Base URL)
|
||||
auto PerformInternalRequest(const std::string &endpoint,
|
||||
const std::string &jsonBody)
|
||||
-> Result<std::string>;
|
||||
static auto WriteCallback(void *contents, size_t size, size_t nmemb,
|
||||
std::string *out) -> size_t;
|
||||
auto UrlEncode(std::string_view value) const -> std::string;
|
||||
auto UrlEncodePreservingOperators(std::string_view query) const
|
||||
-> std::string;
|
||||
};
|
||||
std::string m_ApiKey;
|
||||
std::string m_AccessToken;
|
||||
ProxyConfig m_Proxy;
|
||||
bool m_Verbose = false;
|
||||
const std::string m_BaseUrl =
|
||||
"https://www.googleapis.com/youtube/v3";
|
||||
JSRuntime *m_rt;
|
||||
JSContext *m_ctx;
|
||||
std::string m_preprocessedPlayer;
|
||||
|
||||
// Helper methods for the solver logic
|
||||
void InitSolver();
|
||||
void SetPlayerJs(const std::string &js);
|
||||
std::string SolveChallenge(const std::string &challenge,
|
||||
const std::string &type);
|
||||
auto PerformRequest(
|
||||
const std::string &purl, const std::string &endpoint,
|
||||
const cpr::Parameters ¶ms = {},
|
||||
const cpr::Header &headers =
|
||||
{{"Content-Type", "application/json"},
|
||||
{"User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
|
||||
"AppleWebKit/537.36"}},
|
||||
HttpMethod method = HttpMethod::GET,
|
||||
const std::string &body = "") -> Result<std::string>;
|
||||
|
||||
auto PerformRequest(
|
||||
const std::string &endpoint, const cpr::Parameters ¶ms = {},
|
||||
const cpr::Header &headers =
|
||||
{{"Content-Type", "application/json"},
|
||||
{"User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
|
||||
"AppleWebKit/537.36"}},
|
||||
HttpMethod method = HttpMethod::GET,
|
||||
const std::string &body = "") -> Result<std::string>;
|
||||
// Helper specifically for the internal YouTube API (different Base
|
||||
// URL)
|
||||
auto PerformInternalRequest(const std::string &endpoint,
|
||||
const std::string &jsonBody)
|
||||
-> Result<std::string>;
|
||||
static auto WriteCallback(void *contents, size_t size, size_t nmemb,
|
||||
std::string *out) -> size_t;
|
||||
auto UrlEncode(std::string_view value) const -> std::string;
|
||||
auto UrlEncodePreservingOperators(std::string_view query) const
|
||||
-> std::string;
|
||||
};
|
||||
|
||||
} // namespace YouTube
|
||||
@@ -1,10 +1,11 @@
|
||||
#pragma once
|
||||
#include <string_view>
|
||||
|
||||
namespace YouTube::Internal {
|
||||
namespace YouTube::Internal
|
||||
{
|
||||
|
||||
// Replace the comment with the actual content of yt.solver.lib.js
|
||||
static constexpr std::string_view SOLVER_LIB_JS = R"js(
|
||||
// Replace the comment with the actual content of yt.solver.lib.js
|
||||
static constexpr std::string_view SOLVER_LIB_JS = R"js(
|
||||
/*!
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
* This file was automatically generated by https://github.com/yt-dlp/ejs
|
||||
@@ -13230,8 +13231,8 @@ var lib = (function (exports) {
|
||||
})({});
|
||||
)js";
|
||||
|
||||
// Replace the comment with the actual content of yt.solver.core.js
|
||||
static constexpr std::string_view SOLVER_CORE_JS = R"js(
|
||||
// Replace the comment with the actual content of yt.solver.core.js
|
||||
static constexpr std::string_view SOLVER_CORE_JS = R"js(
|
||||
var jsc = (function (meriyah, astring) {
|
||||
'use strict';
|
||||
// ... (Paste full content of yt.solver.core.js here) ...
|
||||
|
||||
+1418
-1418
File diff suppressed because it is too large.
Load diff
+30561
-30562
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user