added option for multiple link

This commit is contained in:
Nils Pukropp committed 2021-05-13 00:17:16 +02:00
1 parent c0b1347351
commit 964845f084
2 files changed
+15 -9

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "ytd-rs" name = "ytd-rs"
version = "0.1.1" version = "0.1.2"
authors = ["Nils Pukropp <nils.pukropp@outlook.de>"] authors = ["Nils Pukropp <nils.pukropp@outlook.de>"]
edition = "2018" edition = "2018"
license-file ="LICENSE" license-file ="LICENSE"
+14 -8
View File
@@ -89,7 +89,7 @@ impl Display for Arg {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct YoutubeDL { pub struct YoutubeDL {
path: PathBuf, path: PathBuf,
link: String, links: Vec<String>,
args: Vec<Arg>, args: Vec<Arg>,
} }
@@ -146,7 +146,11 @@ impl YoutubeDL {
/// and finally a link that can be `""` if no video should be downloaded /// 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 /// The path gets canonicalized and the directory gets created by the constructor
pub fn new(dl_path: &str, args: Vec<Arg>, link: &str) -> Result<YoutubeDL, String> { pub fn new_multiple_links(
dl_path: &str,
args: Vec<Arg>,
links: Vec<String>,
) -> Result<YoutubeDL, String> {
// create path // create path
let path = Path::new(dl_path); let path = Path::new(dl_path);
@@ -169,15 +173,15 @@ impl YoutubeDL {
// absolute path // absolute path
match canonicalize(dl_path) { match canonicalize(dl_path) {
// return new youtube-dl job // return new youtube-dl job
Ok(path) => Ok(YoutubeDL { Ok(path) => Ok(YoutubeDL { path, links, args }),
path,
link: link.to_string(),
args,
}),
Err(why) => Err(format!("Error creating YouTubeDL: {:?}", why)), Err(why) => Err(format!("Error creating YouTubeDL: {:?}", why)),
} }
} }
pub fn new(dl_path: &str, args: Vec<Arg>, link: &str) -> Result<YoutubeDL, String> {
YoutubeDL::new_multiple_links(dl_path, args, vec![link.to_string()])
}
/// Starts the download and returns when finished the result as [`YoutubeDLResult`]. /// Starts the download and returns when finished the result as [`YoutubeDLResult`].
pub fn download(&self) -> YoutubeDLResult { pub fn download(&self) -> YoutubeDLResult {
let pr_result = self.spawn_youtube_dl(); 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() { let pr = match cmd.spawn() {
Err(why) => { Err(why) => {