Crate invidious

Source
Expand description

Rust bindings for the Invidious API.

§Quickstart

Get started by creating a client with ClientSync::default() and use the functions from there.

§Blocking API

use invidious::*;

fn main() {
    let client = ClientSync::default();
    let video = client.video("fBj3nEdCjkY", None).unwrap();
    let seach_results = client.search(Some("q=testing")).unwrap();
}

§Async API

Enable feature reqwest_async.

invidious = { version = "0.6", no-default-features = true, features = ["reqwest_async"]}
#[tokio::main]
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.

§Methods

Control how the client is making the web requests.

§Changing methods

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).

invidious = { version = "0.7", no-default-features = true, features = ["isahc_async"]}
let video = ClientAsync::default()
    .method(MethodAsync::Isahc)
    .video("fBj3nEdCjkY", None).await.unwrap();

If none of the fetch methods matches your needs, consider implmenting your own client struct. (Sync and async)

§Features

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.

FeatureCrate used
httpreq_sync (enabled by default)http_req
ureq_syncureq
minreq_syncminreq with https feature
minreq_http_syncminreq
reqwest_syncreqwest with blocking feature
reqwest_asyncreqwest
isahc_syncisahc
isahc_asyncisahc

§General usage

Most functions look something like:

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

Params allows user to include URL params as specified in the Invidious API docs.

The beginning question mark ? is omitted.

§How this works

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.

On a related note, you may use vidiup.siri.sh to look for instances with specific features enabled.

§Contributing

Contributions are welcome! Make a pull request at GitHub if you do.

  • Make changes to outdated bindings structs.
  • Add new fetch methods with either faster compile time or runtime.
  • Improve documentation.

Re-exports§

pub use async_trait;
pub use http_req;
pub use isahc;
pub use minreq;
pub use reqwest;
pub use ureq;

Modules§

channel
Channel related structs.
functions
Misc functions used in the crate.
hidden
Structs that act as building blocks for other structs.
universal
Structs that doesn’t belong in either of the other two categories.
video
Video related structs.

Structs§

ClientAsync
An async client, containing all info needed to perform a fetch.
ClientSync
A blocking client struct, containing all info needed to perform a fetch.
CommonChannel
Shared channel object as specified in https://docs.invidious.io/api/common_types/
CommonImage
Shared image object as specified in https://docs.invidious.io/api/common_types/
CommonPlaylist
Shared playlist object as specified in https://docs.invidious.io/api/common_types/
CommonPlaylistVideo
Playlist video struct used in CommonPlaylist
CommonThumbnail
Shared thumbnail object as specified in https://docs.invidious.io/api/common_types/
CommonVideo
Shared video object as specified in https://docs.invidious.io/api/common_types/

Enums§

InvidiousError
Error enum for the library.
MethodAsync
Request methods for ClientAsync.
MethodSync
Request methods for ClientSync.

Constants§

INSTANCE
Default instance used in ClientSync/ClientAsync::default().
USER_AGENT
Some instances required a user agent to be set, but it is not implmented yet

Traits§

ClientAsyncClone
ClientAsync, but with Clone
ClientAsyncTrait
Async Invidious client
ClientSyncClone
ClientSync, but with Clone
ClientSyncTrait
Sync Invidious client
PublicItems
A trait which contains all basic functionalites a binding struct should include.

Type Aliases§

AsyncMethodCustom
Type of a custom async fetch function
MethodReturn
Return type of fetch functions
MethodSyncCustom
Type of a custom sync fetch function