vidsage_core/utils/
validators.rs1use std::path::Path;
4
5pub fn validate_video_format(format: &str) -> bool {
7 matches!(
8 format.to_lowercase().as_str(),
9 "mp4" | "webm" | "avi" | "mov" | "mkv" | "flv" | "wmv" | "m4v"
10 )
11}
12
13pub fn validate_commentary_style(style: &str) -> bool {
15 matches!(
16 style.to_lowercase().as_str(),
17 "professional"
18 | "casual"
19 | "educational"
20 | "entertaining"
21 | "analytical"
22 | "storytelling"
23 | "poetic"
24 | "technical"
25 )
26}
27
28pub fn validate_language_code(code: &str) -> bool {
30 code.len() == 2 && code.chars().all(|c| c.is_ascii_lowercase())
31}
32
33pub fn validate_resolution(resolution: (u32, u32)) -> bool {
35 let (width, height) = resolution;
36 width > 0 && height > 0 && width <= 8192 && height <= 8192
37}
38
39pub fn validate_frame_rate(frame_rate: f64) -> bool {
41 frame_rate > 0.0 && frame_rate <= 120.0
42}
43
44pub fn validate_compression_level(level: u8) -> bool {
46 level <= 9
47}
48
49pub fn validate_file_path(path: &Path) -> bool {
51 path.is_absolute() || path.starts_with("./") || path.starts_with("../")
52}
53
54pub fn validate_video_quality(quality: &str) -> bool {
56 matches!(
57 quality.to_lowercase().as_str(),
58 "low" | "medium" | "high" | "ultra"
59 )
60}
61
62pub fn validate_positive_integer(value: i64) -> bool {
64 value > 0
65}
66
67pub fn validate_positive_float(value: f64) -> bool {
69 value > 0.0
70}
71
72pub fn validate_percentage(value: u8) -> bool {
74 value <= 100
75}