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")
|
XmpMeta::register_namespace(XMP, "xmp")
|
||||||
.map_err(|e| CoreError::Unknown(format!("Failed to register XMP namespace: {}", e)))?;
|
.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 {
|
for meta in metadata {
|
||||||
match meta.source {
|
match meta.source {
|
||||||
@@ -48,10 +48,10 @@ impl MediaProcessorPlugin for XmpWriterPlugin {
|
|||||||
continue;
|
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 => {
|
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 {
|
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 {
|
write_face_regions(&mut xmp, &faces, context).await?;
|
||||||
eprintln!("Failed to write face regions to XMP: {}", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
let xmp_str = xmp.to_string();
|
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) {
|
fn set_xmp_prop(xmp: &mut XmpMeta, ns: &str, key: &str, value: &str) -> CoreResult<()> {
|
||||||
if let Err(e) = xmp.set_property(ns, key, &XmpValue::from(value)) {
|
xmp.set_property(ns, key, &XmpValue::from(value))
|
||||||
eprintln!("Failed to set {}:{} in XMP: {}", ns, key, e);
|
.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) {
|
fn add_xmp_array_item(xmp: &mut XmpMeta, ns: &str, key: &str, value: &str) -> CoreResult<()> {
|
||||||
if let Err(e) = xmp.append_array_item(ns, &XmpValue::from(key), &XmpValue::from(value)) {
|
xmp.append_array_item(ns, &XmpValue::from(key), &XmpValue::from(value))
|
||||||
eprintln!("Failed to add item to {}:{} in XMP: {}", ns, key, e);
|
.map_err(|e| {
|
||||||
}
|
CoreError::Unknown(format!(
|
||||||
|
"Failed to append item to {}:{} array in XMP: {}",
|
||||||
|
ns, key, e
|
||||||
|
))
|
||||||
|
})?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn write_face_regions(
|
async fn write_face_regions(
|
||||||
@@ -123,7 +126,7 @@ async fn write_face_regions(
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
let name_path = format!("{}/mwg-rs:Name", region_path);
|
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!(
|
let area_str = format!(
|
||||||
"{}, {}, {}, {}",
|
"{}, {}, {}, {}",
|
||||||
@@ -133,10 +136,10 @@ async fn write_face_regions(
|
|||||||
face.y_max - face.y_min // Height
|
face.y_max - face.y_min // Height
|
||||||
);
|
);
|
||||||
let area_path = format!("{}/mwg-rs:Area", region_path);
|
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);
|
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(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user