From 964845f084b3a4e4ebc2735ac63d334602d43e89 Mon Sep 17 00:00:00 2001 From: Nils Pukropp Date: Thu, 13 May 2021 00:17:16 +0200 Subject: [PATCH] added option for multiple link --- Cargo.toml | 2 +- src/lib.rs | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f303af1..eaa0858 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ytd-rs" -version = "0.1.1" +version = "0.1.2" authors = ["Nils Pukropp "] edition = "2018" license-file ="LICENSE" diff --git a/src/lib.rs b/src/lib.rs index 3911867..44e112c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -89,7 +89,7 @@ impl Display for Arg { #[derive(Clone, Debug)] pub struct YoutubeDL { path: PathBuf, - link: String, + links: Vec, args: Vec, } @@ -146,7 +146,11 @@ impl YoutubeDL { /// and finally a link that can be `""` if no video should be downloaded /// /// The path gets canonicalized and the directory gets created by the constructor - pub fn new(dl_path: &str, args: Vec, link: &str) -> Result { + pub fn new_multiple_links( + dl_path: &str, + args: Vec, + links: Vec, + ) -> Result { // create path let path = Path::new(dl_path); @@ -169,15 +173,15 @@ impl YoutubeDL { // absolute path match canonicalize(dl_path) { // return new youtube-dl job - Ok(path) => Ok(YoutubeDL { - path, - link: link.to_string(), - args, - }), + Ok(path) => Ok(YoutubeDL { path, links, args }), Err(why) => Err(format!("Error creating YouTubeDL: {:?}", why)), } } + pub fn new(dl_path: &str, args: Vec, link: &str) -> Result { + YoutubeDL::new_multiple_links(dl_path, args, vec![link.to_string()]) + } + /// Starts the download and returns when finished the result as [`YoutubeDLResult`]. pub fn download(&self) -> YoutubeDLResult { let pr_result = self.spawn_youtube_dl(); @@ -215,7 +219,9 @@ impl YoutubeDL { }; } - cmd.arg(&self.link); + for link in self.links.iter() { + cmd.arg(&link); + } let pr = match cmd.spawn() { Err(why) => {