#pragma once #include #include "NetworkClient.hpp" #include #include #include #include namespace Echoion::Core { class YtDlpManager { public: explicit YtDlpManager(std::shared_ptr networkClient); ~YtDlpManager(); // Initialize - checks for yt-dlp and downloads if needed Api::Result initialize(); // Get the path to the yt-dlp executable [[nodiscard]] std::filesystem::path getExecutablePath() const; // Check if yt-dlp is available [[nodiscard]] bool isAvailable() const; // Get yt-dlp version [[nodiscard]] std::string getVersion() const; // Force update yt-dlp to latest version Api::Result update(); // Execute yt-dlp with given arguments and return output [[nodiscard]] std::string execute(const std::vector& args) const; // Set cookie options for YouTube authentication void setCookiesPath(const std::string& path); void setCookiesFromBrowser(const std::string& browser); // Get cookie arguments for yt-dlp command [[nodiscard]] std::vector getCookieArgs() const; private: // Get the storage directory for yt-dlp [[nodiscard]] std::filesystem::path getStorageDir() const; // Get the executable name based on platform [[nodiscard]] std::string getExecutableName() const; // Download yt-dlp from official source Api::Result downloadYtDlp(); // Make executable executable (Unix only) Api::Result makeExecutable(); // Check if update is needed (older than 7 days) [[nodiscard]] bool shouldUpdate() const; // Get download URL based on platform [[nodiscard]] std::string getDownloadUrl() const; std::shared_ptr networkClient_; std::filesystem::path executablePath_; std::atomic initialized_{false}; mutable std::mutex mutex_; // Cookie configuration for YouTube authentication std::optional cookiesPath_; std::optional cookiesFromBrowser_; // yt-dlp download URLs static constexpr std::string_view YTDLP_VERSION_URL = "https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest"; static constexpr std::string_view YTDLP_DOWNLOAD_LINUX = "https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp"; static constexpr std::string_view YTDLP_DOWNLOAD_WINDOWS = "https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe"; static constexpr std::string_view YTDLP_DOWNLOAD_MACOS = "https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_macos"; }; } // namespace Echoion::Core