diff --git a/src/lib.rs b/src/lib.rs index 84e4e59..f5fe5e6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -251,6 +251,7 @@ pub struct YoutubeDl { all_formats: bool, auth: Option<(String, String)>, cookies: Option, + cookies_from_browser: Option, user_agent: Option, referer: Option, url: String, @@ -261,6 +262,7 @@ pub struct YoutubeDl { date: Option, extract_audio: bool, playlist_items: Option, + max_downloads: Option, extra_args: Vec, output_template: Option, output_directory: Option, @@ -281,6 +283,7 @@ impl YoutubeDl { all_formats: false, auth: None, cookies: None, + cookies_from_browser: None, user_agent: None, referer: None, process_timeout: None, @@ -290,6 +293,7 @@ impl YoutubeDl { playlist_reverse: false, extract_audio: false, playlist_items: None, + max_downloads: None, extra_args: Vec::new(), output_template: None, output_directory: None, @@ -383,6 +387,36 @@ impl YoutubeDl { self } + /// Set the `--cookies-from-browser` command line flag. + pub fn cookies_from_browser>( + &mut self, + browser_name: S, + browser_keyring: Option, + browser_profile: Option, + browser_container: Option, + ) -> &mut Self { + self.cookies_from_browser = Some(format!( + "{}{}{}{}", + browser_name.into(), + if let Some(keyring) = browser_keyring { + format!("+{}", keyring.into()) + } else { + String::from("") + }, + if let Some(profile) = browser_profile { + format!(":{}", profile.into()) + } else { + String::from("") + }, + if let Some(container) = browser_container { + format!("::{}", container.into()) + } else { + String::from("") + } + )); + self + } + /// Set a process-level timeout for youtube-dl. (this controls the maximum overall duration /// the process may take, when it times out, `Error::ProcessTimeout` is returned) pub fn process_timeout(&mut self, timeout: Duration) -> &mut Self { @@ -402,6 +436,12 @@ impl YoutubeDl { self } + /// Set the `--max-downloads` command line flag. + pub fn max_downloads(&mut self, max_downloads: u32) -> &mut Self { + self.max_downloads = Some(max_downloads.to_string()); + self + } + /// Add an additional custom CLI argument. /// /// This allows specifying arguments that are not covered by other @@ -476,6 +516,11 @@ impl YoutubeDl { args.push(cookie_path); } + if let Some(cookies_from_browser) = &self.cookies_from_browser { + args.push("--cookies-from-browser"); + args.push(cookies_from_browser); + } + if let Some(user_agent) = &self.user_agent { args.push("--user-agent"); args.push(user_agent); @@ -495,6 +540,11 @@ impl YoutubeDl { args.push(playlist_items); } + if let Some(max_downloads) = &self.max_downloads { + args.push("--max-downloads"); + args.push(max_downloads); + } + if let Some(output_template) = &self.output_template { args.push("-o"); args.push(output_template);