12 个版本
新 0.0.12 | 2024 年 8 月 17 日 |
---|---|
0.0.11 | 2024 年 8 月 12 日 |
0.0.9 | 2024 年 7 月 31 日 |
0.0.4 | 2024 年 6 月 27 日 |
0.0.1 | 2023 年 12 月 3 日 |
#2013 在 Web 编程
每月 763 次下载
在 youtui 中使用
385KB
9K SLoC
关于
Ytmapi-rs - YouTube 音乐的异步 API - 使用 Google 的内部 API、Tokio 和 Reqwest。灵感来源于 https://github.com/sigma67/ytmusicapi/。
此项目未得到 Google 的支持或认可。
请参阅 docs.rs 以获取文档和用法示例。
lib.rs
:
ytmapi_rs
将库集成到 YouTube 音乐的内部 API 中。
示例
有关使用 builder 的其他示例,请参阅 builder
模块。
使用预先创建的 cookie 文件的基本用法。
#[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 用法,使用工作流程和 builder 方法重用 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(())
}
可选功能
TLS
注意:当使用标准构造函数构建多个功能时,reqwest 将优先使用 default-tls。使用 YtMusicBuilder
确保首选 TLS 的选择。有关更多信息,请参阅 reqwest 文档 https://docs.rs/reqwest/latest/reqwest/tls/index.html。
- default-tls (默认启用):使用 reqwest 的默认 TLS - 编写时是 native-tls。
- native-tls:此功能允许使用依赖供应商 TLS 的 native-tls crate。
- rustls-tls:此功能允许使用用 rust 编写的 rustls crate。
其他
- simplified_queries:向
YtMusic
添加方便的方法。 - serde_json:启用与
serde_json
的某些互操作性函数。
依赖项
~8–23MB
~395K SLoC