emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/calibre 472fb38333 06/11: Factor out JSON parsing in ca


From: ELPA Syncer
Subject: [elpa] externals/calibre 472fb38333 06/11: Factor out JSON parsing in calibre-cli
Date: Sat, 20 May 2023 19:57:31 -0400 (EDT)

branch: externals/calibre
commit 472fb38333788474869461590424d27659fd46c9
Author: Kjartan Óli Ágústsson <kjartanoli@disroot.org>
Commit: Kjartan Óli Ágústsson <kjartanoli@disroot.org>

    Factor out JSON parsing in calibre-cli
    
    * calibre-cli.el (calibre-cli--list): Add function to parse JSON.
    (calibre-cli--get-books): Use calibre-cli--list to get book data.
---
 calibre-cli.el | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/calibre-cli.el b/calibre-cli.el
index 564736dc75..665f141594 100644
--- a/calibre-cli.el
+++ b/calibre-cli.el
@@ -28,22 +28,29 @@
 (require 'calibre-book)
 (require 'calibre-util)
 
+(defun calibre-cli--list (&rest fields)
+  "List books in the active library.
+If FIELDS is a list of metadata fields to list, if none are
+specified the default is 'all'."
+  (with-temp-buffer
+    (apply #'call-process
+           `(,calibre-calibredb-executable
+             nil
+             t
+             nil
+             "--with-library"
+             ,(calibre--library)
+             "list"
+             ,@(if fields
+                (flatten-list (mapcar (lambda (f) `("-f" ,f)) fields))
+                '("-f" "all"))
+             "--for-machine"))
+    (goto-char (point-min))
+    (json-parse-buffer :object-type 'alist :array-type 'list)))
+
 (defun calibre-cli--get-books ()
   "Return all books in the Calibre library `calibre-library-dir'."
-  (let ((json (with-temp-buffer
-                (call-process calibre-calibredb-executable
-                              nil
-                              t
-                              nil
-                              "list"
-                              "--with-library"
-                              (calibre--library)
-                              "-f"
-                              "all"
-                              "--for-machine")
-                (goto-char (point-min))
-                (json-parse-buffer :object-type 'alist :array-type 'list))))
-    (mapcar #'calibre-cli--make-book json)))
+  (mapcar #'calibre-cli--make-book (calibre-cli--list)))
 
 (defun calibre-cli--make-book (json)
   "Make a `calibre-book' from JSON."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]