aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/card.lua1
-rw-r--r--lib/data.lua37
2 files changed, 38 insertions, 0 deletions
diff --git a/lib/card.lua b/lib/card.lua
index e3cb11e..2313141 100644
--- a/lib/card.lua
+++ b/lib/card.lua
@@ -132,6 +132,7 @@ M.ICON = {
slackware = '\u{F318}', -- linux-slackware
breaktimer = '\u{F13AB}', -- timer
calendar = '\u{F0E17}', -- calendar-month
+ immich = '\u{F02F9}', -- image-multiple
}
-- The gap between a title's icon and its text. One constant so the measured
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