use std::fmt::{Debug, Display};
use serde::{Deserialize, Serialize};
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Debug, Default)]
pub enum TorrentFormat {
#[serde(rename = "v1")]
V1,
#[serde(rename = "v2")]
V2,
#[serde(rename = "hybrid")]
#[default]
Hybrid,
}
impl Display for TorrentFormat {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
TorrentFormat::V1 => "v1",
TorrentFormat::V2 => "v2",
TorrentFormat::Hybrid => "hybrid",
}
)
}
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct TorrentPieceSize(pub i32);
impl Default for TorrentPieceSize {
fn default() -> Self {
Self::auto()
}
}
impl From<i32> for TorrentPieceSize {
fn from(value: i32) -> Self {
Self(value)
}
}
impl TorrentPieceSize {
pub fn auto() -> Self {
Self(0)
}
pub fn k16() -> Self {
Self(16384)
}
pub fn k32() -> Self {
Self(32768)
}
pub fn k64() -> Self {
Self(65536)
}
pub fn k128() -> Self {
Self(131072)
}
pub fn k256() -> Self {
Self(262144)
}
pub fn k512() -> Self {
Self(524288)
}
pub fn m1() -> Self {
Self(1048576)
}
pub fn m2() -> Self {
Self(2097152)
}
pub fn m4() -> Self {
Self(4194304)
}
pub fn m8() -> Self {
Self(8388608)
}
pub fn m16() -> Self {
Self(16777216)
}
pub fn m32() -> Self {
Self(33554432)
}
pub fn m64() -> Self {
Self(67108864)
}
pub fn m128() -> Self {
Self(134217728)
}
pub fn m256() -> Self {
Self(268435456)
}
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum TaskStatus {
Failed,
Queued,
Running,
Finished,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TorrentCreatorTask {
#[serde(rename = "taskID")]
pub task_id: String,
pub source_path: String,
pub piece_size: TorrentPieceSize,
#[cfg(feature = "qBittorrent-5_3")]
pub ignore_dotfiles: bool,
pub private: bool,
pub time_added: String,
pub format: Option<TorrentFormat>,
pub optimize_alignment: Option<bool>,
pub padded_file_size_limit: Option<i32>,
pub status: TaskStatus,
pub comment: Option<String>,
pub torrent_file_path: Option<String>,
pub source: Option<String>,
pub trackers: Vec<String>,
pub url_seeds: Vec<String>,
pub time_started: Option<String>,
pub time_finished: Option<String>,
pub error_message: Option<String>,
pub progress: Option<i32>,
}