implements youtube search

This commit is contained in:
2025-06-11 21:16:59 -07:00
parent 937a061cdd
commit 0e7305baa4
4 changed files with 219 additions and 1 deletions

View File

@@ -31,6 +31,22 @@ struct MediaItem: Codable
}
}
struct SearchResultItem: Codable
{
var type: String
var title: String
var author: String
var mediaUrl: String
var thumbnailUrl: String
}
struct FetchResult<T: Codable>: Codable
{
let success: Bool
let results: T?
let error: String?
}
struct NowPlayingInfo: Codable
{
let playingItem: MediaItem?
@@ -130,6 +146,12 @@ struct API
.post()
}
public func search(query: String) async throws -> FetchResult<[SearchResultItem]> {
try await request()
.pathString("/search?q=\(query.uriEncoded())")
.json()
}
public func events() async throws -> AsyncStream<StreamEvent> {
return AsyncStream { continuation in
var websocketTask: URLSessionWebSocketTask = spawnWebsocketTask(with: continuation)