use crate::prelude::*;
use flat_db::Hash;
use lava_torrent::torrent::v1::Torrent;
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize, Default)]
pub(crate) struct QueueItem {
pub name: String,
pub path: PathBuf,
pub hash: Hash<20>,
pub indexer: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub verify: Option<VerifyStatus>,
#[serde(skip_serializing_if = "Option::is_none")]
pub spectrogram: Option<SpectrogramStatus>,
#[serde(skip_serializing_if = "Option::is_none")]
pub transcode: Option<TranscodeStatus>,
#[serde(skip_serializing_if = "Option::is_none")]
pub upload: Option<UploadStatus>,
}
impl QueueItem {
#[must_use]
pub(crate) fn from_torrent(path: PathBuf, torrent: &Torrent) -> Self {
let comment = torrent.comment().unwrap_or_default();
let id = get_torrent_id_from_torrent_url(comment);
let info_hash = torrent.info_hash();
Self {
name: torrent.name.clone(),
path,
hash: Hash::from_string(&info_hash).expect("torrent hash should be valid"),
indexer: torrent.source().unwrap_or_default().to_lowercase(),
id,
..Self::default()
}
}
}
impl Display for QueueItem {
fn fmt(&self, formatter: &mut Formatter<'_>) -> FmtResult {
write!(formatter, "{}", self.name)
}
}