Migrate core infrastructure to VoidLibrary

This commit is contained in:
faumaray committed 2026-06-22 15:53:23 +03:00
1 parent 53801f2b53
commit 2bdb63766d
65 files changed
+16109 -12011

No files matched your search

+109 -100
View File
@@ -1,129 +1,138 @@
#pragma once
#include <filesystem>
#include <memory>
#include <mutex>
#include <optional>
#include <string>
#include <string_view>
#include <vector>
#include <optional>
#include <memory>
#include <mutex>
#include <filesystem>
#include <quickjs.h>
namespace Echoion::Core {
namespace Echoion::Core
{
/**
* Signature cipher for YouTube stream URLs
* Uses QuickJS (when available) to execute the JavaScript decipher functions from player JS
*
* Based on yt-dlp's signature extraction logic
*/
class SignatureCipher {
public:
SignatureCipher();
~SignatureCipher();
/**
* Signature cipher for YouTube stream URLs
* Uses QuickJS (when available) to execute the JavaScript decipher
* functions from player JS
*
* Based on yt-dlp's signature extraction logic
*/
class SignatureCipher
{
public:
// Disable copy, enable move
SignatureCipher(const SignatureCipher&) = delete;
SignatureCipher& operator=(const SignatureCipher&) = delete;
SignatureCipher(SignatureCipher&&) noexcept;
SignatureCipher& operator=(SignatureCipher&&) noexcept;
SignatureCipher();
~SignatureCipher();
/**
* Initialize the QuickJS solver with core libraries
* Must be called before using the cipher
*/
void initialize();
// Disable copy, enable move
SignatureCipher(const SignatureCipher&) = delete;
SignatureCipher& operator=(const SignatureCipher&) = delete;
SignatureCipher(SignatureCipher&&) noexcept;
SignatureCipher& operator=(SignatureCipher&&) noexcept;
/**
* Set the player JS code and extract decipher functions
* @param playerJsCode The raw player JavaScript code from YouTube
* @return true if extraction succeeded
*/
bool setPlayerJs(std::string_view playerJsCode);
/**
* Initialize the QuickJS solver with core libraries
* Must be called before using the cipher
*/
void initialize();
/**
* Check if the cipher is ready (has valid decipher function)
*/
[[nodiscard]] bool isReady() const;
/**
* Set the player JS code and extract decipher functions
* @param playerJsCode The raw player JavaScript code from YouTube
* @return true if extraction succeeded
*/
bool setPlayerJs(std::string_view playerJsCode);
/**
* Decipher a signature cipher string
* Format: s=ENCODED_SIG&sp=SIG_PARAM&url=ENCODED_URL
* @param signatureCipher The signature cipher string
* @return The full deciphered URL or empty string on failure
*/
[[nodiscard]] std::string decipher(std::string_view signatureCipher);
/**
* Check if the cipher is ready (has valid decipher function)
*/
[[nodiscard]] bool isReady() const;
/**
* Solve a challenge (signature or n-param) using the preprocessed player
* @param challenge The challenge string to solve
* @param type "sig" for signature, "n" for n-parameter
* @return The solved challenge or empty string on failure
*/
[[nodiscard]] std::string solveChallenge(const std::string& challenge, const std::string& type);
/**
* Decipher a signature cipher string
* Format: s=ENCODED_SIG&sp=SIG_PARAM&url=ENCODED_URL
* @param signatureCipher The signature cipher string
* @return The full deciphered URL or empty string on failure
*/
[[nodiscard]] std::string
decipher(std::string_view signatureCipher);
/**
* Decipher the n-parameter for throttling
* @param nParam The encoded n parameter
* @return The deciphered n parameter
*/
[[nodiscard]] std::string decipherNParam(std::string_view nParam);
/**
* Solve a challenge (signature or n-param) using the preprocessed
* player
* @param challenge The challenge string to solve
* @param type "sig" for signature, "n" for n-parameter
* @return The solved challenge or empty string on failure
*/
[[nodiscard]] std::string
solveChallenge(const std::string& challenge,
const std::string& type);
/**
* Clear the cipher state
*/
void clear();
/**
* Decipher the n-parameter for throttling
* @param nParam The encoded n parameter
* @return The deciphered n parameter
*/
[[nodiscard]] std::string decipherNParam(std::string_view nParam);
/**
* Check if cipher has been initialized
*/
[[nodiscard]] bool isInitialized() const;
/**
* Clear the cipher state
*/
void clear();
private:
/**
* Initialize QuickJS runtime and context with solver libraries
*/
void initSolver();
/**
* Check if cipher has been initialized
*/
[[nodiscard]] bool isInitialized() const;
/**
* Download solver libraries from remote URL
* @param url The URL to download from
* @return The downloaded JS code or empty string on failure
*/
[[nodiscard]] std::optional<std::string> downloadSolverLibrary(
std::string_view url);
private:
/**
* Get cache directory for storing solver libraries
*/
[[nodiscard]] std::filesystem::path getCacheDir();
/**
* Initialize QuickJS runtime and context with solver libraries
*/
void initSolver();
/**
* Execute JavaScript code in QuickJS and return result
*/
[[nodiscard]] std::optional<std::string> executeJS(
std::string_view code,
std::string_view filename = "<script>");
/**
* Download solver libraries from remote URL
* @param url The URL to download from
* @return The downloaded JS code or empty string on failure
*/
[[nodiscard]] std::optional<std::string>
downloadSolverLibrary(std::string_view url);
/**
* Cleanup QuickJS resources
*/
void cleanupQuickJS();
/**
* Get cache directory for storing solver libraries
*/
[[nodiscard]] std::filesystem::path getCacheDir();
JSRuntime* runtime_ = nullptr;
JSContext* context_ = nullptr;
/**
* Execute JavaScript code in QuickJS and return result
*/
[[nodiscard]] std::optional<std::string>
executeJS(std::string_view code,
std::string_view filename = "<script>");
// Player JS code and extracted functions
std::string playerJsCode_;
std::string preprocessedPlayer_;
/**
* Cleanup QuickJS resources
*/
void cleanupQuickJS();
// State
bool initialized_ = false;
bool solverInitialized_ = false;
bool hasPlayerJs_ = false;
JSRuntime* runtime_ = nullptr;
JSContext* context_ = nullptr;
mutable std::mutex mutex_;
};
// Player JS code and extracted functions
std::string playerJsCode_;
std::string preprocessedPlayer_;
// State
bool initialized_ = false;
bool solverInitialized_ = false;
bool hasPlayerJs_ = false;
mutable std::mutex mutex_;
};
} // namespace Echoion::Core