gemacs/importers/photo.scm

38 lines
1.1 KiB
Scheme

(define-module (importers photo)
#:use-module (ice-9 popen)
#:use-module (ice-9 format)
#:use-module (ice-9 rdelim)
#:use-module (org format)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-19)
#:export (image->org
get-creation
*move-files*))
(define *move-files* #f)
;; implementation
(define (get-creation filename)
(if (access? filename R_OK)
(let* ((port (open-input-pipe
;; FIXME: add "datetimeoriginal" as another option
(string-join
`("exiftool" "-T" "-createdate" ,filename) " ")))
(str (read-line port)))
(close-pipe port)
(string->date str "~Y:~m:~d ~H:~M:~S"))))
(define (image->org filename)
(string-concatenate `("* "
,(date->org (get-creation filename) #t #t) " "
,(link->org (canonicalize-path filename)
;; TODO: an option could remove
;; the file extension
(basename filename) #f)
"\n"
,(org-properties `(("FILENAME" ,filename))))))
;; timestamp = OrgFormat.datetime(datetime)
;; output = OrgFormat.link(filename, photo_file)
;; properties = OrgProperties(photo_file + timestamp)