use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ClipMetadata {
pub camera_make: Option<String>,
pub camera_model: Option<String>,
pub lens: Option<String>,
pub iso: Option<u32>,
pub shutter_speed: Option<String>,
pub aperture: Option<String>,
pub white_balance: Option<String>,
pub scene_number: Option<String>,
pub take_number: Option<u32>,
pub camera_angle: Option<String>,
pub location: Option<String>,
pub director: Option<String>,
pub cinematographer: Option<String>,
pub production: Option<String>,
pub shoot_date: Option<DateTime<Utc>>,
pub copyright: Option<String>,
pub custom: HashMap<String, String>,
}
impl ClipMetadata {
#[must_use]
pub fn new() -> Self {
Self {
camera_make: None,
camera_model: None,
lens: None,
iso: None,
shutter_speed: None,
aperture: None,
white_balance: None,
scene_number: None,
take_number: None,
camera_angle: None,
location: None,
director: None,
cinematographer: None,
production: None,
shoot_date: None,
copyright: None,
custom: HashMap::new(),
}
}
pub fn set_custom(&mut self, key: String, value: String) {
self.custom.insert(key, value);
}
#[must_use]
pub fn get_custom(&self, key: &str) -> Option<&str> {
self.custom.get(key).map(String::as_str)
}
pub fn remove_custom(&mut self, key: &str) -> Option<String> {
self.custom.remove(key)
}
}
impl Default for ClipMetadata {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_metadata_creation() {
let metadata = ClipMetadata::new();
assert!(metadata.camera_make.is_none());
assert!(metadata.custom.is_empty());
}
#[test]
fn test_custom_fields() {
let mut metadata = ClipMetadata::new();
metadata.set_custom("color_space".to_string(), "Rec.709".to_string());
assert_eq!(metadata.get_custom("color_space"), Some("Rec.709"));
let removed = metadata.remove_custom("color_space");
assert_eq!(removed, Some("Rec.709".to_string()));
assert!(metadata.get_custom("color_space").is_none());
}
}