feat(06-01): add --cookies and --cookies-from-browser CLI args
- Add --cookies <FILE> for Netscape-format cookie files - Add --cookies-from-browser <BROWSER> for browser cookie extraction - Add CLI tests for both arguments - 140 tests pass
This commit is contained in:
50
src/cli.rs
50
src/cli.rs
@@ -122,6 +122,17 @@ pub struct Args {
|
||||
/// Shorthand for --download-archive with default path
|
||||
#[arg(long = "download-archive-skip-duplicates")]
|
||||
pub download_archive_skip_duplicates: bool,
|
||||
|
||||
// ===== Authentication Options =====
|
||||
/// Path to Netscape-format cookies file
|
||||
/// Use browser extensions like "Get cookies.txt LOCALLY" to export cookies
|
||||
#[arg(long = "cookies", value_name = "FILE")]
|
||||
pub cookies: Option<PathBuf>,
|
||||
|
||||
/// Extract cookies from browser (firefox, chrome, edge, etc.)
|
||||
/// Requires browser-cookie3 library or similar to be installed
|
||||
#[arg(long = "cookies-from-browser", value_name = "BROWSER")]
|
||||
pub cookies_from_browser: Option<String>,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
@@ -340,4 +351,43 @@ mod tests {
|
||||
assert_eq!(config.command, "scan");
|
||||
assert_eq!(config.args, vec!["{}", "--verbose"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cookies_arg() {
|
||||
let args = Args::parse_from([
|
||||
"gallery-dl",
|
||||
"--cookies",
|
||||
"cookies.txt",
|
||||
"https://example.com",
|
||||
]);
|
||||
assert_eq!(args.cookies, Some(PathBuf::from("cookies.txt")));
|
||||
assert_eq!(args.urls.len(), 1);
|
||||
assert_eq!(args.urls[0], "https://example.com");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cookies_from_browser_arg() {
|
||||
let args = Args::parse_from([
|
||||
"gallery-dl",
|
||||
"--cookies-from-browser",
|
||||
"firefox",
|
||||
"https://twitter.com/user",
|
||||
]);
|
||||
assert_eq!(args.cookies_from_browser, Some("firefox".to_string()));
|
||||
assert_eq!(args.urls.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cookies_args_combined() {
|
||||
let args = Args::parse_from([
|
||||
"gallery-dl",
|
||||
"--cookies",
|
||||
"cookies.txt",
|
||||
"--cookies-from-browser",
|
||||
"chrome",
|
||||
"https://example.com",
|
||||
]);
|
||||
assert_eq!(args.cookies, Some(PathBuf::from("cookies.txt")));
|
||||
assert_eq!(args.cookies_from_browser, Some("chrome".to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user