many different fixes
This commit is contained in:
1 parent
a583c17916
commit
53801f2b53
36 files changed
+5149
-1291
No files matched your search
@@ -1,14 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <echoion/api.hpp>
|
||||
#include "NetworkClient.hpp"
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <echoion/api.hpp>
|
||||
#include <filesystem>
|
||||
#include <future>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
namespace Echoion::Core {
|
||||
|
||||
struct YtDlpResult {
|
||||
std::string output;
|
||||
int exitCode;
|
||||
bool success;
|
||||
std::chrono::milliseconds executionTime;
|
||||
};
|
||||
|
||||
class YtDlpManager {
|
||||
public:
|
||||
explicit YtDlpManager(std::shared_ptr<NetworkClient> networkClient);
|
||||
@@ -28,17 +40,34 @@ public:
|
||||
|
||||
// Force update yt-dlp to latest version
|
||||
Api::Result<void> update();
|
||||
|
||||
// Execute yt-dlp with given arguments and return output
|
||||
[[nodiscard]] std::string execute(const std::vector<std::string>& args) const;
|
||||
|
||||
// Set cookie options for YouTube authentication
|
||||
void setCookiesPath(const std::string& path);
|
||||
void setCookiesFromBrowser(const std::string& browser);
|
||||
|
||||
// Execute yt-dlp with given arguments and return output (synchronous)
|
||||
[[nodiscard]] std::string
|
||||
execute(const std::vector<std::string>& args) const;
|
||||
|
||||
// Execute yt-dlp asynchronously and return a future
|
||||
[[nodiscard]] std::future<YtDlpResult>
|
||||
executeAsync(const std::vector<std::string>& args);
|
||||
|
||||
// Execute multiple yt-dlp commands concurrently
|
||||
[[nodiscard]] std::vector<YtDlpResult>
|
||||
executeBatch(const std::vector<std::vector<std::string>>& argsList);
|
||||
|
||||
// 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<std::string> getCookieArgs() const;
|
||||
|
||||
// Set proxy configuration for yt-dlp
|
||||
void setProxyConfig(const std::optional<Api::ProxyConfig>& proxy);
|
||||
[[nodiscard]] std::optional<Api::ProxyConfig> getProxyConfig() const;
|
||||
|
||||
// Configure thread pool size for async operations (default: 4)
|
||||
void setThreadPoolSize(size_t size);
|
||||
[[nodiscard]] size_t getThreadPoolSize() const;
|
||||
|
||||
private:
|
||||
// Get the storage directory for yt-dlp
|
||||
[[nodiscard]] std::filesystem::path getStorageDir() const;
|
||||
@@ -58,19 +87,50 @@ private:
|
||||
// Get download URL based on platform
|
||||
[[nodiscard]] std::string getDownloadUrl() const;
|
||||
|
||||
std::shared_ptr<NetworkClient> networkClient_;
|
||||
std::filesystem::path executablePath_;
|
||||
std::atomic<bool> initialized_{false};
|
||||
// Internal execute implementation
|
||||
[[nodiscard]] YtDlpResult
|
||||
executeInternal(const std::vector<std::string>& args) const;
|
||||
|
||||
// Build the full command with all options
|
||||
[[nodiscard]] std::string
|
||||
buildCommand(const std::vector<std::string>& args) const;
|
||||
|
||||
// Get proxy arguments for yt-dlp command
|
||||
[[nodiscard]] std::vector<std::string> getProxyArgs() const;
|
||||
|
||||
// Escape shell argument
|
||||
[[nodiscard]] static std::string escapeArg(const std::string& arg);
|
||||
|
||||
// Thread pool for async operations
|
||||
void startThreadPool();
|
||||
void stopThreadPool();
|
||||
void workerThread();
|
||||
|
||||
std::shared_ptr<NetworkClient> networkClient_;
|
||||
std::filesystem::path executablePath_;
|
||||
std::atomic<bool> initialized_{false};
|
||||
mutable std::mutex mutex_;
|
||||
|
||||
// Cookie configuration for YouTube authentication
|
||||
std::optional<std::string> cookiesPath_;
|
||||
std::optional<std::string> 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 =
|
||||
|
||||
// Proxy configuration
|
||||
std::optional<Api::ProxyConfig> proxyConfig_;
|
||||
mutable std::mutex proxyMutex_;
|
||||
|
||||
// Thread pool for async operations
|
||||
size_t threadPoolSize_ = 4;
|
||||
std::vector<std::jthread> threadPool_;
|
||||
std::queue<std::packaged_task<YtDlpResult()>> taskQueue_;
|
||||
std::mutex taskMutex_;
|
||||
std::condition_variable taskCv_;
|
||||
std::atomic<bool> stopThreads_{false};
|
||||
|
||||
// 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";
|
||||
|
||||
Reference in new issue
Block a user