1 unstable release
0.1.0 | Apr 20, 2023 |
---|
#449 in Video
11MB
307 lines
ytb-downloader
Table of Contents
About The Project
A Rust library for downloading videos from Youtube, choosing between all the available formats.
Getting Started
Add ytb-downloader
to Cargo.toml and import it:
use ytb-downloader::*;
Note that the library is uses async/await so
tokio = { version = "1.27.0", features = ["macros", "rt-multi-thread", "fs"] }
is needed as well. These are the necessary features of Tokio for ytb-downloader
but you can add more if you need to.
Usage
The examples below use error_chain for error handling, that's why the Result doesn't also have an error type parameter.
Downloading a video using the download_video!
macro:
#[macro_use] extern crate ytb_downloader;
use ytb_downloader::*;
use errors::*;
[tokio::main]
async fn main() -> Result<()> {
let source = get_available_sources("https://www.youtube.com/watch?v=pqhfyrW_BEA").await?
.into_iter().next().unwrap();
const OUTPUT_FILE: &str = "download.m4a";
download_video!(&source, OUTPUT_FILE).await;
Ok(())
}
Downloading a video using the actual function call:
use ytb_downloader::*;
use errors::*;
[tokio::main]
async fn main() -> Result<()> {
let source = get_available_sources("https://www.youtube.com/watch?v=pqhfyrW_BEA").await?
.into_iter().next().unwrap();
const OUTPUT_FILE: &str = "download.m4a";
download_video(&source, OUTPUT_FILE, None).await;
Ok(())
}
Downloading a video with a chunk size of 10240 bytes:
use ytb_downloader::*;
use errors::*;
[tokio::main]
async fn main() -> Result<()> {
let source = get_available_sources("https://www.youtube.com/watch?v=pqhfyrW_BEA").await?
.into_iter().next().unwrap();
const OUTPUT_FILE: &str = "download.m4a";
download_video(&source, OUTPUT_FILE, Some(10240)).await;
Ok(())
}
Contributing
Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
License
Distributed under the MIT License. See LICENSE.txt
for more information.
Contact
Pavlos Smith - paulsmith4561+at+gmail.com
Dependencies
~11–25MB
~370K SLoC