Skip to main content

vidsage_core/utils/
validators.rs

1//! Validation functions
2
3use std::path::Path;
4
5/// Validate a video format
6pub 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
13/// Validate a commentary style
14pub 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
28/// Validate a language code (ISO 639-1)
29pub fn validate_language_code(code: &str) -> bool {
30    code.len() == 2 && code.chars().all(|c| c.is_ascii_lowercase())
31}
32
33/// Validate a resolution tuple (width, height)
34pub fn validate_resolution(resolution: (u32, u32)) -> bool {
35    let (width, height) = resolution;
36    width > 0 && height > 0 && width <= 8192 && height <= 8192
37}
38
39/// Validate a frame rate
40pub fn validate_frame_rate(frame_rate: f64) -> bool {
41    frame_rate > 0.0 && frame_rate <= 120.0
42}
43
44/// Validate a compression level (0-9)
45pub fn validate_compression_level(level: u8) -> bool {
46    level <= 9
47}
48
49/// Validate a file path
50pub fn validate_file_path(path: &Path) -> bool {
51    path.is_absolute() || path.starts_with("./") || path.starts_with("../")
52}
53
54/// Validate a video processing quality
55pub fn validate_video_quality(quality: &str) -> bool {
56    matches!(
57        quality.to_lowercase().as_str(),
58        "low" | "medium" | "high" | "ultra"
59    )
60}
61
62/// Validate a positive integer
63pub fn validate_positive_integer(value: i64) -> bool {
64    value > 0
65}
66
67/// Validate a positive float
68pub fn validate_positive_float(value: f64) -> bool {
69    value > 0.0
70}
71
72/// Validate a percentage (0-100)
73pub fn validate_percentage(value: u8) -> bool {
74    value <= 100
75}