use crate::commentary::CommentaryStyle;
use crate::video::metadata::{VideoFormat, VideoQuality};
use crate::video::processor::CompressionLevel;
pub fn string_to_video_format(s: &str) -> Option<VideoFormat> {
match s.to_lowercase().as_str() {
"mp4" => Some(VideoFormat::MP4),
"webm" => Some(VideoFormat::WebM),
"avi" => Some(VideoFormat::AVI),
"mov" => Some(VideoFormat::MOV),
"mkv" => Some(VideoFormat::MKV),
"flv" => Some(VideoFormat::FLV),
_ => Some(VideoFormat::Other),
}
}
pub fn video_format_to_string(format: VideoFormat) -> String {
match format {
VideoFormat::MP4 => "mp4".to_string(),
VideoFormat::WebM => "webm".to_string(),
VideoFormat::AVI => "avi".to_string(),
VideoFormat::MOV => "mov".to_string(),
VideoFormat::MKV => "mkv".to_string(),
VideoFormat::FLV => "flv".to_string(),
VideoFormat::Other => "other".to_string(),
}
}
pub fn string_to_commentary_style(s: &str) -> Option<CommentaryStyle> {
match s.to_lowercase().as_str() {
"professional" => Some(CommentaryStyle::Professional),
"casual" => Some(CommentaryStyle::Casual),
"educational" => Some(CommentaryStyle::Educational),
"entertaining" => Some(CommentaryStyle::Entertaining),
"analytical" => Some(CommentaryStyle::Analytical),
"storytelling" => Some(CommentaryStyle::Storytelling),
"poetic" => Some(CommentaryStyle::Poetic),
"technical" => Some(CommentaryStyle::Technical),
_ => None,
}
}
pub fn commentary_style_to_string(style: CommentaryStyle) -> String {
match style {
CommentaryStyle::Professional => "professional".to_string(),
CommentaryStyle::Casual => "casual".to_string(),
CommentaryStyle::Educational => "educational".to_string(),
CommentaryStyle::Entertaining => "entertaining".to_string(),
CommentaryStyle::Analytical => "analytical".to_string(),
CommentaryStyle::Storytelling => "storytelling".to_string(),
CommentaryStyle::Poetic => "poetic".to_string(),
CommentaryStyle::Technical => "technical".to_string(),
}
}
pub fn string_to_video_quality(s: &str) -> Option<VideoQuality> {
match s.to_lowercase().as_str() {
"low" => Some(VideoQuality::Low),
"medium" => Some(VideoQuality::Medium),
"high" => Some(VideoQuality::High),
"ultra" => Some(VideoQuality::Ultra),
_ => {
s.parse::<u32>().ok().map(VideoQuality::Custom)
},
}
}
pub fn video_quality_to_string(quality: VideoQuality) -> String {
match quality {
VideoQuality::Low => "low".to_string(),
VideoQuality::Medium => "medium".to_string(),
VideoQuality::High => "high".to_string(),
VideoQuality::Ultra => "ultra".to_string(),
VideoQuality::Custom(bitrate) => bitrate.to_string(),
}
}
pub fn string_to_compression_level(s: &str) -> Option<CompressionLevel> {
match s.to_lowercase().as_str() {
"low" => Some(CompressionLevel::Low),
"medium" => Some(CompressionLevel::Medium),
"high" => Some(CompressionLevel::High),
"ultra" => Some(CompressionLevel::Ultra),
_ => {
s.parse::<f32>()
.ok()
.filter(|&x| (0.1..=1.0).contains(&x))
.map(CompressionLevel::Custom)
},
}
}
pub fn compression_level_to_string(level: CompressionLevel) -> String {
match level {
CompressionLevel::Low => "low".to_string(),
CompressionLevel::Medium => "medium".to_string(),
CompressionLevel::High => "high".to_string(),
CompressionLevel::Ultra => "ultra".to_string(),
CompressionLevel::Custom(ratio) => ratio.to_string(),
}
}
pub fn string_to_bool(s: &str) -> Option<bool> {
match s.to_lowercase().as_str() {
"true" | "yes" | "1" => Some(true),
"false" | "no" | "0" => Some(false),
_ => None,
}
}
pub fn bool_to_string(value: bool) -> String {
if value {
"true".to_string()
} else {
"false".to_string()
}
}