odl 2.0.3

flexible download library and CLI intended to be fast, reliable, and easy to use.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
use std::path::PathBuf;
use std::str::FromStr;
use std::time::Duration;

use clap::{Parser, Subcommand};

#[derive(clap::ValueEnum, Clone, Copy, Debug, PartialEq, Eq)]
pub enum OutputFormat {
    /// Human-readable output: progress bars, plain text.
    Text,
    /// Machine-readable output: NDJSON progress events (download) or a
    /// single JSON document (config/probe/status). Intended for agents
    /// and scripts. Progress bars are suppressed.
    Json,
}

#[derive(clap::ValueEnum, Clone, Copy, Debug)]
pub enum LogLevel {
    Off,
    Error,
    Warn,
    Info,
    Debug,
    Trace,
}

#[derive(clap::ValueEnum, Clone, Debug)]
pub enum FileChangedAction {
    Abort,
    Restart,
}

#[derive(clap::ValueEnum, Clone, Debug)]
pub enum NotResumableAction {
    Abort,
    Restart,
}

#[derive(clap::ValueEnum, Clone, Debug)]
pub enum SameDownloadAction {
    Abort,
    Resume,
    AddNumberToNameAndContinue,
}

#[derive(clap::ValueEnum, Clone, Debug)]
pub enum FinalFileAction {
    Abort,
    ReplaceAndContinue,
    AddNumberToNameAndContinue,
}

/// Which download engine to use.
/// What `odl tools` should do.
#[derive(clap::Subcommand, Debug)]
pub enum ToolsAction {
    /// Report which helpers are installed, where, and which version.
    Status,
    /// Download helpers into odl's data directory and record their paths in
    /// the config file. Downloads are verified against checksums published
    /// with them, and the latest release is always used — extractors break as
    /// sites change, so a pinned version would rot.
    Install {
        /// Which helper to install. Both, when omitted.
        #[arg(value_enum)]
        tool: Option<ToolChoice>,
        /// Install without asking for confirmation.
        #[arg(long, short = 'y')]
        yes: bool,
    },
}

#[derive(clap::ValueEnum, Clone, Copy, Debug, PartialEq, Eq)]
pub enum ToolChoice {
    #[value(name = "yt-dlp")]
    Ytdlp,
    Ffmpeg,
}

#[derive(clap::ValueEnum, Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum EngineChoice {
    /// Delegate configured media hosts to yt-dlp when it is installed, and
    /// download everything else over HTTP.
    #[default]
    Auto,
    /// Always use odl's own multipart HTTP downloader.
    Http,
    /// Always delegate to yt-dlp, failing if it is unavailable.
    Ytdlp,
}

/// When to ask which quality to download.
#[derive(clap::ValueEnum, Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum ChooseFormat {
    /// Ask when the terminal is interactive and there is a single download to
    /// decide about; take the best available otherwise.
    #[default]
    Auto,
    /// Always ask, even for a download that already picked a format. Choosing
    /// a different quality discards what was downloaded and starts over,
    /// since two encodings cannot be joined; pair it with
    /// `--on-file-changed restart` to accept that without a prompt.
    ///
    /// Still silent without a terminal or with `--format json`: a question
    /// nobody can answer is a hang, not a prompt.
    Always,
    /// Never ask; take the best available.
    Never,
}

