use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
pub enum DownloadType {
#[default]
Video,
Audio,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
pub enum DownloadSource {
#[default]
Single,
Batch,
Playlist,
Channel,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
pub enum Quality {
Best,
#[default]
HD1080,
HD720,
SD480,
}
impl DownloadType {
pub fn label(&self) -> &'static str {
match self {
DownloadType::Video => "📹 Video",
DownloadType::Audio => "🎵 Audio",
}
}
}
impl DownloadSource {
pub fn label(&self) -> &'static str {
match self {
DownloadSource::Single => "Single URL",
DownloadSource::Batch => "Batch File",
DownloadSource::Playlist => "Playlist",
DownloadSource::Channel => "Channel",
}
}
pub fn icon(&self) -> &'static str {
match self {
DownloadSource::Single => "🔗",
DownloadSource::Batch => "📄",
DownloadSource::Playlist => "📋",
DownloadSource::Channel => "📺",
}
}
#[allow(dead_code)]
pub fn needs_url(&self) -> bool {
!matches!(self, DownloadSource::Batch)
}
pub fn output_template(&self, base_dir: &str) -> String {
let dir = base_dir.trim_end_matches('/');
match self {
DownloadSource::Single | DownloadSource::Batch => format!(
"{}/%(title)s - [%(uploader)s - %(upload_date>%b %d %Y)s].%(ext)s",
dir
),
DownloadSource::Playlist => format!(
"{}/Playlists/@%(uploader)s/%(playlist_title)s/%(playlist_index)03d - %(title)s - [%(upload_date>%b %d %Y)s].%(ext)s",
dir
),
DownloadSource::Channel => format!(
"{}/Channels/@%(uploader)s/%(title)s - [%(upload_date>%b %d %Y)s].%(ext)s",
dir
),
}
}
}
impl Quality {
pub fn label(&self) -> &'static str {
match self {
Quality::Best => "Best",
Quality::HD1080 => "1080p",
Quality::HD720 => "720p",
Quality::SD480 => "480p",
}
}
pub fn format_string(&self) -> &'static str {
match self {
Quality::Best => "bestvideo+bestaudio/best",
Quality::HD1080 => "bestvideo[height<=1080]+bestaudio/best[height<=1080]",
Quality::HD720 => "bestvideo[height<=720]+bestaudio/best[height<=720]",
Quality::SD480 => "bestvideo[height<=480]+bestaudio/best[height<=480]",
}
}
}