Rust bindings for the Invidious API.
"May Invidious live and prosper, with, or without us."
~ The Invidious team on YouTube trying to take them down.
Go show them some support by donating and starring their GitHub repos!
Get started by creating a client with ClientSync::default()
and use the functions from there.
```rust use invidious::*;
fn main() { let client = ClientSync::default(); let video = client.video("fBj3nEdCjkY", None).unwrap(); let seach_results = client.search(Some("q=testing")).unwrap(); } ```
Enable feature reqwest_async
.
toml
invidious = { version = "0.6", no-default-features = true, features = ["reqwest_async"]}
```rust
async fn main() { let client = ClientAsync::default(); let vidio = client.video("fBj3nEdCjkY", None).await.unwrap(); let seach_results = client.search(Some("q=testing")).await.unwrap(); } ```
Read more about ClientSync
and ClientAsync
to see all avaliable functions.
Control how the client is making the web requests.
For example, to use isahc
instead of reqwest
for sending requests in ClientAsync
, first
enable the isahc_async
feature and optionally disable the reqwest_async
feature (if
enabled).
toml
invidious = { version = "6.0", no-default-features = true, features = ["isahc_async"]}
rust
let video = ClientAsync::default()
.method(MethodAsync::ISAHC)
.video("fBj3nEdCjkY", None).await.unwrap();
If the existing methods are not suitable for use (takes too long to compile, resource inefficient, does not support async runtime), you can use your own fetch function instead.
toml
invidious = { version = "6.0", no-default-features = true, features = ["async"]}
See no fetch features are enabled, just async
which enables ClientAsync
and related code.
```rust
async fn main() { let video = ClientAsync::default() .custommethod(Box::new(customfetch)) .video("fBj3nEdCjkY", None).await.unwrap(); }
// MethodReturn is just short for Result<String, Box<dyn Error>>
async fn custom_fetch(url: String) -> MethodReturn {
Ok(reqwest::get(url).await?.text().await?)
}
```
This crate utilises features for specifying which crates to use for fetching the http(s) responses. Only crates that are needed are included. Different features result in various compile times and performances. The compile times of each feature can be found in MethodSync
and MethodAsync
.
All avaliable features are listed below.
|Feature|Crate used|
|---|---|
|httpreq_sync
(enabled by default)|http_req|
|ureq_sync
|ureq|
|minreq_sync
|minreq with https feature|
|minreq_http_sync
|minreq|
|reqwest_sync
|reqwest with blocking feature|
|reqwest_async
|reqwest|
|isahc_sync
|isahc|
|isahc_async
|isahc|
Most functions look something like:
rs
client.function_name(id: &str, params: Option<&str>) // when id is needed.
client.function_name(params: Option<&str>) // when id is not needed, for example search.
Params allows user to include URL params as specified in the Invidious API docs.
The beginning question mark ?
is omitted.
Invidious is an alternative frontend for YouTube, and also offering an API.
This crate includes structs for each of the API endpoints, and allowing users to include any extra parameters they want. Then uses the serde crate to serialize and deserialize json responses from the Invidious API.
Contributions are welcome! Make a pull request at GitHub if you do.
License: GPL-3.0