fn parse_speed(s: &str) -> Result<u64, String> {
    let s = s.trim();
    if s.is_empty() {
        return Err("empty speed string".to_string());
    }

    // Remove common trailing rate markers like `/s` or `bps` (case-insensitive)
    let mut working = s.to_string();
    let lower = working.to_lowercase();
    if lower.ends_with("/s") {
        working.truncate(working.len() - 2);
    } else if lower.ends_with("bps") {
        working.truncate(working.len() - 3);
    }
    let working = working.trim();

    // split into numeric prefix and suffix
    let mut idx = 0usize;
    for (i, ch) in working.char_indices() {
        if !(ch.is_ascii_digit() || ch == '.') {
            idx = i;
            break;
        }
        idx = i + ch.len_utf8();
    }

    let (num_part, suf_part) = if idx == 0 {
        // no numeric prefix
        return Err(format!("invalid speed '{}': missing numeric value", s));
    } else if idx >= working.len() {
        (working, "")
    } else {
        (working[..idx].trim(), working[idx..].trim())
    };

    let value =
        f64::from_str(num_part).map_err(|e| format!("invalid number '{}': {}", num_part, e))?;
    if value < 0.0 {
        return Err("speed must be non-negative".to_string());
    }

    let suffix_owned = suf_part
        .trim()
        .trim_start_matches([' ', '\t', '\''])
        .to_lowercase();

    // Determine multiplier (all based on 1024)
    let multiplier: f64 = match suffix_owned.as_str() {
        "" | "b" | "byte" | "bytes" => 1.0,
        "k" | "kb" | "kib" | "kibibyte" | "kb/s" => 1024f64,
        "m" | "mb" | "mib" | "mibibyte" => 1024f64.powi(2),
        "g" | "gb" | "gib" | "gibibyte" => 1024f64.powi(3),
        // Allow common variants like "kib/s" trimmed earlier, also accept single-letter with optional trailing 'b'
        other => {
            // try to match prefixes (e.g., "kib", "kb", "k")
            let o = other.trim();
            if o.starts_with('k') {
                1024f64
            } else if o.starts_with('m') {
                1024f64.powi(2)
            } else if o.starts_with('g') {
                1024f64.powi(3)
            } else {
                return Err(format!("unknown size suffix '{}'", other));
            }
        }
    };

    let bytes_f = value * multiplier;
    if !bytes_f.is_finite() || bytes_f < 0.0 {
        return Err("resulting speed is out of range".to_string());
    }
    let bytes = bytes_f as u128; // use wider intermediate to reduce overflow risk
    if bytes > (u64::MAX as u128) {
        return Err("speed too large".to_string());
    }
    Ok(bytes as u64)
}

/// Stable description of the machine-readable interface, shown under
/// `odl --help`. This is a documented contract: agents and scripts may
/// rely on these exit codes and JSON shapes across patch/minor releases.
/// Keep in sync with `exit_code`/`error_kind` in `main.rs` and the
/// `JsonReporter` in `json.rs`.
const MACHINE_INTERFACE_HELP: &str = "\
EXIT CODES:
  0    success
  1    other / internal error
  2    usage or invalid input (bad URL, missing input, invalid config/flags)
  3    network error (DNS, timeout, HTTP status, connection)
  4    conflict (save/server conflict, checksum mismatch)
  5    I/O error
  6    metadata error (lockfile in use, decode failure)
  7    yt-dlp error (missing, too old, failed, or unsupported URL)
  130  cancelled

