aboutsummaryrefslogtreecommitdiffstats
path: root/lib/data.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lib/data.lua')
-rw-r--r--lib/data.lua37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/data.lua b/lib/data.lua
index 8e60d6d..1173fce 100644
--- a/lib/data.lua
+++ b/lib/data.lua
@@ -591,4 +591,41 @@ function M.breaktimer_parse(text)
return out
end
+-- The Immich memories index written by bin/immich-fetch.sh.
+--
+-- Returns a list of { id, year, taken = { y, m, d, H, M }, place }, plus
+-- .url, the server's address for a click-through, or nil when
+-- the index is absent or carries no 'generated' key. nil means "the fetch never
+-- ran"; an empty list means "no memories today", which the card names
+-- differently. `place` is nil when the key lacks asset.read or the photo has no
+-- location, so the card can print '--'.
+function M.immich_parse(text)
+ if type(text) ~= 'string' then return nil end
+ local out, generated = {}, false
+ for line in text:gmatch('[^\n]+') do
+ local kind, rest = line:match('^(%S+)%s+(.*)$')
+ if kind == 'generated' then
+ generated = true
+ elseif kind == 'url' then
+ out.url = rest
+ elseif kind == 'photo' then
+ -- The place is last and takes the rest of the line, so a pipe in a
+ -- place name cannot shift a field.
+ local id, year, taken, place = rest:match('^([^|]+)|(%d*)|([^|]*)|(.*)$')
+ if id then
+ local y, m, d, H, Mi = taken:match('^(%d+)-(%d+)-(%d+)T(%d+):(%d+)')
+ out[#out + 1] = {
+ id = id,
+ year = tonumber(year),
+ taken = y and { tonumber(y), tonumber(m), tonumber(d),
+ tonumber(H), tonumber(Mi) } or nil,
+ place = place ~= '' and place or nil,
+ }
+ end
+ end
+ end
+ if not generated then return nil end
+ return out
+end
+
return M