#pragma once #include "../NetworkClient.hpp" #include "TrackSource.hpp" #include #include #include #include #include #include namespace Echoion::Core { // Native Yandex Music source (unofficial api.music.yandex.net). Full // tracks require a Yandex OAuth token (sources.yandexToken) from an // account with Plus; without one this source reports unavailable and // yandex URLs keep routing to ytdlp-direct. // // Yandex is reachable directly in this deployment's region and may // geo-block foreign proxy exits, so every request deliberately bypasses // the configured proxy (NetworkClient::getDirect). class YandexMusicSource : public ITrackSource { public: // endpointOverride points tests at a StubHttpServer (it replaces // both the API base and the download-info hosts). explicit YandexMusicSource(std::shared_ptr network, std::string endpointOverride = ""); void configure(bool enabled, std::string token); [[nodiscard]] std::string_view name() const override { return "yandex"; } [[nodiscard]] bool canHandle(const std::string& query) const override; [[nodiscard]] bool isAvailable() const override; [[nodiscard]] bool supportsSearch() const override { return false; } Api::Result search(std::string_view query) override; Api::Result resolve(const std::string& urlOrId) override; Api::Result getStream(const Api::TrackInfo& track) override; // Album/playlist track listing for queue imports. [[nodiscard]] bool isCollectionUrl(const std::string& url) const; Api::Result> playlistTracks(const std::string& url); // Related/similar tracks for radio autoplay. trackId is the bare // Yandex numeric id (no "yandex:" prefix). Api::Result> related(const std::string& trackId, size_t limit = 10); // Extract the bare Yandex track id from a music.yandex.* URL, if it // is a single-track URL. Used to seed radio from history. [[nodiscard]] std::optional trackIdFromUrl(const std::string& url) const; private: Api::Result apiGet(const std::string& path); [[nodiscard]] std::string tokenSnapshot() const; std::shared_ptr network_; std::string endpoint_; std::atomic enabled_{true}; mutable std::mutex tokenMutex_; std::string token_; }; } // namespace Echoion::Core