-
-
Save nick42d/f1ff0d1c29dc85256b0a50900c7f39e7 to your computer and use it in GitHub Desktop.
Test rusty_ytdl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "tests" | |
version = "0.1.0" | |
edition = "2021" | |
[dependencies] | |
rusty_ytdl = {path = "../rusty_ytdl"} | |
futures = "0.3.30" | |
tokio = "1.39.2" | |
ytmapi-rs = "0.0.9" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use futures::future::join; | |
use tokio::task::JoinSet; | |
use ytmapi_rs::common::YoutubeID; | |
#[tokio::main] | |
async fn main() { | |
let yt = ytmapi_rs::YtMusic::from_cookie_file("/home/nickd/.config/youtui/cookie.txt") | |
.await | |
.unwrap(); | |
let mut join_set = yt.search_songs("Beatles") | |
.await | |
.unwrap() | |
.into_iter() | |
.take(20) | |
.enumerate() | |
.map(|(idx, s)| download(idx, s.video_id)) | |
.collect::<JoinSet<_>>(); | |
while join_set.join_next().await.is_some() { | |
println!("Task finished") | |
} | |
} | |
async fn download( idx: usize, id: ytmapi_rs::VideoID<'_>) { | |
let opts = rusty_ytdl::VideoOptions { | |
quality: rusty_ytdl::VideoQuality::LowestVideo, | |
filter: rusty_ytdl::VideoSearchOptions::Video, | |
..Default::default() | |
}; | |
let video = rusty_ytdl::Video::new_with_options(id.get_raw(), opts).unwrap(); | |
let path1 = format!("test{idx}.mp3"); | |
let (res, info) = join(video.download(&path1), video.get_basic_info()).await; | |
let mut res = res.is_ok(); | |
let mut idx = 0; | |
while idx < 5 && !res { | |
res = video.download(&path1).await.is_ok(); | |
idx+=1; | |
}; | |
let info = info.unwrap(); | |
println!( | |
"video: {:?} retries: {:?}\n download succeeded: {:?}", | |
info.video_details.title, | |
idx, | |
res | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment