#music #youtube #tokio #google-api #internal #asynchronous #reqwest

ytmapi-rs

An asynchronous (tokio) pure Rust API for Youtube Music using Google's internal API

2 releases

0.0.2 Jan 11, 2024
0.0.1 Dec 3, 2023

#1412 in Web programming

38 downloads per month
Used in youtui

MIT license

655KB
5K SLoC

About

Ytmapi-rs - an asynchronous API for youtube music - using Google's internal API, Tokio and Reqwest. Inspired by https://github.com/sigma67/ytmusicapi/.

This project is not supported or endorsed by Google.

Please refer to docs.rs for documentation and usage examples.


lib.rs:

Library into YouTube Music's internal API.

Examples

Basic usage with a pre-created cookie file :

#[tokio::main]
pub async fn main() -> Result<(), ytmapi_rs::Error> {
    let cookie_path = std::path::Path::new("./cookie.txt");
    let yt = ytmapi_rs::YtMusic::from_cookie_file(cookie_path).await?;
    yt.get_search_suggestions("Beatles").await?;
    let result = yt.get_search_suggestions("Beatles").await?;
    println!("{:?}", result);
    Ok(())
}

Basic usage - oauth:

#[tokio::main]
pub async fn main() -> Result<(), ytmapi_rs::Error> {
    let (code, url) = ytmapi_rs::generate_oauth_code_and_url().await?;
    println!("Go to {url}, finish the login flow, and press enter when done");
    let mut _buf = String::new();
    let _ = std::io::stdin().read_line(&mut _buf);
    let token = ytmapi_rs::generate_oauth_token(code).await?;
    // NOTE: The token can be re-used until it expires, and refreshed once it has,
    // so it's recommended to save it to a file here.
    let yt = ytmapi_rs::YtMusic::from_oauth_token(token);
    let result = yt.get_search_suggestions("Beatles").await?;
    println!("{:?}", result);
    Ok(())
}

Dependencies

~8–24MB
~332K SLoC