#api-wrapper #youtube #api #wrapper #async-api #http-request #http-response

invidious

Get information about videos from YouTube with this simple Invidious API wrapper. Does not use the YouTube API (No tokens required)

18 unstable releases (6 breaking)

0.7.4 Oct 27, 2023
0.7.2 Sep 27, 2023
0.6.4 Jul 25, 2023
0.4.1 Dec 9, 2022
0.3.1 Jul 30, 2022

#224 in Web programming

Download history 7/week @ 2024-01-01 2/week @ 2024-01-08 18/week @ 2024-01-22 14/week @ 2024-01-29 12/week @ 2024-02-05 34/week @ 2024-02-12 37/week @ 2024-02-19 69/week @ 2024-02-26 30/week @ 2024-03-04 101/week @ 2024-03-11 41/week @ 2024-03-18 7/week @ 2024-03-25 87/week @ 2024-04-01 27/week @ 2024-04-08 57/week @ 2024-04-15

181 downloads per month
Used in 2 crates

AGPL-3.0

70KB
2K SLoC

invidious

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 = "6.0", 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.

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

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.

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.

License: GPL-3.0

Dependencies

~0.7–19MB
~261K SLoC