Server-backed Rust client for the Riva media proxy.
By default, this crate targets the riva servers. You can override the server with environment variables.
youtube(enabled by default)soundcloud(enabled by default)
Disable defaults if needed:
[dependencies]
riva = { version = "1", default-features = false, features = ["youtube"] }Base URL (first non-empty value wins):
RIVA_BASE_URLRIVA_SERVER_URLRIVA_URL
Access secret (optional, first non-empty value wins):
RIVA_ACCESS_SECRETRIVA_API_KEYRIVA_TOKEN
If an access secret is set, the client sends Authorization: Bearer <secret>.
use riva::RivaClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = RivaClient::from_env()?;
let health = client.health().await?;
println!("{} @ {}", health.status, health.time);
Ok(())
}use riva::{RivaClient, YoutubeClientType};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = RivaClient::from_env()?;
let info = client
.youtube_info("rkaiKn5iGzc", Some(YoutubeClientType::Web))
.await?;
println!("video info: {info}");
let response = client
.youtube_stream("rkaiKn5iGzc", 18, Some(YoutubeClientType::Web))
.await?;
let mut stream = response.bytes_stream();
while let Some(chunk) = stream.next().await {
let bytes = chunk?;
println!("received {} bytes", bytes.len());
}
Ok(())
}For bytes_stream() consumption, add:
futures-util = "0.3"and import:
use futures_util::StreamExt;use riva::RivaClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = RivaClient::from_env()?;
let response = client
.soundcloud_stream("https://soundcloud.com/kordhell/trageluxe")
.await?;
let bytes = response.bytes().await?;
println!("downloaded {} bytes", bytes.len());
Ok(())
}RivaClient::from_env()RivaClient::new(config)RivaClient::health()RivaClient::youtube_info(...)(feature:youtube)RivaClient::youtube_stream(...)(feature:youtube)RivaClient::soundcloud_stream(...)(feature:soundcloud)