summaryrefslogtreecommitdiff
path: root/src/lib/stats-aggregate.source.sh
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-06-24 10:36:25 +0300
committerPaul Buetow <paul@buetow.org>2026-06-24 10:36:25 +0300
commit6dfc0f1a9521cc4afe4941fc1328eec014b760a7 (patch)
tree4303307c104aa9dbe84e906eb9c0f1dd279469d9 /src/lib/stats-aggregate.source.sh
parent99c5241d853daceb8cfaec91023730ff062858b7 (diff)
Promote single canonical identify-stream EXIF parser into metadata-cache (8r0)
The `identify -verbose` EXIF-line regex and its array-fill loop were duplicated in three places that had already drifted: album-metadata's photo_exif_details_html and _photo_exif_values_to (exif: only) and stats-aggregate's _stats_parse_identify_stream (exif: plus a native Geometry -> __geometry path). Promote one canonical parser, photo_exif_values_to, into metadata-cache.source.sh next to its sibling cache primitive cached_photo_identify_output. It reads an identify stream from stdin and fills a nameref associative array; it is a strict superset of all three former sites (bare exif: tag keys plus the synthetic __geometry key). - stats accumulate_photo_stats now calls photo_exif_values_to (stdin); _stats_parse_identify_stream is removed. - album _photo_exif_values_to is a thin wrapper that pipes cached_photo_identify_output through the canonical parser. - album photo_exif_details_html consumes the same parser and skips the __geometry key it does not display. metadata-cache is sourced before both consumers in LIB_SOURCES, so the canonical parser is available at use time. Regenerated bin/shuriken via `just build`. Added test_shared_identify_parser_returns_exif_and_geometry asserting one parse yields both an exif: key and __geometry. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'src/lib/stats-aggregate.source.sh')
-rw-r--r--src/lib/stats-aggregate.source.sh28
1 files changed, 7 insertions, 21 deletions
diff --git a/src/lib/stats-aggregate.source.sh b/src/lib/stats-aggregate.source.sh
index 6b30f62..77603c5 100644
--- a/src/lib/stats-aggregate.source.sh
+++ b/src/lib/stats-aggregate.source.sh
@@ -499,8 +499,8 @@ _stats_record_enums() {
# Record dimension stats (megapixels, aspect ratio, orientation) from the native
# Geometry field. Geometry is "WxH+x+y"; the leading WxH is what we need. These
-# are native fields, not exif: lines, so they come from the separate native
-# parser path in _stats_parse_identify_stream.
+# are native fields, not exif: lines, so they come from the native Geometry
+# (__geometry) path in the shared photo_exif_values_to parser.
_stats_record_dimensions() {
local -n values_ref="$1"; shift
local -r photo="$1"; shift
@@ -618,24 +618,6 @@ _stats_tally() {
fi
}
-# Parse one photo's `identify -verbose` stream into an associative array. The
-# current album.source.sh regex only captures exif: lines, but the audit needs
-# the native Geometry field for dimensions, so this adds a second match path
-# storing it under the synthetic key __geometry.
-_stats_parse_identify_stream() {
- local -n values_ref="$1"; shift
- local line
-
- values_ref=()
- while IFS= read -r line; do
- if [[ "$line" =~ ^[[:space:]]*exif:([^:]+):[[:space:]]*(.*)$ ]]; then
- values_ref["${BASH_REMATCH[1]}"]="${BASH_REMATCH[2]}"
- elif [[ "$line" =~ ^[[:space:]]*Geometry:[[:space:]]*(.*)$ ]]; then
- values_ref[__geometry]="${BASH_REMATCH[1]}"
- fi
- done
-}
-
# Aggregate a single photo: parse its identify stream (from stdin) and update
# every counter. Split out from collect_photo_exif_stats so tests can feed a
# synthetic fixture without stubbing the cache layer.
@@ -646,7 +628,11 @@ accumulate_photo_stats() {
local -A exif_values=()
local record_fn
- _stats_parse_identify_stream exif_values
+ # Parse the identify stream from stdin via the single canonical parser
+ # (photo_exif_values_to, promoted to metadata-cache.source.sh in task 8r0).
+ # It captures both exif: tags and the native Geometry line under __geometry,
+ # which _stats_record_dimensions consumes.
+ photo_exif_values_to exif_values
STATS_TOTALS[photos]=$(( STATS_TOTALS[photos] + 1 ))
# Dispatch the EXIF-driven recorders from the registry list so categories are
# not hardcoded here. Each takes the parsed values array plus the photo path.