Crates.io | ytb-downloader |
lib.rs | ytb-downloader |
version | 0.1.0 |
source | src |
created_at | 2023-04-20 15:48:59.202764 |
updated_at | 2023-04-20 15:48:59.202764 |
description | A library for downloading Youtube videos. |
homepage | |
repository | |
max_upload_size | |
id | 844572 |
size | 10,512,195 |
A Rust library for downloading videos from Youtube, choosing between all the available formats.
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.
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(())
}
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".
git checkout -b feature/AmazingFeature
)git commit -m 'Add some AmazingFeature'
)git push origin feature/AmazingFeature
)Distributed under the MIT License. See LICENSE.txt
for more information.
Pavlos Smith - paulsmith4561+at+gmail.com