|
5 | 5 | //! without extension), `{num}` (the number at the end of the name: `IMG_0042` → `0042`), `{seq}` / |
6 | 6 | //! `{seq:3}` (sequence number, zero-padded to 3 digits), `{date}` / `{date:%Y%m%d}` (capture date; |
7 | 7 | //! `%Y %y %m %B %b %d %H %M %S`), `{folder}` (the original's folder name), `{camera}`, `{lens}`, `{iso}`, |
8 | | -//! `{rating}`, `{title}`, `{creator}`, `{ext}` (extension, without the dot). Unknown tokens stay as |
9 | | -//! typed. Characters that aren't allowed in file names become `-`. The original extension is always |
10 | | -//! kept. |
| 8 | +//! `{rating}`, `{title}`, `{creator}`, `{ext}` (extension, without the dot), and the metadata fields |
| 9 | +//! the library stores (`{caption}`, `{headline}`, `{category}`, `{keywords}`, `{copyright}`, |
| 10 | +//! `{job_title}`, `{location}`, `{city}`, `{state}`, `{country}`, `{serial}`, `{alt_text}`, |
| 11 | +//! `{extended_description}`, `{description_writer}`, `{shutter}`, `{aperture}`, `{focal}`; issue |
| 12 | +//! #1584: freely usable metadata fields as file-name tags, for markers other apps don't use). |
| 13 | +//! Unknown tokens stay as typed. Characters that aren't allowed in file names become `-`. The |
| 14 | +//! original extension is always kept. |
11 | 15 | //! |
12 | 16 | //! Safety: |
13 | 17 | //! - a target that exists on disk, or that another photo in the batch gets, receives a `-1`, `-2`… |
@@ -139,6 +143,23 @@ pub const TOKENS: &[TokenHelp] = &[ |
139 | 143 | TokenHelp { tag: "{rating}", aliases: &[], meaning: "Star rating (0–5)" }, |
140 | 144 | TokenHelp { tag: "{title}", aliases: &[], meaning: "Title metadata" }, |
141 | 145 | TokenHelp { tag: "{creator}", aliases: &[], meaning: "Creator metadata" }, |
| 146 | + TokenHelp { tag: "{caption}", aliases: &[], meaning: "Caption metadata" }, |
| 147 | + TokenHelp { tag: "{headline}", aliases: &[], meaning: "Headline metadata" }, |
| 148 | + TokenHelp { tag: "{category}", aliases: &[], meaning: "Category metadata" }, |
| 149 | + TokenHelp { tag: "{keywords}", aliases: &[], meaning: "Keywords, separated by spaces" }, |
| 150 | + TokenHelp { tag: "{copyright}", aliases: &[], meaning: "Copyright notice metadata" }, |
| 151 | + TokenHelp { tag: "{job_title}", aliases: &[], meaning: "Creator's job title" }, |
| 152 | + TokenHelp { tag: "{location}", aliases: &[], meaning: "Location (sublocation)" }, |
| 153 | + TokenHelp { tag: "{city}", aliases: &[], meaning: "City" }, |
| 154 | + TokenHelp { tag: "{state}", aliases: &[], meaning: "State or province" }, |
| 155 | + TokenHelp { tag: "{country}", aliases: &[], meaning: "Country" }, |
| 156 | + TokenHelp { tag: "{serial}", aliases: &[], meaning: "Camera body serial number" }, |
| 157 | + TokenHelp { tag: "{alt_text}", aliases: &[], meaning: "Alt text (accessibility)" }, |
| 158 | + TokenHelp { tag: "{extended_description}", aliases: &[], meaning: "Long description (accessibility)" }, |
| 159 | + TokenHelp { tag: "{description_writer}", aliases: &[], meaning: "Caption writer metadata" }, |
| 160 | + TokenHelp { tag: "{shutter}", aliases: &[], meaning: "Shutter speed (1/250)" }, |
| 161 | + TokenHelp { tag: "{aperture}", aliases: &[], meaning: "f-number, number only (8, 2.8)" }, |
| 162 | + TokenHelp { tag: "{focal}", aliases: &[], meaning: "Focal length (24mm)" }, |
142 | 163 | TokenHelp { tag: "{ext}", aliases: &[], meaning: "Original extension without the dot" }, |
143 | 164 | TokenHelp { |
144 | 165 | tag: "{text:Couple initials}", |
@@ -267,6 +288,23 @@ pub fn sample_photo() -> Photo { |
267 | 288 | p.meta.iso = Some(400); |
268 | 289 | p.meta.title = "Harbour".into(); |
269 | 290 | p.meta.creator = "Ann Lee".into(); |
| 291 | + p.meta.caption = "The ferry leaves at dawn.".into(); |
| 292 | + p.meta.headline = "First light on the pier".into(); |
| 293 | + p.meta.category = "TRA".into(); |
| 294 | + p.meta.keywords = vec!["harbour".into(), "dawn".into()]; |
| 295 | + p.meta.copyright = "© 2026 Ann Lee".into(); |
| 296 | + p.meta.contact.job_title = "Photographer".into(); |
| 297 | + p.meta.location = "South Pier".into(); |
| 298 | + p.meta.city = "Fleetwood".into(); |
| 299 | + p.meta.state = "Lancashire".into(); |
| 300 | + p.meta.country = "England".into(); |
| 301 | + p.meta.camera_serial = "0123456789".into(); |
| 302 | + p.meta.alt_text = "A fishing boat at the pier at dawn".into(); |
| 303 | + p.meta.extended_description = "A red-hulled fishing boat moored at South Pier, Fleetwood, in first light.".into(); |
| 304 | + p.meta.description_writer = "A. Lee".into(); |
| 305 | + p.meta.shutter = "1/250".into(); |
| 306 | + p.meta.aperture = Some(8.0); |
| 307 | + p.meta.focal_mm = Some(24.0); |
270 | 308 | p |
271 | 309 | } |
272 | 310 |
|
@@ -431,6 +469,24 @@ pub fn expand_tokens_with( |
431 | 469 | "rating" => p.rating.to_string(), |
432 | 470 | "title" => p.meta.title.clone(), |
433 | 471 | "creator" => p.meta.creator.clone(), |
| 472 | + "caption" => p.meta.caption.clone(), |
| 473 | + "headline" => p.meta.headline.clone(), |
| 474 | + "category" => p.meta.category.clone(), |
| 475 | + "keywords" => p.meta.keywords.join(" "), |
| 476 | + "copyright" => p.meta.copyright.clone(), |
| 477 | + "job_title" => p.meta.contact.job_title.clone(), |
| 478 | + "location" => p.meta.location.clone(), |
| 479 | + "city" => p.meta.city.clone(), |
| 480 | + "state" => p.meta.state.clone(), |
| 481 | + "country" => p.meta.country.clone(), |
| 482 | + "serial" => p.meta.camera_serial.clone(), |
| 483 | + "alt_text" => p.meta.alt_text.clone(), |
| 484 | + "extended_description" => p.meta.extended_description.clone(), |
| 485 | + "description_writer" => p.meta.description_writer.clone(), |
| 486 | + "shutter" => p.meta.shutter.trim().to_string(), |
| 487 | + // the number only: "f/2.8" would lose its slash in a file name |
| 488 | + "aperture" => p.meta.aperture.filter(|a| a.is_finite() && *a > 0.0).map(|a| format!("{a:.1}").replace(".0", "")).unwrap_or_default(), |
| 489 | + "focal" => p.meta.focal_mm.filter(|f| f.is_finite() && *f > 0.0).map(|f| format!("{f:.0}mm")).unwrap_or_default(), |
434 | 490 | "ext" => ext.to_string(), |
435 | 491 | // (a text not filled in by `fill_texts`: nothing) |
436 | 492 | "text" if arg.is_some() => String::new(), |
@@ -2269,6 +2325,35 @@ pub(crate) mod tests { |
2269 | 2325 | assert_eq!(expand_tokens("{seq}|{seq:2}", &p, 7, 3), "007|07"); |
2270 | 2326 | } |
2271 | 2327 |
|
| 2328 | + /// The metadata fields the library stores are file-name tags (issue #1584): every new token |
| 2329 | + /// expands from its field, the technical ones name files (no slash), and a missing field |
| 2330 | + /// leaves an empty gap. |
| 2331 | + #[test] |
| 2332 | + fn metadata_tokens_name_files_from_the_stored_fields() { |
| 2333 | + let p = sample_photo(); |
| 2334 | + assert_eq!(expand_tokens("{caption}|{headline}|{category}", &p, 1, 1), "The ferry leaves at dawn.|First light on the pier|TRA"); |
| 2335 | + assert_eq!(expand_tokens("{keywords}", &p, 1, 1), "harbour dawn"); |
| 2336 | + assert_eq!(expand_tokens("{copyright}|{job_title}", &p, 1, 1), "© 2026 Ann Lee|Photographer"); |
| 2337 | + assert_eq!(expand_tokens("{location}|{city}|{state}|{country}", &p, 1, 1), "South Pier|Fleetwood|Lancashire|England"); |
| 2338 | + assert_eq!(expand_tokens("{serial}", &p, 1, 1), "0123456789"); |
| 2339 | + assert_eq!( |
| 2340 | + expand_tokens("{alt_text}|{extended_description}|{description_writer}", &p, 1, 1), |
| 2341 | + "A fishing boat at the pier at dawn|A red-hulled fishing boat moored at South Pier, Fleetwood, in first light.|A. Lee" |
| 2342 | + ); |
| 2343 | + // the technical tokens keep file names usable (an f/ would become a - in every name) |
| 2344 | + assert_eq!(expand_tokens("{shutter}|{aperture}|{focal}", &p, 1, 1), "1/250|8|24mm"); |
| 2345 | + let mut q = sample_photo(); |
| 2346 | + q.meta.aperture = Some(2.8); |
| 2347 | + q.meta.focal_mm = Some(24.5); |
| 2348 | + assert_eq!(expand_tokens("{aperture}|{focal}", &q, 1, 1), "2.8|24mm"); |
| 2349 | + assert_eq!(expand("SKU-{keywords}", &q, 1), "SKU-harbour dawn.CR3"); |
| 2350 | + // a field the photo doesn't have leaves an empty gap, and empty keeps the name |
| 2351 | + let mut empty = sample_photo(); |
| 2352 | + empty.meta = Default::default(); |
| 2353 | + assert_eq!(expand_tokens("{caption}|{serial}|{aperture}|{focal}", &empty, 1, 1), "|||"); |
| 2354 | + assert_eq!(expand("{caption}", &empty, 1), "IMG_0042.CR3"); |
| 2355 | + } |
| 2356 | + |
2272 | 2357 | /// `{seq:N}` pads to at most 9 digits whatever N a template asks for (a template can come from a preset file, a |
2273 | 2358 | /// script or MCP): at, just below and just above the cap, a caller width past it, and widths that would need |
2274 | 2359 | /// gigabytes. The huge widths come last, so an uncapped width fails on the small ones before allocating. |
|
0 commit comments