Improve exif metadata update functions
This commit is contained in:
parent
fed1c9c2c4
commit
d958729665
1 changed files with 38 additions and 35 deletions
73
init.el
73
init.el
|
@ -1,3 +1,5 @@
|
||||||
|
;; -*- lexical-binding: t -*-
|
||||||
|
|
||||||
;;; ~/.emacs.d/init.el --- Configuration file for Emacs
|
;;; ~/.emacs.d/init.el --- Configuration file for Emacs
|
||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
|
@ -980,42 +982,43 @@
|
||||||
:config
|
:config
|
||||||
(pdf-tools-install))
|
(pdf-tools-install))
|
||||||
|
|
||||||
(defun dl/view-exif-data (file)
|
|
||||||
"View EXIF data of FILE."
|
|
||||||
(interactive (let ((fname (thing-at-point 'existing-filename)))
|
|
||||||
(list
|
|
||||||
(read-string (format "File (%s): " (file-name-nondirectory fname))
|
|
||||||
nil nil fname))))
|
|
||||||
(let ((buf-name (concat "*EXIF " file "*")))
|
|
||||||
;; If the buffer already exists, kill it.
|
|
||||||
(when (get-buffer buf-name)
|
|
||||||
(kill-buffer buf-name))
|
|
||||||
;; Create a new buffer and window.
|
|
||||||
(let ((buf (get-buffer-create buf-name))
|
|
||||||
(window (split-window nil)))
|
|
||||||
(call-process "exiftool"
|
|
||||||
nil buf t
|
|
||||||
(expand-file-name file))
|
|
||||||
(with-current-buffer buf
|
|
||||||
(goto-char (point-min))
|
|
||||||
;; Read-only, q to close the window, C-u q to close and kill.
|
|
||||||
(special-mode))
|
|
||||||
(set-window-buffer window buf))))
|
|
||||||
|
|
||||||
(defun dl/set-exif-data (file tag-name tag-value)
|
(defun dl/edit-exif-metadata ()
|
||||||
"In FILE, set EXIF tag TAG-NAME to value TAG-VALUE."
|
"Edit the EXIF metadata of the file at point or of the current file."
|
||||||
(interactive (list (let ((fname (thing-at-point 'existing-filename)))
|
(interactive)
|
||||||
(read-string (format "File (%s): " (file-name-nondirectory fname))
|
(let* ((file (or (thing-at-point 'existing-filename) (buffer-file-name)))
|
||||||
nil nil fname))
|
(buffer (switch-to-buffer-other-window "*EXIFTool Metadata*"))
|
||||||
(read-string "Tag (Title): " nil nil "Title")
|
(metadata (with-temp-buffer
|
||||||
(read-string "Value: ")))
|
(call-process "exiftool" nil t nil file)
|
||||||
(let ((options '("-%t=%v" "-overwrite_original" "%f"))
|
(buffer-string))))
|
||||||
(spec (list
|
;; Display current metadata
|
||||||
(cons ?f (expand-file-name file))
|
(with-current-buffer buffer
|
||||||
(cons ?t tag-name)
|
(erase-buffer)
|
||||||
(cons ?v tag-value))))
|
(insert metadata)
|
||||||
(apply #'call-process "exiftool" nil nil nil
|
(goto-char (point-min))
|
||||||
(mapcar (lambda (arg) (format-spec arg spec)) options))))
|
(while (re-search-forward "\\(.*\\): \\(.*\\)" nil t)
|
||||||
|
(replace-match "\\1:\t\\2")))
|
||||||
|
(switch-to-buffer buffer)
|
||||||
|
(local-set-key (kbd "C-c C-c") (lambda ()
|
||||||
|
(interactive)
|
||||||
|
(dl/save-exif-metadata file buffer)))
|
||||||
|
(local-set-key (kbd "C-c C-k") 'kill-buffer)))
|
||||||
|
|
||||||
|
(defun dl/save-exif-metadata (file buffer)
|
||||||
|
"Save the edited EXIF metadata in BUFFER to the FILE."
|
||||||
|
(interactive)
|
||||||
|
(with-current-buffer buffer
|
||||||
|
(goto-char (point-min))
|
||||||
|
(let ((arguments '()))
|
||||||
|
(while (re-search-forward "\\(.*?\\):\\(.*\\)" nil t)
|
||||||
|
(let ((tag (string-trim (match-string 1)))
|
||||||
|
(value (string-trim (match-string 2))))
|
||||||
|
(push (format "-%s=%s" tag value) arguments)))
|
||||||
|
;; Write metadata changes to file using exiftool
|
||||||
|
(apply #'call-process
|
||||||
|
"exiftool" nil nil nil (append arguments (list "-overwrite_original" file)))
|
||||||
|
(kill-buffer)
|
||||||
|
(message "EXIF metadata updated."))))
|
||||||
|
|
||||||
(use-package nov
|
(use-package nov
|
||||||
:ensure t
|
:ensure t
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue