Migrate to VoidLibrary (toolchain + API groundwork)
This commit is contained in:
1 parent
5e1e3d66c4
commit
e17cfed56f
38 files changed
+3077
-2505
No files matched your search
@@ -0,0 +1,143 @@
|
||||
#pragma once
|
||||
|
||||
#include "TrackTypes.hpp"
|
||||
#include "Types.hpp"
|
||||
#include <chrono>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Echoion::Api
|
||||
{
|
||||
|
||||
// YouTube-specific types for the extracted client algorithm
|
||||
|
||||
struct YouTubeFormat {
|
||||
std::string itag;
|
||||
std::string mimeType;
|
||||
std::optional<std::string> url;
|
||||
std::optional<std::string> signatureCipher;
|
||||
int32_t bitrate;
|
||||
int32_t width;
|
||||
int32_t height;
|
||||
std::optional<std::string> qualityLabel;
|
||||
std::optional<std::string> audioQuality;
|
||||
int32_t audioSampleRate;
|
||||
int32_t audioChannels;
|
||||
bool hasVideo;
|
||||
bool hasAudio;
|
||||
};
|
||||
|
||||
struct YouTubeVideoDetails {
|
||||
std::string videoId;
|
||||
std::string title;
|
||||
std::string author;
|
||||
std::optional<std::chrono::seconds> lengthSeconds;
|
||||
std::vector<YouTubeFormat> formats;
|
||||
std::vector<YouTubeFormat> adaptiveFormats;
|
||||
std::optional<std::string> playerJsUrl;
|
||||
std::optional<std::string> streamingData;
|
||||
};
|
||||
|
||||
struct YouTubeSearchResult {
|
||||
std::string videoId;
|
||||
std::string title;
|
||||
std::string channelTitle;
|
||||
std::optional<std::chrono::seconds> duration;
|
||||
std::optional<std::string> thumbnailUrl;
|
||||
std::string publishedAt;
|
||||
uint64_t viewCount;
|
||||
};
|
||||
|
||||
struct YouTubePlaylistItem {
|
||||
std::string videoId;
|
||||
std::string title;
|
||||
std::optional<std::chrono::seconds> duration;
|
||||
std::optional<std::string> thumbnailUrl;
|
||||
};
|
||||
|
||||
struct YouTubePlaylist {
|
||||
std::string playlistId;
|
||||
std::string title;
|
||||
std::string author;
|
||||
std::vector<YouTubePlaylistItem> videos;
|
||||
std::optional<std::string> continuationToken;
|
||||
};
|
||||
|
||||
struct YouTubePlayerConfig {
|
||||
std::string innertubeApiKey;
|
||||
std::string innertubeClientName;
|
||||
std::string innertubeClientVersion;
|
||||
std::string contextClientName;
|
||||
std::string contextClientVersion;
|
||||
std::string visitorData;
|
||||
std::optional<std::string> poToken;
|
||||
};
|
||||
|
||||
struct YouTubeClientContext {
|
||||
std::string hl = "en";
|
||||
std::string gl = "US";
|
||||
std::string clientName = "WEB";
|
||||
std::string clientVersion;
|
||||
std::optional<std::string> visitorData;
|
||||
std::optional<std::string> userAgent;
|
||||
};
|
||||
|
||||
// Convert YouTube types to generic TrackInfo
|
||||
[[nodiscard]] inline TrackInfo
|
||||
ConvertToTrackInfo(const YouTubeVideoDetails& details)
|
||||
{
|
||||
TrackInfo info;
|
||||
info.id = details.videoId;
|
||||
info.title = details.title;
|
||||
info.artist = details.author;
|
||||
if (details.lengthSeconds.has_value()) {
|
||||
info.duration =
|
||||
std::chrono::milliseconds(*details.lengthSeconds * 1000);
|
||||
}
|
||||
info.source = TrackSource::YouTube;
|
||||
info.originalUrl = "https://youtube.com/watch?v=" + details.videoId;
|
||||
return info;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline TrackInfo
|
||||
ConvertToTrackInfo(const YouTubeSearchResult& result)
|
||||
{
|
||||
TrackInfo info;
|
||||
info.id = result.videoId;
|
||||
info.title = result.title;
|
||||
info.artist = result.channelTitle;
|
||||
if (result.duration.has_value()) {
|
||||
info.duration = std::chrono::milliseconds(*result.duration * 1000);
|
||||
}
|
||||
info.thumbnailUrl = result.thumbnailUrl;
|
||||
info.source = TrackSource::YouTube;
|
||||
info.originalUrl = "https://youtube.com/watch?v=" + result.videoId;
|
||||
return info;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline PlaylistInfo
|
||||
ConvertToPlaylistInfo(const YouTubePlaylist& playlist)
|
||||
{
|
||||
PlaylistInfo info;
|
||||
info.id = playlist.playlistId;
|
||||
info.name = playlist.title;
|
||||
info.owner = playlist.author;
|
||||
// Convert playlist items to tracks
|
||||
for (const auto& item : playlist.videos) {
|
||||
TrackInfo track;
|
||||
track.id = item.videoId;
|
||||
track.title = item.title;
|
||||
track.source = TrackSource::YouTube;
|
||||
track.originalUrl = "https://youtube.com/watch?v=" + item.videoId;
|
||||
if (item.duration.has_value()) {
|
||||
track.duration =
|
||||
std::chrono::milliseconds(*item.duration * 1000);
|
||||
}
|
||||
track.thumbnailUrl = item.thumbnailUrl;
|
||||
info.tracks.push_back(std::move(track));
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
} // namespace Echoion::Api
|
||||
Reference in new issue
Block a user