many different fixes

This commit is contained in:
faumaray committed 2026-02-03 05:07:15 +03:00
1 parent a583c17916
commit 53801f2b53
36 files changed
+5149 -1291

No files matched your search

+110 -21
View File
@@ -1,13 +1,19 @@
#pragma once
#include <echoion/api.hpp>
#include "NetworkClient.hpp"
#include "UrlShortener.hpp"
#include "YtDlpManager.hpp"
#include <regex>
#include <chrono>
#include <echoion/api.hpp>
#include <functional>
#include <future>
#include <memory>
#include <mutex>
#include <optional>
#include <regex>
#include <string>
#include <memory>
#include <unordered_map>
#include <vector>
namespace Echoion::Core {
@@ -29,21 +35,46 @@ public:
// Force update yt-dlp
Api::Result<void> updateYtDlp();
// Search for videos using yt-dlp
[[nodiscard]] Api::Result<Api::SearchResult> search(std::string_view query,
std::optional<std::string> pageToken = std::nullopt);
// Search for videos using YouTube Data API v3 (or yt-dlp as fallback)
[[nodiscard]] Api::Result<Api::SearchResult>
search(std::string_view query,
std::optional<std::string> pageToken = std::nullopt);
// Get video details including stream URLs using yt-dlp
[[nodiscard]] Api::Result<Api::TrackInfo> getVideoInfo(std::string_view videoId);
// Get video details including stream URLs using yt-dlp
[[nodiscard]] Api::Result<Api::TrackInfo> getVideoInfo(std::string_view videoId);
// Get playlist videos using yt-dlp
[[nodiscard]] Api::Result<Api::PlaylistInfo> getPlaylist(std::string_view playlistId);
// Get video details asynchronously
[[nodiscard]] std::future<Api::Result<Api::TrackInfo>>
getVideoInfoAsync(std::string_view videoId);
// Extract video ID from various YouTube URL formats (handles redirects for short URLs)
[[nodiscard]] std::optional<std::string> extractVideoId(std::string_view url);
[[nodiscard]] static std::optional<std::string> extractPlaylistId(std::string_view url);
// Get multiple video details concurrently
[[nodiscard]] std::vector<Api::Result<Api::TrackInfo>>
getVideoInfoBatch(const std::vector<std::string>& videoIds);
// Check if URL is a YouTube URL
// Get playlist videos - uses YouTube API v2 if key available, otherwise
// yt-dlp Then resolves each track individually via yt-dlp for full metadata
[[nodiscard]] Api::Result<Api::PlaylistInfo>
getPlaylist(std::string_view playlistId);
// Get playlist videos asynchronously with concurrent track resolution
[[nodiscard]] std::future<Api::Result<Api::PlaylistInfo>>
getPlaylistAsync(std::string_view playlistId);
// Stream playlist tracks with callback - calls trackCallback for each track
// as it is resolved, enabling immediate playback of first track
void getPlaylistStreaming(std::string_view playlistId,
std::function<void(Api::TrackInfo&&)> trackCallback,
std::function<void(size_t totalTracks)> onPlaylistInfo = nullptr,
std::function<void()> onComplete = nullptr);
// Extract video ID from various YouTube URL formats (handles redirects for
// short URLs)
[[nodiscard]] std::optional<std::string>
extractVideoId(std::string_view url);
[[nodiscard]] static std::optional<std::string>
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)
@@ -56,12 +87,70 @@ public:
void setCookiesPath(const std::string& path);
void setCookiesFromBrowser(const std::string& browser);
private:
std::shared_ptr<NetworkClient> networkClient_;
std::unique_ptr<YtDlpManager> ytDlpManager_;
std::atomic<bool> initialized_{false};
mutable std::mutex mutex_;
};
// Configure proxy for yt-dlp
void setProxyConfig(const std::optional<Api::ProxyConfig>& proxy);
[[nodiscard]] std::optional<Api::ProxyConfig> getProxyConfig() const;
// Set YouTube API key for enhanced playlist resolution (optional)
void setApiKey(const std::string& apiKey);
[[nodiscard]] bool hasApiKey() const;
// Configure concurrent resolution settings
void setMaxConcurrentResolutions(size_t max);
[[nodiscard]] size_t getMaxConcurrentResolutions() const;
// Enable/disable URL shortening for track links
void setUrlShorteningEnabled(bool enabled);
[[nodiscard]] bool isUrlShorteningEnabled() const;
private:
// Internal search implementations
[[nodiscard]] Api::Result<Api::SearchResult>
searchWithApi(std::string_view query,
const std::optional<std::string>& pageToken);
[[nodiscard]] Api::Result<Api::SearchResult>
searchWithYtDlp(std::string_view query,
const std::optional<std::string>& pageToken);
// Fetch video durations for search results (batch API call)
void fetchVideoDurations(std::vector<Api::TrackInfo>& tracks,
const std::vector<std::string>& videoIds);
// Parse ISO 8601 duration string
[[nodiscard]] static std::chrono::seconds
parseIso8601Duration(const std::string& duration);
// URL encode/decode helpers
[[nodiscard]] static std::string urlEncode(std::string_view value);
[[nodiscard]] static std::string decodeHtmlEntities(std::string_view value);
// Internal methods for playlist resolution
[[nodiscard]] Api::Result<std::vector<Api::YouTubePlaylistItem>>
fetchPlaylistItems(std::string_view playlistId);
[[nodiscard]] Api::Result<Api::TrackInfo>
resolveTrackWithYtDlp(const Api::YouTubePlaylistItem& item);
// Build YouTube API v3 URL for playlist items
[[nodiscard]] std::string buildPlaylistApiUrl(
std::string_view playlistId,
const std::optional<std::string>& pageToken = std::nullopt) const;
std::shared_ptr<NetworkClient> networkClient_;
std::unique_ptr<YtDlpManager> ytDlpManager_;
std::unique_ptr<UrlShortener> urlShortener_;
std::atomic<bool> initialized_{false};
mutable std::mutex mutex_;
// Configuration
std::optional<std::string> apiKey_;
mutable std::mutex configMutex_;
size_t maxConcurrentResolutions_ = 4;
bool urlShorteningEnabled_ = true;
// Populate shortened URLs for tracks
void populateShortenedUrls(std::vector<Api::TrackInfo>& tracks);
void populateShortenedUrl(Api::TrackInfo& track);
};
} // namespace Echoion::Core