feat: Update XMP writing functions to handle errors properly and ensure consistency
This commit is contained in:
@@ -39,7 +39,7 @@ impl MediaProcessorPlugin for XmpWriterPlugin {
|
||||
XmpMeta::register_namespace(XMP, "xmp")
|
||||
.map_err(|e| CoreError::Unknown(format!("Failed to register XMP namespace: {}", e)))?;
|
||||
|
||||
set_xmp_prop(&mut xmp, DC, "title", &media.original_filename);
|
||||
set_xmp_prop(&mut xmp, DC, "title", &media.original_filename)?;
|
||||
|
||||
for meta in metadata {
|
||||
match meta.source {
|
||||
@@ -48,10 +48,10 @@ impl MediaProcessorPlugin for XmpWriterPlugin {
|
||||
continue;
|
||||
}
|
||||
|
||||
set_xmp_prop(&mut xmp, EXIF, &meta.tag_name, &meta.tag_value);
|
||||
set_xmp_prop(&mut xmp, EXIF, &meta.tag_name, &meta.tag_value)?;
|
||||
}
|
||||
MediaMetadataSource::TrackInfo => {
|
||||
set_xmp_prop(&mut xmp, XMP, &meta.tag_name, &meta.tag_value);
|
||||
set_xmp_prop(&mut xmp, XMP, &meta.tag_name, &meta.tag_value)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,13 +63,11 @@ impl MediaProcessorPlugin for XmpWriterPlugin {
|
||||
})?;
|
||||
|
||||
for tag in tags {
|
||||
add_xmp_array_item(&mut xmp, DC, "subject", &tag.name);
|
||||
add_xmp_array_item(&mut xmp, DC, "subject", &tag.name)?;
|
||||
}
|
||||
}
|
||||
|
||||
if let Err(e) = write_face_regions(&mut xmp, &faces, context).await {
|
||||
eprintln!("Failed to write face regions to XMP: {}", e);
|
||||
}
|
||||
write_face_regions(&mut xmp, &faces, context).await?;
|
||||
|
||||
let xmp_str = xmp.to_string();
|
||||
|
||||
@@ -81,16 +79,21 @@ impl MediaProcessorPlugin for XmpWriterPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
fn set_xmp_prop(xmp: &mut XmpMeta, ns: &str, key: &str, value: &str) {
|
||||
if let Err(e) = xmp.set_property(ns, key, &XmpValue::from(value)) {
|
||||
eprintln!("Failed to set {}:{} in XMP: {}", ns, key, e);
|
||||
}
|
||||
fn set_xmp_prop(xmp: &mut XmpMeta, ns: &str, key: &str, value: &str) -> CoreResult<()> {
|
||||
xmp.set_property(ns, key, &XmpValue::from(value))
|
||||
.map_err(|e| CoreError::Unknown(format!("Failed to set {}:{} in XMP: {}", ns, key, e)))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn add_xmp_array_item(xmp: &mut XmpMeta, ns: &str, key: &str, value: &str) {
|
||||
if let Err(e) = xmp.append_array_item(ns, &XmpValue::from(key), &XmpValue::from(value)) {
|
||||
eprintln!("Failed to add item to {}:{} in XMP: {}", ns, key, e);
|
||||
}
|
||||
fn add_xmp_array_item(xmp: &mut XmpMeta, ns: &str, key: &str, value: &str) -> CoreResult<()> {
|
||||
xmp.append_array_item(ns, &XmpValue::from(key), &XmpValue::from(value))
|
||||
.map_err(|e| {
|
||||
CoreError::Unknown(format!(
|
||||
"Failed to append item to {}:{} array in XMP: {}",
|
||||
ns, key, e
|
||||
))
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn write_face_regions(
|
||||
@@ -123,7 +126,7 @@ async fn write_face_regions(
|
||||
})?;
|
||||
|
||||
let name_path = format!("{}/mwg-rs:Name", region_path);
|
||||
set_xmp_prop(xmp, "mwg-rs", &name_path, &person_name);
|
||||
set_xmp_prop(xmp, "mwg-rs", &name_path, &person_name)?;
|
||||
|
||||
let area_str = format!(
|
||||
"{}, {}, {}, {}",
|
||||
@@ -133,10 +136,10 @@ async fn write_face_regions(
|
||||
face.y_max - face.y_min // Height
|
||||
);
|
||||
let area_path = format!("{}/mwg-rs:Area", region_path);
|
||||
set_xmp_prop(xmp, "mwg-rs", &area_path, &area_str);
|
||||
set_xmp_prop(xmp, "mwg-rs", &area_path, &area_str)?;
|
||||
|
||||
let type_path = format!("{}/mwg-rs:Type", region_path);
|
||||
set_xmp_prop(xmp, "mwg-rs", &type_path, "Face");
|
||||
set_xmp_prop(xmp, "mwg-rs", &type_path, "Face")?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user