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,56 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
use crate::domain::entities::Project;
|
||||
use crate::domain::value_objects::{SyncOffset, TrackId};
|
||||
|
||||
/// Ajusta o offset de sincronização de uma faixa externa existente pelo TrackId.
|
||||
pub struct AdjustSync;
|
||||
|
||||
impl AdjustSync {
|
||||
pub fn execute(project: &mut Project, id: TrackId, offset: SyncOffset) -> Result<()> {
|
||||
let track = project
|
||||
.find_track_mut(id)
|
||||
.ok_or_else(|| anyhow!("Faixa não encontrada: {:?}", id))?;
|
||||
track.set_offset(offset);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::application::use_cases::add_audio_track::AddAudioTrack;
|
||||
use crate::domain::entities::{MkvOutput, Project, VideoFile};
|
||||
use crate::domain::value_objects::{FilePath, TrackLanguage};
|
||||
|
||||
#[test]
|
||||
fn ajusta_offset_existente() {
|
||||
let mut project = Project::new(
|
||||
VideoFile::new(FilePath::from("input.mkv")),
|
||||
MkvOutput::new(FilePath::from("output.mkv")),
|
||||
)
|
||||
.unwrap();
|
||||
let lang = TrackLanguage::new("por").unwrap();
|
||||
AddAudioTrack::execute(
|
||||
&mut project,
|
||||
FilePath::from("audio.aac"),
|
||||
SyncOffset::default(),
|
||||
lang,
|
||||
)
|
||||
.unwrap();
|
||||
let id = project.tracks[0].id();
|
||||
|
||||
AdjustSync::execute(&mut project, id, SyncOffset::from_ms(1200)).unwrap();
|
||||
assert_eq!(project.tracks[0].offset().as_ms(), 1200);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn erro_se_id_inexistente() {
|
||||
let mut project = Project::new(
|
||||
VideoFile::new(FilePath::from("input.mkv")),
|
||||
MkvOutput::new(FilePath::from("output.mkv")),
|
||||
)
|
||||
.unwrap();
|
||||
let result = AdjustSync::execute(&mut project, TrackId::new(99), SyncOffset::from_ms(500));
|
||||
assert!(result.is_err());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user