Files
faumaray d146f11f02 Release 1.0.0
Signed-off-by: faumaray <faumaray@gmail.com>
2026-07-04 01:49:28 +03:00

59 lines
1.7 KiB
C++

#pragma once
#include "../YouTubeClient.hpp"
#include "TrackSource.hpp"
#include <memory>
namespace Echoion::Core
{
// yt-dlp-backed source, in two router entries over the same
// YouTubeClient:
// - Direct ("ytdlp-direct", useProxy=false): non-YouTube extractor URLs
// (SoundCloud, Bandcamp, VK, Yandex, radio pages) reachable without a
// proxy. Never handles bare text search.
// - Proxied ("ytdlp-proxied", useProxy=true): last-resort YouTube
// resolution + text search through the configured proxy; also owns
// the SOCKS5 download-to-file path.
class YtDlpSource : public ITrackSource
{
public:
enum class Mode { Direct, Proxied };
YtDlpSource(std::shared_ptr<YouTubeClient> client, Mode mode,
std::string tempDir);
[[nodiscard]] std::string_view name() const override
{
return mode_ == Mode::Direct ? "ytdlp-direct"
: "ytdlp-proxied";
}
[[nodiscard]] bool canHandle(const std::string& query) const override;
[[nodiscard]] bool isAvailable() const override;
[[nodiscard]] bool supportsSearch() const override
{
return mode_ == Mode::Proxied;
}
Api::Result<Api::SearchResult>
search(std::string_view query) override;
Api::Result<Api::TrackInfo>
resolve(const std::string& urlOrId) override;
Api::Result<StreamHandle>
getStream(const Api::TrackInfo& track) override;
// Force the download-to-file path on the next getStream (set by
// the router's preferDownload retry).
Api::Result<StreamHandle>
getStreamViaDownload(const Api::TrackInfo& track);
private:
std::shared_ptr<YouTubeClient> client_;
Mode mode_;
std::string tempDir_;
};
} // namespace Echoion::Core