#youtube #downloader #download #pytube

无 std rustube

A YouTube 视频下载器,最初受 pytube 启发,用 Rust 编写

26 个不稳定版本 (5 个破坏性更新)

0.6.0 2022 年 10 月 16 日
0.4.0 2022 年 6 月 28 日
0.3.8 2022 年 1 月 2 日
0.3.7 2021 年 12 月 25 日
0.2.4 2021 年 3 月 14 日

#49 in 视频

Download history 193/week @ 2024-03-13 196/week @ 2024-03-20 267/week @ 2024-03-27 351/week @ 2024-04-03 256/week @ 2024-04-10 306/week @ 2024-04-17 269/week @ 2024-04-24 168/week @ 2024-05-01 246/week @ 2024-05-08 256/week @ 2024-05-15 151/week @ 2024-05-22 170/week @ 2024-05-29 148/week @ 2024-06-05 146/week @ 2024-06-12 187/week @ 2024-06-19 194/week @ 2024-06-26

每月 702 次下载
用于 5 crates

MIT/Apache

160KB
3K SLoC

rustube

crates.io docs.rs licence

build YT download


一个完整的(WIP)、易于使用的 YouTube 下载器。

注意:0.3.5 是一个临时修复,以适应 YouTube api 的变化 (#38)。遗憾的是,这个修复对于受年龄限制的视频不起作用。我们正在 #39 中修复这个问题。

概述

路线图

  • 下载普通视频
  • 下载受年龄限制的视频 (由于 YouTube API 的更改,0.3.5 以后不再工作)
  • 异步 API
  • 阻塞 API
  • 完整视频信息反序列化
  • 基于功能的可选视频信息反序列化
  • CLI
  • 测试套件
  • 基准测试
  • Python 绑定
  • C / C++ 绑定

用法

rustube 提供了一个极容易使用的 API。如果你只想下载视频,不关心任何中间步骤和视频信息,这就足够了

#[tokio::main]
async fn main() {
    let url = "https://www.youtube.com/watch?v=Edx9D2yaOGs&ab_channel=CollegeHumor";
    println!("downloaded video to {:?}", rustube::download_best_quality(&url).await.unwrap());
}

当然,rustube 有很多比下载视频更强大的功能。它还旨在反序列化 YouTube 提供的完整视频信息(这仍然是 WIP)。因此,查找视频观看次数就像这样

use rustube::{Id, VideoFetcher};

let id = Id::from_raw("https://www.youtube.com/watch?v=Edx9D2yaOGs&ab_channel=CollegeHumor").unwrap();
let descrambler = VideoFetcher::from_id(id.into_owned())
        .unwrap()
        .fetch()
        .await
        .unwrap();

let view_count = descrambler.video_details().view_count;
let title = descrambler.video_title();
println!("The video `{}` was viewed {} times.", title, view_count);

有关更多示例,请参阅阻塞 API 的概述 API 文档

CLI

rustube 包含一个 CLI,rustube-cli,因此你可以下载你喜欢的 YouTube 视频,而不必编写一行代码。

要安装它,只需运行

cargo install rustube-cli

成功安装 rustube-cli 后,您就可以访问 rustube 命令

A simple CLI for the rustube YouTube-downloader library.
For documentation and more information about rustube or the rustube-cli checkout
`https://github.com/DzenanJupic/rustube`.

For help with certain subcommands run `rustube <SUBCOMMAND> --help`.

USAGE:
    rustube <SUBCOMMAND>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

SUBCOMMANDS:
    check       Checks if a video can be downloaded and fetches information about it
                This command is similar to fetch, in the way that it also fetches information
                about a video, but, other then fetch, will also decrypt all stream URLs.
                Therefore you can use the returned URLs for downloading the video. This of
                course means that the video has to be downloadable.
                By default this command will check for any streams that contain a video and an
                audio track. To specify other behavior, like checking for a stream with a
                particular quality, have a look at the subcommand help.
    download    Downloads a YouTube video
                By default, the Stream with the best quality and both a video, and an audio
                track will be downloaded. To specify other download behavior, have a look the
                the subcommand help.
    fetch       Fetches information about a YouTube video
                Fetching information does not require the video to actually be downloadable. So
                this also works when a video is, i.e., an offline stream. The downside is that
                you often don't have access to the stream URLs. Some videos come with pre-
                decrypted urls, in which case you can also use these to download the video, but
                if the video url is encrypted there's no way for you to download the video using
                only the returned information. To get decrypted URLs, have a look at `check`.
                For most use cases it's recommended to use `check` instead, since it gives you
                both more control and more information.
    help        Prints this message or the help of the given subcommand(s)

贡献

rustube 仍然处于非常早期阶段,欢迎您为其做出贡献!目标是利用 Rust 的速度、类型系统和安全性,制作最快的、最可靠的、最完整的 YouTube 下载器。

本项目是完全开源的。您提交给 rustube 的任何贡献,都必须同时拥有 MIT 许可证和 Apache-2.0 许可证,并以 MIT 或 Apache-2.0 许可证授权,不得附加任何额外条款或条件。

许可证

本项目根据 MIT 许可证或 Apache-2.0 许可证的条款进行许可,由您自行选择。

依赖项

~2–16MB
~238K SLoC