1 个不稳定版本
新版本 0.3.0 | 2024 年 8 月 18 日 |
---|
在 多媒体 分类中排名第 27 位
1MB
25K SLoC
RustyPipe 是一个功能齐全的 Rust 客户端,用于公共 YouTube / YouTube Music API (Innertube),受 NewPipe 启发。
功能
YouTube
- 播放器(视频/音频流,字幕)
- 视频详情(元数据,评论,推荐视频)
- 播放列表
- 频道(视频,短片,直播,播放列表,信息,搜索)
- 频道 RSS
- 搜索(带筛选器)
- 搜索建议
- 热门
- URL 解析器
YouTube Music
- 播放列表
- 专辑
- 艺术家
- 搜索
- 搜索建议
- 电台
- 曲目详情(歌词,推荐)
- 心情/流派
- 排行榜
- 新(专辑,音乐视频)
入门
Cargo.toml
[dependencies]
rustypipe = "0.1.3"
tokio = { version = "1.20.0", features = ["macros", "rt-multi-thread"] }
观看视频
use std::process::Command;
use rustypipe::{client::RustyPipe, param::StreamFilter};
#[tokio::main]
async fn main() {
// Create a client
let rp = RustyPipe::new();
// Fetch the player
let player = rp.query().player("pPvd8UxmSbQ").await.unwrap();
// Select the best streams
let (video, audio) = player.select_video_audio_stream(&StreamFilter::default());
// Open mpv player
let mut args = vec![video.expect("no video stream").url.to_owned()];
if let Some(audio) = audio {
args.push(format!("--audio-file={}", audio.url));
}
Command::new("mpv").args(args).output().unwrap();
}
获取播放列表
use rustypipe::client::RustyPipe
#[tokio::main]
async fn main() {
// Create a client
let rp = RustyPipe::new();
// Get the playlist
let playlist = rp
.query()
.playlist("PL2_OBreMn7FrsiSW0VDZjdq0xqUKkZYHT")
.await
.unwrap();
// Get all items (maximum: 1000)
playlist.videos.extend_limit(rp.query(), 1000).await.unwrap();
println!("Name: {}", playlist.name);
println!("Author: {}", playlist.channel.unwrap().name);
println!("Last update: {}", playlist.last_update.unwrap());
playlist
.videos
.items
.iter()
.for_each(|v| println!("[{}] {} ({}s)", v.id, v.name, v.length));
}
输出
Name: Homelab
Author: Jeff Geerling
Last update: 2023-05-04
[cVWF3u-y-Zg] I put a computer in my computer (720s)
[ecdm3oA-QdQ] 6-in-1: Build a 6-node Ceph cluster on this Mini ITX Motherboard (783s)
[xvE4HNJZeIg] Scrapyard Server: Fastest all-SSD NAS! (733s)
[RvnG-ywF6_s] Nanosecond clock sync with a Raspberry Pi (836s)
[R2S2RMNv7OU] I made the Petabyte Raspberry Pi even faster! (572s)
[FG--PtrDmw4] Hiding Macs in my Rack! (515s)
...
获取频道
use rustypipe::client::RustyPipe
#[tokio::main]
async fn main() {
// Create a client
let rp = RustyPipe::new();
// Get the channel
let channel = rp
.query()
.channel_videos("UCl2mFZoRqjw_ELax4Yisf6w")
.await
.unwrap();
println!("Name: {}", channel.name);
println!("Description: {}", channel.description);
println!("Subscribers: {}", channel.subscriber_count.unwrap());
channel
.content
.items
.iter()
.for_each(|v| println!("[{}] {} ({}s)", v.id, v.name, v.length.unwrap()));
}
输出
Name: Louis Rossmann
Description: I discuss random things of interest to me. (...)
Subscribers: 1780000
[qBHgJx_rb8E] Introducing Rossmann senior, a genuine fossil 😃 (122s)
[TmV8eAtXc3s] Am I wrong about CompTIA? (592s)
[CjOJJc1qzdY] How FUTO projects loosen Google's grip on your life! (588s)
[0A10JtkkL9A] a private moment between a man and his kitten (522s)
[zbHq5_1Cd5U] Is Texas mandating auto repair shops use OEM parts? SB1083 analysis & breakdown; tldr, no. (645s)
[6Fv8bd9ICb4] Who owns this? (199s)
...
开发
需求
- 稳定 Rust 的当前版本
just
任务运行器nextest
测试运行器pre-commit
- yq (YAML 处理器)
任务
测试
just test
运行单元+集成测试just unittest
运行单元测试just testyt
运行 YouTube 集成测试just testintl
运行所有受支持语言的 YouTube 集成测试(这需要很长时间,因此不在 CI 中运行)YT_LANG=de just testyt
运行特定语言的 YouTube 集成测试
工具
just testfiles
下载单元测试中缺失的测试文件just report2yaml
将 RustyPipe 报告转换为更易于阅读的 yaml 格式(需要yq
)
依赖项
~15–32MB
~595K SLoC