1 parent
df99b6ea7f
commit
d146f11f02
63 files changed
+8331
-2709
No files matched your search
@@ -0,0 +1,79 @@
|
||||
#pragma once
|
||||
|
||||
#include "../NetworkClient.hpp"
|
||||
#include "TrackSource.hpp"
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
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<NetworkClient> 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<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;
|
||||
|
||||
// Album/playlist track listing for queue imports.
|
||||
[[nodiscard]] bool isCollectionUrl(const std::string& url) const;
|
||||
Api::Result<std::vector<Api::TrackInfo>>
|
||||
playlistTracks(const std::string& url);
|
||||
|
||||
// Related/similar tracks for radio autoplay. trackId is the bare
|
||||
// Yandex numeric id (no "yandex:" prefix).
|
||||
Api::Result<std::vector<Api::TrackInfo>>
|
||||
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<std::string>
|
||||
trackIdFromUrl(const std::string& url) const;
|
||||
|
||||
private:
|
||||
|
||||
Api::Result<std::string> apiGet(const std::string& path);
|
||||
[[nodiscard]] std::string tokenSnapshot() const;
|
||||
|
||||
std::shared_ptr<NetworkClient> network_;
|
||||
std::string endpoint_;
|
||||
std::atomic<bool> enabled_{true};
|
||||
mutable std::mutex tokenMutex_;
|
||||
std::string token_;
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
Reference in new issue
Block a user