use crate::error::{ConformError, ConformResult};
use crate::importers::TimelineImporter;
use crate::types::ClipReference;
use std::path::Path;
pub struct XmlImporter {
format: XmlFormat,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum XmlFormat {
FcpXml,
PremiereXml,
ResolveXml,
Auto,
}
impl XmlImporter {
#[must_use]
pub const fn new(format: XmlFormat) -> Self {
Self { format }
}
fn detect_format(_content: &str) -> XmlFormat {
XmlFormat::FcpXml
}
fn parse_fcpxml(&self, _content: &str) -> ConformResult<Vec<ClipReference>> {
Ok(Vec::new())
}
fn parse_premiere_xml(&self, _content: &str) -> ConformResult<Vec<ClipReference>> {
Ok(Vec::new())
}
fn parse_resolve_xml(&self, _content: &str) -> ConformResult<Vec<ClipReference>> {
Ok(Vec::new())
}
}
impl Default for XmlImporter {
fn default() -> Self {
Self::new(XmlFormat::Auto)
}
}
impl TimelineImporter for XmlImporter {
fn import<P: AsRef<Path>>(&self, path: P) -> ConformResult<Vec<ClipReference>> {
let content = std::fs::read_to_string(path)?;
let format = if self.format == XmlFormat::Auto {
Self::detect_format(&content)
} else {
self.format
};
match format {
XmlFormat::FcpXml => self.parse_fcpxml(&content),
XmlFormat::PremiereXml => self.parse_premiere_xml(&content),
XmlFormat::ResolveXml => self.parse_resolve_xml(&content),
XmlFormat::Auto => Err(ConformError::UnsupportedFormat(
"Could not auto-detect XML format".to_string(),
)),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_xml_importer_creation() {
let importer = XmlImporter::new(XmlFormat::FcpXml);
assert_eq!(importer.format, XmlFormat::FcpXml);
}
#[test]
fn test_xml_importer_default() {
let importer = XmlImporter::default();
assert_eq!(importer.format, XmlFormat::Auto);
}
}