use crate::config::FixPolicy; use crate::fix::{FixAction, FixKind, FixOutcome, FixPlan}; use crate::rules::FixTier; use crate::scan::Issue; pub fn plan_fix(issues: &[Issue], policy: FixPolicy) -> FixPlan { let mut recommended = None; let mut has_faststart = false; let mut has_remux = false; let mut has_reencode = false; for issue in issues { if let Some(action) = &issue.action { if action.eq_ignore_ascii_case("faststart") { has_faststart = true; } } match issue.fix_tier { FixTier::Remux => has_remux = true, FixTier::Reencode => has_reencode = true, FixTier::None => {} } } if has_faststart { recommended = Some(FixKind::Faststart); } else if has_remux { recommended = Some(FixKind::Remux); } else if has_reencode { recommended = Some(FixKind::Reencode); } let mut actions = Vec::new(); let mut blocked_reason = None; if let Some(kind) = recommended { if kind == FixKind::Reencode && policy == FixPolicy::Safe { blocked_reason = Some("Re-encode required but policy is safe".to_string()); } else { actions.push(FixAction { kind, command: command_template(kind), destructive: true, }); } } FixPlan { policy, recommended, actions, blocked_reason, } } pub fn plan_outcome(plan: FixPlan) -> FixOutcome { let message = if let Some(kind) = plan.recommended { format!("Fix plan generated: {:?}", kind) } else { "Fix plan generated".to_string() }; FixOutcome { plan, applied: false, success: false, message, output_path: None, re_scan_required: false, } } fn command_template(kind: FixKind) -> Vec { let mut cmd = vec![ "ffmpeg".to_string(), "-v".to_string(), "error".to_string(), "-i".to_string(), "".to_string(), ]; match kind { FixKind::Remux => { cmd.push("-c".to_string()); cmd.push("copy".to_string()); } FixKind::Faststart => { cmd.push("-c".to_string()); cmd.push("copy".to_string()); cmd.push("-movflags".to_string()); cmd.push("+faststart".to_string()); } FixKind::Reencode => { cmd.push("-c:v".to_string()); cmd.push("libx264".to_string()); cmd.push("-c:a".to_string()); cmd.push("aac".to_string()); cmd.push("-movflags".to_string()); cmd.push("+faststart".to_string()); } } cmd.push("".to_string()); cmd }