feat: implement project management and media track handling
- Added domain entities for audio, subtitle, and video tracks. - Created a Project entity to manage media editing sessions. - Implemented value objects for file paths, sync offsets, track IDs, and languages. - Developed infrastructure for asynchronous FFmpeg process execution. - Built a user interface for selecting video files, adding audio and subtitle tracks, and managing output settings. - Integrated error handling and logging for media processing tasks.
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Código de idioma ISO 639-2 (3 letras minúsculas), ex: "por", "eng".
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct TrackLanguage(String);
|
||||
|
||||
impl TrackLanguage {
|
||||
/// Cria um TrackLanguage validando o formato ISO 639-2 (3 letras minúsculas).
|
||||
pub fn new(code: impl Into<String>) -> Result<Self> {
|
||||
let code = code.into();
|
||||
if code.len() == 3 && code.chars().all(|c| c.is_ascii_lowercase()) {
|
||||
Ok(TrackLanguage(code))
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"Código de idioma inválido: '{}'. Esperado formato ISO 639-2 (3 letras minúsculas, ex: 'por', 'eng')",
|
||||
code
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_str(&self) -> &str {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for TrackLanguage {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn idioma_valido() {
|
||||
assert!(TrackLanguage::new("por").is_ok());
|
||||
assert!(TrackLanguage::new("eng").is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn idioma_invalido_curto() {
|
||||
assert!(TrackLanguage::new("pt").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn idioma_invalido_maiusculo() {
|
||||
assert!(TrackLanguage::new("POR").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn idioma_invalido_longo() {
|
||||
assert!(TrackLanguage::new("port").is_err());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user