#pragma once #include #include "NetworkClient.hpp" #include "YtDlpManager.hpp" #include #include #include #include #include namespace Echoion::Core { class YouTubeClient { public: explicit YouTubeClient(std::shared_ptr networkClient); ~YouTubeClient(); // Initialize the client - downloads yt-dlp if needed Api::Result initialize(); void shutdown(); // Check if yt-dlp is available [[nodiscard]] bool isAvailable() const; // Get yt-dlp version [[nodiscard]] std::string getYtDlpVersion() const; // Force update yt-dlp Api::Result updateYtDlp(); // Search for videos using yt-dlp [[nodiscard]] Api::Result search(std::string_view query, std::optional pageToken = std::nullopt); // Get video details including stream URLs using yt-dlp [[nodiscard]] Api::Result getVideoInfo(std::string_view videoId); // Get playlist videos using yt-dlp [[nodiscard]] Api::Result getPlaylist(std::string_view playlistId); // Extract video ID from various YouTube URL formats (handles redirects for short URLs) [[nodiscard]] std::optional extractVideoId(std::string_view url); [[nodiscard]] static std::optional extractPlaylistId(std::string_view url); // Check if URL is a YouTube URL [[nodiscard]] static bool isYouTubeUrl(std::string_view url); // Get stream URL for a video (used by MusicManager) [[nodiscard]] Api::Result getStreamUrl(std::string_view videoId); // Get best audio stream URL using yt-dlp [[nodiscard]] Api::Result getAudioStreamUrl(std::string_view videoId); // Configure cookie options for yt-dlp void setCookiesPath(const std::string& path); void setCookiesFromBrowser(const std::string& browser); private: std::shared_ptr networkClient_; std::unique_ptr ytDlpManager_; std::atomic initialized_{false}; mutable std::mutex mutex_; }; } // namespace Echoion::Core