From acabf69a93468fb01fbbf62e1ba96819a1d51c53 Mon Sep 17 00:00:00 2001 From: nixo Date: Sat, 12 Jan 2019 22:55:18 +0100 Subject: [PATCH] init photo --- photo.scm | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 photo.scm diff --git a/photo.scm b/photo.scm new file mode 100644 index 0000000..7773522 --- /dev/null +++ b/photo.scm @@ -0,0 +1,113 @@ +(use-modules (srfi srfi-19)) ; string/date +(use-modules (ice-9 ftw)) +(use-modules (ice-9 format)) +(use-modules (ice-9 popen)) +(use-modules (ice-9 rdelim)) +(use-modules (ice-9 textual-ports)) ; put-string + +(getcwd) +(chdir "/home/nixo/memories/inbox/photos/moto/Camera") + +(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") + ))) + +(system "ls") + + +;; +(define (date->org date show-time active) + (let* ((brackets (if active '("<" ">") + '( "[" "]"))) + (format (string-append (car brackets) "~Y-~m-~d ~a")) + (format (if show-time + (string-append format " ~H:~M") + format))) + (date->string date (string-append format (car (cdr brackets)))))) + +(define (link->org lnk description replacespaces) + (let* ((lnk (if replacespaces + (regexp-substitute/global #f "[ \t]+" lnk + 'pre "%20" 'post) + lnk)) + (output (if description + (string-concatenate `("[[" ,lnk + "][" ,description + "]]")) + (string-concatenate `("[[" ,lnk + "]]"))))) + output)) + +(define (make-org-pair p) + (string-concatenate `(,(car p) ":" ,(cadr p)))) + +(define (format-properties props) + (string-join + (map (lambda (x) (make-org-pair x)) props) + "\n")) + +(define (create-uuid props) "UUID") + +(define (org-properties props) + (let ((id (create-uuid props))) + (string-concatenate + `( + ":PROPERTIES:\n" + ,(format-properties props) + ":ID:" ,id "\n" + ":END:\n")))) + +(define (image->org filename) + (string-concatenate `("* " + ,(date->org (get-creation filename) #t #t) " " + ,(link->org (canonicalize-path filename) + filename #t) + "\n" + ,(org-properties `(("FILENAME" ,filename)))))) + + + +(use-modules (ice-9 match)) +(define remove-stat + (match-lambda + ((name stat) ; flat file + name) + ((name stat children ...) ; directory + (list name (map remove-stat children))))) + +(define image-exts '("jpg" "jpeg" "png")) + +;; (make-regexp "\.png" regexp/icase) + +;; (map image-exts) +;; (map (lambda (ext) (string-match filename) +;; (string-contains-ci "test.png" ext)) image-exts) + +;; (define (image? filename) +;; (map (lambda (ext) (string-contains-ci filename ext)) image-exts) +;; ) + +;; (filter! image? (cadr (remove-stat (file-system-tree ".")))) + +;; (let ((dir ".")) +;; (remove-stat )) + +(let ((output (open-file "example.org" "a"))) + (put-string output (image->org "IMG_20180520_230823.jpg")) + (close-port output)) + + +;; (image-dir->org ".") + + + + +;; timestamp = OrgFormat.datetime(datetime) +;; output = OrgFormat.link(filename, photo_file) +;; properties = OrgProperties(photo_file + timestamp)