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 DATE_FORMAT: LazyLock<regex::Regex> =
    LazyLock::new(|| regex::Regex::new(r"^(date|d)(\?(.+))?$").expect("Failed to compile regex"));

/// Formats a date format command {date} to a date string.
#[derive(Debug, Default)]
pub struct FormatDate {}

impl NameFormatter for FormatDate {
    fn argument_template(&self) -> &Regex {
        &DATE_FORMAT
    }
    fn replacement_text(
        &self,
        capture: regex::Captures<'_>,
        invocation_info: &NameFormatterInvocationInfo,
    ) -> Result<String> {
        let format_string = capture
            .get(3)
            .map_or(invocation_info.date_default_format.as_str(), |m| m.as_str());
        Ok(invocation_info.date.map_or("NODATE".to_string(), |x| {
            x.format(format_string).to_string()
        }))
    }
}