LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Merge main into feat/gpx-tracklog
Brandon Thomasf7361a7d0197
diff --cc crates/engine/src/cmd/manage.rsindex a538bafd9,8b9ee8a24..41b43cab9--- a/crates/engine/src/cmd/manage.rs+++ b/crates/engine/src/cmd/manage.rs@@@ -59,100 -59,12 +59,103 @@@ fn set_names_ops(s: &crate::Session, na.collect()}+/// Geotag photos from a GPX track log by capture time (Lightroom Classic's Map ▸ Tracklog ▸+/// Auto-Tag Photos). GPX times are UTC; capture times are the camera's local clock, so a photo's+/// recorded zone (Exif `OffsetTimeOriginal`) or the `offset` parameter converts them.+fn auto_tag_tracklog(s: &mut crate::Session, p: &Value) -> Result<Value> {+ use lightcraft_meta::{DateTime, Match, parse_gpx};+ const C: &str = "photo.autoTagTracklog";+ let text = match (str_param(p, "gpx"), str_param(p, "path")) {+ (Some(t), _) => t.to_string(),+ (None, Some(path)) => std::fs::read_to_string(path).map_err(|e| bad(C, format!("can't read {path}: {e}")))?,+ (None, None) => return Err(bad(C, "missing `path` (a .gpx file) or `gpx` (its text)")),+ };+ let log = parse_gpx(&text).map_err(|e| bad(C, e.to_string()))?;+ let (start, end) = log.span().ok_or_else(|| bad(C, "the track log has no timed track points"))?;+ // minutes east of UTC; `None` = not given (zone-less capture times are then read as UTC)+ let offset: Option<i64> = match p.get("offset") {+ None | Some(Value::Null) => None,+ Some(Value::String(o)) if o.trim().is_empty() => None,+ Some(Value::Number(h)) => {+ let h = h.as_f64().unwrap_or(0.0);+ if h.abs() > 18.0 {+ return Err(bad(C, "offset is at most ±18 hours"));+ }+ Some((h * 60.0).round() as i64)+ }+ Some(Value::String(o)) => {+ Some(DateTime::parse_offset(o).ok_or_else(|| bad(C, format!("can't read offset `{o}` (e.g. +02:00 or -5)")))? as i64)+ }+ Some(_) => return Err(bad(C, "offset is `+HH:MM` or a number of hours")),+ };+ let max_gap = f64_or(p, "maxGap", 600.0);+ if max_gap.is_nan() || max_gap < 0.0 {+ return Err(bad(C, "maxGap must be ≥ 0 seconds"));+ }+ let replace = bool_or(p, "replace", false);+ let (mut no_time, mut outside, mut has_gps, mut assumed_utc, mut interpolated) = (0, 0, 0, 0, 0);+ let mut ops = Vec::new();+ let mut photos = Vec::new();+ for id in s.targets(p) {+ let Some(ph) = s.catalog.photo(id) else { continue };+ if ph.meta.gps.is_some() && !replace {+ has_gps += 1;+ continue;+ }+ let Some(dt) = ph.captured.as_deref().and_then(DateTime::parse_iso) else {+ no_time += 1;+ continue;+ };+ // UTC seconds: the recorded zone wins, else the caller's offset+ let utc = match dt.offset_minutes {+ Some(_) => dt.unix_seconds(),+ None => {+ if offset.is_none() {+ assumed_utc += 1;+ }+ dt.unix_seconds() - offset.unwrap_or(0) * 60+ }+ } as f64+ + dt.millis as f64 / 1000.0;+ let Some((g, m)) = log.locate(utc, max_gap) else {+ outside += 1;+ continue;+ };+ if m == Match::Interpolated {+ interpolated += 1;+ }+ let pos = ((g.latitude * 1e7).round() / 1e7, (g.longitude * 1e7).round() / 1e7);+ photos.push(json!({"id": id.0, "gps": [pos.0, pos.1], "match": if m == Match::Interpolated { "interpolated" } else { "nearest" }}));+ if ph.meta.gps != Some(pos) {+ let mut meta = ph.meta.clone();+ meta.gps = Some(pos);+ ops.push(Op::SetMeta { id, meta: Box::new(meta) });+ }+ }+ let tagged = photos.len();+ if !bool_or(p, "dryRun", false) && !ops.is_empty() {+ s.commit("Auto-Tag from Tracklog", Op::Batch { ops })?;+ }+ let iso = |t: f64| format!("{}Z", lightcraft_catalog::dates::civil(t.floor() as i64));+ Ok(json!({+ "tagged": tagged,+ "interpolated": interpolated,+ "nearest": tagged - interpolated,+ "skipped": {"noTime": no_time, "outside": outside, "hasGps": has_gps},+ "assumedUtc": assumed_utc,+ "points": log.points.len(),+ "start": iso(start),+ "end": iso(end),+ "photos": photos,+ }))+}+pub fn specs() -> Vec<CommandSpec> {vec![- cmd!(query "photo.renamePreview", "Rename Preview", [], None, "{template: e.g. `{date}_{name}`, `Trip-{seq:3}` (tokens: {name} {num} {seq} {seq:N} {date} {date:%Y%m%d} {folder} {camera} {lens} {iso} {rating} {title} {creator} {ext}), start?: first sequence number (1), ids?} — renames the files on disk (sidecars too, never overwriting: collisions get -1, -2…); undoable", has_selection, |s, p| {+ cmd!(query "photo.renameTokens", "Rename Template Tags", [], None, "{} → {tokens: [{tag, aliases, meaning, example}], dateDirectives: [{directive, meaning}], notes: [..], sample} — the file-name template tags shared by photo.rename, library.import (rename) and app.export (naming); examples are for a sample photo", always, |_, _| {+ Ok(crate::rename::token_help_json())+ }),+ cmd!(query "photo.renamePreview", "Rename Preview", [], None, "{template: e.g. `{date}_{name}`, `Trip-{seq:3}` (tokens: {name} {num} {seq} {seq:N} {date} {date:%Y%m%d} {folder} {camera} {lens} {iso} {rating} {title} {creator} {ext}; photo.renameTokens explains each), start?: first sequence number (1), ids?} — renames the files on disk (sidecars too, never overwriting: collisions get -1, -2…); undoable", has_selection, |s, p| {let (ids, template, start) = rename_args(s, p, "photo.renamePreview")?;Ok(serde_json::to_value(s.plan_rename(&ids, &template, start)).unwrap_or_default())}),diff --cc docs/parity.mdindex 7e6e55551,4b6abd691..e83448642--- a/docs/parity.md+++ b/docs/parity.md@@@ -44,13 -44,13 +44,13 @@@ and prints the summary; `cargo xtask pa| U. Map & location (MAP) | 0 | 1 | 1 | 0 | — | 0/1 (0%) || V. Preferences (PREF) | 5 | 0 | 3 | 3 | 1/1 (100%) | 4/4 (100%) || W. Cloud & AI infrastructure (CLOUD / AI) | 1 | 0 | 1 | 2 | — | — |- | X. Cross-cutting behaviours (BEHAV) | 14 | 1 | 2 | 1 | 8/8 (100%) | 5/5 (100%) |+ | X. Cross-cutting behaviours (BEHAV) | 15 | 1 | 2 | 1 | 8/8 (100%) | 6/6 (100%) || Y. Menus | 81 | 0 | 4 | 8 | 47/47 (100%) | 23/23 (100%) || Z. Keyboard shortcuts (desktop) | 74 | 3 | 3 | 1 | 49/52 (94%) | 22/23 (96%) |-| Lightroom Classic extras | 29 | 9 | 41 | 9 | — | 20/21 (95%) |-| **Total** | 384 | 25 | 92 | 37 | 194/198 (98%) | 137/145 (94%) |+| Lightroom Classic extras | 30 | 9 | 40 | 9 | — | 20/21 (95%) |- | **Total** | 384 | 25 | 91 | 37 | 194/198 (98%) | 136/144 (94%) |++| **Total** | 385 | 25 | 91 | 37 | 194/198 (98%) | 137/145 (94%) |- Weighted completion (✅ = 1, 🟡 = ½, 🚫 left out): **79.3%** of 500 in-scope rows — P0 99.0% of 198 · P1 96.2% of 144 · P2 39.2% of 158.-Weighted completion (✅ = 1, 🟡 = ½, 🚫 left out): **79.1%** of 501 in-scope rows — P0 99.0% of 198 · P1 96.2% of 145 · P2 38.6% of 158.++Weighted completion (✅ = 1, 🟡 = ½, 🚫 left out): **79.3%** of 501 in-scope rows — P0 99.0% of 198 · P1 96.2% of 145 · P2 39.2% of 158.<!-- /parity:summary -->## Top gapsdiff --cc docs/whats-new.mdindex cd5558480,fff4e9e72..1657c786a--- a/docs/whats-new.md+++ b/docs/whats-new.md@@@ -16,7 -16,7 +16,8 @@@- Import: copy to any folder, by day / by month / one folder, rename on import, metadata preset, Copy as DNG.- Watched-folder auto import; Convert to DNG; Duplicate; Build Standard / 1:1 / Smart Previews.- Export file names use the Rename Photos tokens ({title}, {seq:2}, {date:%Y-%m-%d}…), plus new {num}, {folder}, {lens}, {iso}, {rating}, {creator}.+ - Copyright status, rights usage terms and copyright info URL in Info, metadata presets and exports.+- Auto-Tag from Tracklog: GPS locations for your photos from a GPX track log, matched by capture time.### Editing- Auto Sync: edits apply to every selected photo. Auto B&W mix. Automatic versions.