Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added additional flags (cookies from browser, max downloads) #60

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ pub struct YoutubeDl {
all_formats: bool,
auth: Option<(String, String)>,
cookies: Option<String>,
cookies_from_browser: Option<String>,
user_agent: Option<String>,
referer: Option<String>,
url: String,
Expand All @@ -261,6 +262,7 @@ pub struct YoutubeDl {
date: Option<String>,
extract_audio: bool,
playlist_items: Option<String>,
max_downloads: Option<String>,
extra_args: Vec<String>,
output_template: Option<String>,
output_directory: Option<String>,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -383,6 +387,36 @@ impl YoutubeDl {
self
}

/// Set the `--cookies-from-browser` command line flag.
pub fn cookies_from_browser<S: Into<String>>(
&mut self,
browser_name: S,
browser_keyring: Option<S>,
browser_profile: Option<S>,
browser_container: Option<S>,
) -> &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 {
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Loading