JSON OUTPUT (--format json):
  Downloads stream newline-delimited JSON (NDJSON) to stdout, one object
  per line, each tagged with \"type\" and \"url\":
    phase      {\"phase\": evaluating|resolving_conflicts|downloading|post_processing|assembling|flushing|verifying}
    filename   {\"filename\"}
    progress   {\"downloaded\", \"total\": <int|null>}
    message    {\"message\"}
    completed  {\"path\", \"already_complete\"}
    failed     {\"message\"}
    cancelled  {}
  One-shot commands emit a single JSON document on stdout:
    probe        {\"type\":\"probe\", filename, size, size_is_approx, engine, quality, resumable, etag, last_modified, checksums, ...}
    status/list  {\"type\":\"status\", count, downloads:[...]}
    config       {\"type\":\"config\", path, config}  (config_saved on write)
  Errors print one JSON object to stderr:
    {\"type\":\"error\", \"kind\", \"message\", \"exit_code\"}

ENGINES:
  Links on known media hosts are handed to an installed `yt-dlp`; everything
  else uses odl's own multipart HTTP downloader. `--engine` forces the choice.
  A delegated download reports \"engine\":\"ytdlp\" and cannot observe the
  underlying HTTP exchange, so etag/last_modified are null and checksums is
  empty; sizes may be estimates (\"size_is_approx\": true). Configure it under
  [ytdlp] in config.toml.

  Quality is chosen once and pinned: a resume never mixes encodings. To change
  it, name another format (--format-id) or ask again (--choose-format always);
  either discards what was downloaded and starts over.";

#[derive(Parser, Debug)]
#[command(version, about, long_about = None, after_long_help = MACHINE_INTERFACE_HELP)]
pub struct Args {
    /// The URL of the file to download, or a path to a file containing one URL per line.
    /// Blank lines and lines starting with `#` or `//` are ignored.
    /// Optional so subcommands (like `config`) can be used without providing an input.
    pub input: Option<String>,

    /// If true, tries to download the file at url and read it as a text file and then use it as input
    #[arg(long, default_value_t = false)]
    pub remote_list: bool,

    /// Which download engine to use.
    #[arg(long, value_enum, default_value_t = EngineChoice::Auto)]
    pub engine: EngineChoice,

    /// Whether to ask which quality to download when a media host is delegated to yt-dlp.
    #[arg(long, value_enum, default_value_t = ChooseFormat::Auto)]
    pub choose_format: ChooseFormat,

    /// Skip verifying the finished file against known checksums.
    ///
    /// The checksums are still recorded and reported; odl just stops hashing
    /// the file to act on them, which a caller may prefer to do itself. The
    /// file's size is still checked.
    #[arg(long)]
    pub no_verify_checksums: bool,

    /// Transliterate filenames to ASCII: `Café` is saved as `Cafe`, and a
    /// title in any script becomes something every terminal and filesystem
    /// renders the same way.
    ///
    /// Lossy, and it renames the per-download directory — a download already
    /// in progress under the other setting starts over.
    #[arg(long)]
    pub ascii_filenames: bool,

    /// Download this exact media format instead of asking or picking the best.
    /// Naming a different format than a download already started discards what
    /// was downloaded and starts over, since encodings cannot be joined.
    #[arg(long, value_name = "ID")]
    pub format_id: Option<String>,

    /// Max connections that download manager can make in parallel for a single file
    #[arg(long, value_name = "COUNT")]
    pub max_connections: Option<u64>,

    /// The maximum number of files that the download manager can download in parallel.
    ///
    /// This controls the overall concurrency of downloads. For example, if set to 4, up to 4 files
    /// will be downloaded at the same time, regardless of how many connections are used for each file.
    ///
    /// Note: For controlling how many parts of a single file can be downloaded concurrently,
    /// see the `max_connections` option.
    #[arg(long, value_name = "COUNT")]
    pub max_concurrent_downloads: Option<usize>,

    /// When `input` is a URL, this specifies the output file path.
    /// When `input` is a file containing URLs, this specifies the output directory for downloaded files.
    /// Will use server provided name if not specified or if `input` is a file.
    #[arg(short, long, value_name = "FILE|DIR")]
    pub output: Option<PathBuf>,

    /// This is the path where odl tracks download progress.
    /// All data will be downloaded here first before being appended at the output location.
    #[arg(short, long, value_name = "DIR")]
    pub download_dir: Option<PathBuf>,

    /// The config file to use. defaults to `odl/config.toml` inside user's appdata directory (varies based on OS)
    #[arg(short, long, value_name = "FILE")]
    pub config_file: Option<PathBuf>,

    /// User agent to use for making requests. This option overrides random-user-agent.
    #[arg(short = 'U', long)]
    pub user_agent: Option<String>,

    /// Should the user_agent be randomized for each request?
    #[arg(long)]
    pub randomize_user_agent: Option<bool>,

    #[arg(long, value_name = "(http(s)|socks)://")]
    pub proxy: Option<String>,

    /// Connect timeout for requests. Accepts suffixes like `30s`, `5m`, `2h`, `1d` or long forms (`seconds`, `minutes`, `hours`, `days`). Default `5s`.
    #[arg(short, long = "timeout", value_name = "DURATION", value_parser = humantime::parse_duration)]
    pub timeout: Option<Duration>,

    /// Max number of retries in case of a network error
    #[arg(long, value_name = "COUNT")]
    pub max_retries: Option<u32>,

    /// Number of fixed (non-exponential) retries before exponential backoff starts
    #[arg(long, value_name = "COUNT")]
    pub n_fixed_retries: Option<u32>,

    /// Wait number of seconds after a network error before retry. Fractions are supported.
    #[arg(long, value_name = "DURATION", value_parser = humantime::parse_duration)]
    pub wait_between_retries: Option<Duration>,

    /// If true, sets the downloaded file's last-modified timestamp to match the server's value (if available).
    #[arg(short, long)]
    pub use_server_time: Option<bool>,

    /// How to handle a server file-changed conflict. Possible values: `abort`, `restart`.
    /// Default: `restart` (restart the download and warn).
    #[arg(long, value_enum, default_value_t = FileChangedAction::Restart)]
    pub on_file_changed: FileChangedAction,

    /// How to handle a server not-resumable conflict. Possible values: `abort`, `restart`.
    /// Default: `restart` (restart the download and warn).
    #[arg(long, value_enum, default_value_t = NotResumableAction::Restart)]
    pub on_not_resumable: NotResumableAction,

    /// Should we accept invalid SSL certificates? Do not use unless you are absolutely sure of what you are doing.
    #[arg(long)]
    pub accept_invalid_certs: Option<bool>,

    /// Enable HTTP/2 (default: HTTP/1.1 only). HTTP/1.1 opens a separate
    /// TCP connection per part, which usually yields higher throughput
    /// on high-bandwidth links — especially on Windows where h2's
    /// flow-control windows on a single TCP can throttle downloads.
    #[arg(long)]
    pub http2: Option<bool>,

    /// Allow mid-flight subdivision of long-running parts to keep idle
    /// connections busy. Default: enabled. Pass `--dynamic-split false`
    /// to lock the part layout chosen at evaluate / resume time.
    #[arg(long)]
    pub dynamic_split: Option<bool>,

    /// Custom HTTP headers to include in each request. Specify as `KEY:VALUE`.
    #[arg(long = "header", value_name = "KEY:VALUE", num_args = 0.., action = clap::ArgAction::Append)]
    pub headers: Vec<String>,

    /// How to handle a save conflict when the same download structure exists. Possible values: `abort`, `resume`, `add-number-to-name-and-continue`.
    /// Default: `resume`.
    #[arg(long, value_enum, default_value_t = SameDownloadAction::Resume)]
    pub on_same_download_exists: SameDownloadAction,

    /// How to handle a save conflict when a final file already exists. Possible values: `abort`, `replace-and-continue`, `add-number-to-name-and-continue`.
    /// Default: `replace-and-continue`.
    #[arg(long, value_enum, default_value_t = FinalFileAction::ReplaceAndContinue)]
    pub on_final_file_exists: FinalFileAction,

    /// Expected checksum(s) to verify the assembled file against. Format
    /// `ALGO:DIGEST` (digest hex-encoded) or `ALGO:ENCODING:DIGEST`.
    /// ALGO: `md5`, `sha1`, `sha256`, `sha384`, `sha512`.
    /// ENCODING: `hex` (default) or `base64`.
    /// Repeatable; checked in addition to any server-advertised checksums.
    /// A mismatch fails the download with a conflict error (exit code 4).
    #[arg(long = "checksum", value_name = "ALGO:DIGEST", action = clap::ArgAction::Append)]
    pub checksums: Vec<String>,

    /// HTTP basic authentication username.
    #[arg(long, value_name = "USER")]
    pub http_user: Option<String>,

    /// HTTP basic authentication password.
    #[arg(long, value_name = "PASSWORD")]
    pub http_password: Option<String>,

    /// Maximum aggregate download speed per file in bytes per second.
    /// Accepts human-readable values like `100KB`, `1.5MiB`, `2G` (all units parsed as base 1024).
    /// When unset, downloads run at full speed.
    #[arg(short, long, value_name = "BYTES_PER_SEC", value_parser = parse_speed)]
    pub speed_limit: Option<u64>,

    /// Diagnostic log severity. Overridden by `RUST_LOG` env var when set.
    /// Possible values: `off`, `error`, `warn`, `info`, `debug`, `trace`. Default: `warn`.
    #[arg(long, value_enum, default_value_t = LogLevel::Warn)]
    pub log_level: LogLevel,

    /// Output format. `text` (default) is human-readable; `json` emits
    /// machine-readable output for scripts and agents (NDJSON progress
    /// events while downloading; a single JSON document for
    /// `config --show`, `probe`, and `status`/`list`). Errors are emitted
    /// as a JSON object on stderr. See also the per-variant exit codes.
    #[arg(long, value_enum, default_value_t = OutputFormat::Text, global = true)]
    pub format: OutputFormat,

    #[command(subcommand)]
    pub command: Option<Commands>,
}

#[derive(Subcommand, Debug)]
pub enum Commands {
    /// Configure persistent download-manager settings saved in odl/config.toml
    Config {
        /// Print current configuration path and content
        #[arg(long)]
        show: bool,

        /// Config file to change (defaults to standard odl config path).
        /// You can use this to configure different download managers.
        #[arg(long, value_name = "FILE")]
        config_file: Option<PathBuf>,

        /// Where download manager keeps each download's parts and progress metadata
        #[arg(long, value_name = "DIR")]
        download_dir: Option<PathBuf>,

        /// Set max connections per-file
        #[arg(long, value_name = "COUNT")]
        max_connections: Option<u64>,

        /// Set maximum concurrent downloads
        #[arg(long, value_name = "COUNT")]
        max_concurrent_downloads: Option<usize>,

        /// Set max retries
        #[arg(long, value_name = "COUNT")]
        max_retries: Option<u32>,

        /// Number of fixed (non-exponential) retries before exponential backoff starts
        #[arg(long, value_name = "COUNT")]
        n_fixed_retries: Option<u32>,

        /// Wait between retries. Accepts suffixes like `30s`, `5m`, `2h`, `1d` or long forms (`seconds`, `minutes`, `hours`, `days`). Default `5s`.
        #[arg(long, value_name = "DURATION", value_parser = humantime::parse_duration)]
        wait_between_retries: Option<Duration>,

        /// Download speed limit (bytes/sec) e.g. 1MiB
        #[arg(short, long, value_name = "BYTES_PER_SEC", value_parser = parse_speed)]
        speed_limit: Option<u64>,

        /// Custom user agent
        #[arg(long)]
        user_agent: Option<String>,

        /// Randomize user agent
        #[arg(long)]
        randomize_user_agent: Option<bool>,

        /// Proxy as string
        #[arg(long)]
        proxy: Option<String>,

        /// Connect timeout for requests. Accepts suffixes like `30s`, `5m`, `2h`, `1d` or long forms (`seconds`, `minutes`, `hours`, `days`). Default `5s`.
        #[arg(short, long = "timeout", value_name = "DURATION", value_parser = humantime::parse_duration)]
        timeout: Option<Duration>,

        /// Use server time when saving
        #[arg(long)]
        use_server_time: Option<bool>,

        /// Accept invalid certs
        #[arg(long)]
        accept_invalid_certs: Option<bool>,

        /// Enable HTTP/2 (default: HTTP/1.1 only).
        #[arg(long)]
        http2: Option<bool>,

        /// Allow mid-flight subdivision of long-running parts.
        #[arg(long)]
        dynamic_split: Option<bool>,
    },

    /// Install or inspect the helper programs odl uses for media sites.
    ///
    /// `yt-dlp` turns a media page link into a downloadable video; `ffmpeg`
    /// joins the separate video and audio streams that sites serve for higher
    /// qualities. Both are optional, and installing them yourself and setting
    /// `ytdlp.binary_path` / `ytdlp.ffmpeg_path` in config.toml works equally
    /// well.
    Tools {
        #[command(subcommand)]
        action: ToolsAction,
    },

    /// Probe a URL without downloading: report the resolved filename,
    /// size, resumability, etag, last-modified, and any server-advertised
    /// checksums. Pair with `--format json` for machine-readable output.
    Probe {
        /// The URL to probe.
        #[arg(value_name = "URL")]
        url: String,
    },

    /// Show tracked downloads in the configured download directory:
    /// per-download progress (bytes on disk vs. total), part counts, and
    /// whether the final file has been assembled. Optional FILTER matches
    /// a substring of the URL or filename.
    Status {
        /// Only show downloads whose URL or filename contains this string.
        #[arg(value_name = "FILTER")]
        filter: Option<String>,
    },

    /// List tracked downloads (brief). Alias of `status` with terse
    /// output; honors `--format json`.
    List {
        /// Only show downloads whose URL or filename contains this string.
        #[arg(value_name = "FILTER")]
        filter: Option<String>,
    },
}

#[cfg(test)]
mod tests {
    use super::parse_speed;
    use std::time::Duration;

    #[test]
    fn test_simple_bytes() {
        assert_eq!(parse_speed("100").unwrap(), 100);
        assert_eq!(parse_speed("100B").unwrap(), 100);
    }

    #[test]
    fn test_kilobytes() {
        assert_eq!(parse_speed("1K").unwrap(), 1024);
        assert_eq!(parse_speed("1KB").unwrap(), 1024);
        assert_eq!(parse_speed("100kib").unwrap(), 100 * 1024);
    }

    #[test]
    fn test_megabytes() {
        assert_eq!(parse_speed("1M").unwrap(), 1024u64.pow(2));
        assert_eq!(
            parse_speed("1.5MB").unwrap(),
            ((1.5f64 * (1024f64.powi(2))) as u64)
        );
    }

    #[test]
    fn test_gigabytes() {
        assert_eq!(parse_speed("2G").unwrap(), 2 * 1024u64.pow(3));
        assert_eq!(parse_speed("2GiB").unwrap(), 2 * 1024u64.pow(3));
    }

    #[test]
    fn test_suffix_with_per_second() {
        assert_eq!(parse_speed("100KB/s").unwrap(), 100 * 1024);
        assert_eq!(
            parse_speed("1.5MiB/s").unwrap(),
            ((1.5f64 * (1024f64.powi(2))) as u64)
        );
    }

    #[test]
    fn test_parse_duration_seconds_and_variants() {
        assert_eq!(
            humantime::parse_duration("30s").unwrap(),
            Duration::from_secs(30)
        );
        assert_eq!(
            humantime::parse_duration("30sec").unwrap(),
            Duration::from_secs(30)
        );
        assert_eq!(
            humantime::parse_duration("30seconds").unwrap(),
            Duration::from_secs(30)
        );
    }

    #[test]
    fn test_parse_duration_minutes_hours_days() {
        assert_eq!(
            humantime::parse_duration("2m").unwrap(),
            Duration::from_secs(120)
        );
        assert_eq!(
            humantime::parse_duration("2min").unwrap(),
            Duration::from_secs(120)
        );
        assert_eq!(
            humantime::parse_duration("1h").unwrap(),
            Duration::from_secs(3600)
        );
        assert_eq!(
            humantime::parse_duration("1d").unwrap(),
            Duration::from_secs(86400)
        );
        // fractional hours
        let d = humantime::parse_duration("1.5h").unwrap();
        assert!((d.as_secs_f64() - 1.5 * 3600.0).abs() < 1e-6);
    }
}