summary history branches tags files
commit:58c44473087c14896994cba32d6d972c5818f947
author:Trevor Bentley
committer:Trevor Bentley
date:Mon Jan 13 22:26:04 2025 +0100
parents:fca8c9f3cf33990b050ce6502df263d66f51849c
add option to skip processing if already processed
diff --git a/README.md b/README.md
line changes: +4/-0
index a84f964..7eb44a9
--- a/README.md
+++ b/README.md
@@ -74,6 +74,10 @@ identifier_bin_args = []
 #
 # temp_dir = ""
 
+# Skip files that have already been processed by pww
+#
+skip_processed = false
+
 # Policy defining which file(s) should be updated with new metadata
 #
 #  - DisplayOnly - Just print the tags, do not update any files

diff --git a/src/main.rs b/src/main.rs
line changes: +28/-1
index 20a8dda..bfd31a8
--- a/src/main.rs
+++ b/src/main.rs
@@ -58,6 +58,10 @@ struct PwwArgs {
     #[arg(short = 'n', long)]
     dry_run: bool,
 
+    /// Skip files that have already been processed by pww
+    #[arg(short = 's', long)]
+    skip_processed: bool,
+
     /// Print information about which tags are written
     #[arg(short = 'v', long)]
     verbose: bool,
@@ -197,6 +201,9 @@ struct PwwConfig {
     /// Directory to store temporary files
     temp_dir: Option<PathBuf>,
 
+    /// Skip files that have already been processed by pww
+    skip_processed: bool,
+
     /// Policy for which metadata should be updated
     file_update_policy: FileUpdatePolicy,
 
@@ -304,6 +311,10 @@ impl PwwConfig {
         self.cli.as_ref().map(|c| c.dry_run).unwrap_or_default()
     }
 
+    fn skip_processed(&self) -> bool {
+        self.cli.as_ref().map(|c| c.skip_processed).unwrap_or_default()
+    }
+
     fn verbose(&self) -> bool {
         self.cli.as_ref().map(|c| c.verbose).unwrap_or_default()
     }
@@ -332,6 +343,7 @@ impl ::std::default::Default for PwwConfig {
             identifier_bin: None,
             identifier_bin_args: vec!(),
             temp_dir: None,
+            skip_processed: false,
             file_update_policy: FileUpdatePolicy::SidecarOnly,
             tag_update_policy: TagUpdatePolicy::ReplacePrefixed,
             tag_prefix: Some("[ML] ".to_owned()),
@@ -703,7 +715,22 @@ fn process_image(config: &PwwConfig, input_path: &Path) -> Result<(), PwwError> 
     // Check sidecar file before analysis because it's a common error
     // and we might as well not waste time analyzing when the tags
     // won't be writeable.
-    let _ = should_update_sidecar(&config, &input_path)?;
+    let metafile = match should_update_sidecar(&config, &input_path)? {
+        Some(p) => p,
+        None => input_path.to_owned(),
+    };
+
+    // Check the metadata to see if this file has already been
+    // processed, and skip it if configured to do so.
+    let _ = rexiv2::register_xmp_namespace("pww", "photo-what-what");
+    let meta = rexiv2::Metadata::new_from_path(&metafile)
+        .map_err(|e| PwwError::Unknown(format!("Unable to read metadata from image file: {}", e)))?;
+    if config.skip_processed() && meta.get_tag_numeric("Xmp.photo-what-what.processed") == 1 {
+        if config.verbose() {
+            println!(" - already processed, skipped!")
+        }
+        return Ok(());
+    }
 
     // run ML engine on file
     if config.debug() {