[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."
- [elpa] externals/calibre 41263e2820 08/11: Fix byte compiler warnings, (continued)
- [elpa] externals/calibre 41263e2820 08/11: Fix byte compiler warnings, ELPA Syncer, 2023/05/20
- [elpa] externals/calibre 436e70ac13 09/11: Fix docstring quoting, ELPA Syncer, 2023/05/20
- [elpa] externals/calibre ad65bf9b51 11/11: Bump package version to 1.3.3, ELPA Syncer, 2023/05/20
- [elpa] externals/calibre 3fa7d264da 03/11: Use constant instead of magic value, ELPA Syncer, 2023/05/20
- [elpa] externals/calibre e0f6e49316 04/11: Add missing search function to calibre-cli, ELPA Syncer, 2023/05/20
- [elpa] externals/calibre 67b7386841 07/11: Move functions from calibre-core to calibre-cli, ELPA Syncer, 2023/05/20
- [elpa] externals/calibre 6ff78d6eca 05/11: Use correct author separator in calibre-cli, ELPA Syncer, 2023/05/20
- [elpa] externals/calibre 503e175c54 02/11: Document internal variables, ELPA Syncer, 2023/05/20
- [elpa] externals/calibre d7dd1f4d70 01/11: Fix copyright header, ELPA Syncer, 2023/05/20
- [elpa] externals/calibre 49f05eedc0 10/11: Remove second definition of calibre-series widget, ELPA Syncer, 2023/05/20
- [elpa] externals/calibre 472fb38333 06/11: Factor out JSON parsing in calibre-cli,
ELPA Syncer <=