15 releases
new 0.0.15 | Oct 26, 2024 |
---|---|
0.0.14 | Oct 24, 2024 |
0.0.13 | Sep 4, 2024 |
0.0.12 | Aug 17, 2024 |
0.0.1 | Dec 3, 2023 |
#1133 in Web programming
250 downloads per month
Used in youtui
430KB
10K
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
:
ytmapi_rs
Library into YouTube Music's internal API.
Examples
For additional examples using builder, see builder
module.
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(())
}
OAuth usage, using the workflow, and builder method to re-use the Client
.
#[tokio::main]
pub async fn main() -> Result<(), ytmapi_rs::Error> {
let client = ytmapi_rs::Client::new().unwrap();
let (code, url) = ytmapi_rs::generate_oauth_code_and_url(&client).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(&client, 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::YtMusicBuilder::new_with_client(client)
.with_oauth_token(token)
.build()
.unwrap();
let result = yt.get_search_suggestions("Beatles").await?;
println!("{:?}", result);
Ok(())
}
Optional Features
TLS
NOTE: reqwest will prefer to utilise default-tls if multiple features are
built when using the standard constructors. Use YtMusicBuilder
to ensure
the preferred choice of TLS is used. See reqwest docs for more information https://docs.rs/reqwest/latest/reqwest/tls/index.html.
- default-tls (enabled by default): Utilises the default TLS from reqwest - at the time of writing is native-tls.
- native-tls: This feature allows use of the the native-tls crate, reliant on vendors tls.
- rustls-tls: This feature allows use of the rustls crate, written in rust.
Other
- simplified_queries: Adds convenience methods to
YtMusic
. - serde_json: Enables some interoperability functions with
serde_json
.
Dependencies
~8–24MB
~395K SLoC