photo_sort 0.3.3

A tool to rename and sort photos/videos by its EXIF date/metadata. It tries to extract the date from the EXIF data or file name and renames the image file according to a given format string. Foreach source directory all images are processed and renamed to the target directory
Documentation
use crate::analysis::name_formatters::{NameFormatter, NameFormatterInvocationInfo};
use anyhow::Result;
use regex::Regex;
use std::sync::LazyLock;

static DUPLICATE_FORMAT: LazyLock<regex::Regex> =
    LazyLock::new(|| regex::Regex::new(r"^(dup|duplicate)$").expect("Failed to compile regex"));

/// Formats a duplicate format command {dup} to a duplicate counter string.
#[derive(Debug, Default)]
pub struct FormatDuplicate {}

impl NameFormatter for FormatDuplicate {
    fn argument_template(&self) -> &Regex {
        &DUPLICATE_FORMAT
    }
    fn replacement_text(
        &self,
        _capture: regex::Captures<'_>,
        invocation_info: &NameFormatterInvocationInfo,
    ) -> Result<String> {
        let duplicate_string = invocation_info
            .duplicate_counter
            .map_or(String::new(), |c| c.to_string());
        Ok(duplicate_string)
    }
}