gosh_dl/protocol/
options.rs1use super::checksum::ExpectedChecksum;
6use serde::{Deserialize, Serialize};
7use std::path::PathBuf;
8
9#[derive(
11 Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
12)]
13#[serde(rename_all = "lowercase")]
14#[repr(i8)]
15pub enum DownloadPriority {
16 Low = -1,
18 #[default]
20 Normal = 0,
21 High = 1,
23 Critical = 2,
25}
26
27impl std::fmt::Display for DownloadPriority {
28 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29 match self {
30 Self::Low => write!(f, "low"),
31 Self::Normal => write!(f, "normal"),
32 Self::High => write!(f, "high"),
33 Self::Critical => write!(f, "critical"),
34 }
35 }
36}
37
38impl std::str::FromStr for DownloadPriority {
39 type Err = String;
40
41 fn from_str(s: &str) -> Result<Self, Self::Err> {
42 match s.to_lowercase().as_str() {
43 "low" | "-1" => Ok(Self::Low),
44 "normal" | "0" => Ok(Self::Normal),
45 "high" | "1" => Ok(Self::High),
46 "critical" | "2" => Ok(Self::Critical),
47 _ => Err(format!("Invalid priority: {}", s)),
48 }
49 }
50}
51
52#[derive(Debug, Clone, Default, Serialize, Deserialize)]
54pub struct DownloadOptions {
55 #[serde(default)]
57 pub priority: DownloadPriority,
58 pub save_dir: Option<PathBuf>,
60 pub filename: Option<String>,
62 pub user_agent: Option<String>,
64 pub referer: Option<String>,
66 pub headers: Vec<(String, String)>,
68 pub cookies: Option<Vec<String>>,
70 pub checksum: Option<ExpectedChecksum>,
72 pub mirrors: Vec<String>,
74 pub max_connections: Option<usize>,
76 pub max_download_speed: Option<u64>,
78 pub max_upload_speed: Option<u64>,
80 pub seed_ratio: Option<f64>,
82 pub selected_files: Option<Vec<usize>>,
84 pub sequential: Option<bool>,
86}