From 25aff490d739290602b28bdc53936dd3ea6ed939 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 17 Jun 2026 21:35:21 +0300 Subject: mn0 share camera Make+Model dedup helper The rule that joins a camera's EXIF Make + Model into one label while avoiding a duplicated manufacturer prefix (e.g. "Canon Canon EOS 5D" -> "Canon EOS 5D") was implemented independently in the album tooltip builder and the stats leaderboard tally. Extract it into a single shared helper camera_label_from_make_model in the new src/lib/metadata-label.source.sh, sourced before both callers. Both prior implementations were behavior-identical (empty model -> make, empty make -> model, exact/prefix dedup, case-sensitive), so this is a pure DRY refactor with no observable output change. Added a focused unit test covering dedup, plain concatenation and the empty-field edge cases. Co-Authored-By: Claude Opus 4.8 --- src/lib/metadata-label.source.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/lib/metadata-label.source.sh (limited to 'src/lib/metadata-label.source.sh') diff --git a/src/lib/metadata-label.source.sh b/src/lib/metadata-label.source.sh new file mode 100644 index 0000000..4d36b3c --- /dev/null +++ b/src/lib/metadata-label.source.sh @@ -0,0 +1,31 @@ +# Shared EXIF metadata label helpers. Extracted (task mn0) so the rule for +# turning a camera's Make + Model into one human-readable label lives in a +# single place instead of being duplicated in album-metadata.source.sh's +# tooltip builder and stats-aggregate.source.sh's leaderboard tally. This file +# is sourced before both callers (see LIB_SOURCES in the Justfile). All library +# modules are sourced before any code runs, so definition order only documents +# the dependency, it does not affect availability. + +# Join a camera's EXIF Make + Model into one label, avoiding a duplicated +# manufacturer prefix. Many cameras already repeat the make inside the model +# (e.g. Make="Canon", Model="Canon EOS 5D"), so when the model equals the make +# or starts with " " we keep the model alone ("Canon EOS 5D" rather than +# "Canon Canon EOS 5D"). Either field may be empty: an empty model yields the +# make, an empty make yields the model, and both empty yields an empty string. +camera_label_from_make_model() { + local -r make="$1"; shift + local -r model="$1"; shift + + if [ -z "$model" ]; then + printf '%s' "$make" + return + fi + if [ -z "$make" ]; then + printf '%s' "$model" + return + fi + case "$model" in + "$make"|"$make "*) printf '%s' "$model" ;; + *) printf '%s %s' "$make" "$model" ;; + esac +} -- cgit v1.2.3