[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/calibre 0e7221461b 62/76: Add ability to use CLI interf
From: |
ELPA Syncer |
Subject: |
[elpa] externals/calibre 0e7221461b 62/76: Add ability to use CLI interface instead of SQLite |
Date: |
Thu, 18 May 2023 09:57:46 -0400 (EDT) |
branch: externals/calibre
commit 0e7221461be77e866fc21ec53f2f7e68bd64d7ee
Author: Kjartan Óli Ágústsson <kjartanoli@disroot.org>
Commit: Kjartan Óli Ágústsson <kjartanoli@disroot.org>
Add ability to use CLI interface instead of SQLite
* calibre-cli.el:
(calibre-cli--get-books):
(calibre-cli--make-book):
(calibre-cli--parse-authors):
(calibre-cli--parse-timestamp):
(calibre-cli--parse-formats):
(calibre-cli--parse-path):
(calibre-cli--parse-file-name):
(calibre-cli--search-operation):
(calibre-cli--get-series-books):
(calibre-cli--get-publisher-books):
(calibre-cli--get-format-books):
(calibre-cli--get-tag-books):
(calibre-cli--get-author-books):
(calibre-cli--get-calibre-cli-books):
Create.
---
calibre-cli.el | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 114 insertions(+)
diff --git a/calibre-cli.el b/calibre-cli.el
new file mode 100644
index 0000000000..2ec96fc128
--- /dev/null
+++ b/calibre-cli.el
@@ -0,0 +1,114 @@
+;;; calibre-cli.el --- Fallback CLI interface when SQLite is not available
-*- lexical-binding: t; -*-
+
+;; Copyright (C) 2023 Kjartan Oli Agustsson
+
+;; This file is part of calibre.el.
+
+;; calibre.el is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; calibre.el is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with calibre.el. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+;; This file contains an interface to calibre using calibredb and JSON
+;; parsing instead of SQLite. This interface is significantly slower
+;; than the SQLite interface, and should therefore only be used when
+;; SQLite support is not available.
+
+;;; Code:
+(require 'calibre)
+(require 'calibre-book)
+(require 'calibre-util)
+
+(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)))
+
+(defun calibre-cli--make-book (json)
+ "Make a `calibre-book' from JSON."
+ (let-alist json
+ (calibre-book :id .id
+ :title .title
+ :authors (calibre-cli--parse-authors .authors)
+ :publisher .publisher
+ :series .series
+ :series-index .series_index
+ :timestamp (calibre-cli--parse-timestamp .timestamp)
+ :pubdate (calibre-cli--parse-timestamp .pubdate)
+ :last-modified (calibre-cli--parse-timestamp .last_modified)
+ :tags .tags
+ :formats (calibre-cli--parse-formats .formats)
+ :path (calibre-cli--parse-path .formats)
+ :file-name (calibre-cli--parse-file-name .formats))))
+
+(defun calibre-cli--parse-authors (authors)
+ "Parse AUTHORS a string, into a list of authors.
+AUTHORS should be a comma separated string."
+ (string-split authors ","))
+
+(defun calibre-cli--parse-timestamp (timestamp)
+ "Parse TIMESTAMP into a Lisp timestamp."
+ (iso8601-parse timestamp))
+
+(defun calibre-cli--parse-formats (files)
+ "Return the formats of the book whose files are FILES."
+ (mapcar (lambda (f)
+ (intern (file-name-extension f)))
+ files))
+
+(defun calibre-cli--parse-path (files)
+ "Return the path within the library of the book whose files are FILES."
+ (string-replace (calibre--library)
+ ""
+ (file-name-directory (car files))))
+
+(defun calibre-cli--parse-file-name (files)
+ "Return the File Name of the book whose files are FILES."
+ (file-name-base (car files)))
+
+(defmacro calibre-cli--search-operation (field)
+ "Create a function to search for books matching FIELD."
+ `(defun ,(intern (format "calibre-cli--get-%s-books" field)) (,field)
+ (with-temp-buffer
+ (call-process calibre-calibredb-executable
+ nil
+ t
+ nil
+ "search"
+ "--with-library"
+ (calibre--library)
+ (format ,(format "%s:%%s" field) ,field))
+ (mapcar #'cl-parse-integer
+ (string-split
+ (buffer-substring-no-properties (point-min) (point-max))
+ ",")))))
+
+(calibre-cli--search-operation series)
+(calibre-cli--search-operation publisher)
+(calibre-cli--search-operation format)
+(calibre-cli--search-operation tag)
+(calibre-cli--search-operation author)
+
+(provide 'calibre-cli)
+;;; calibre-cli.el ends here
- [elpa] externals/calibre 6a7a2344c1 41/76: Initialise tabulated list header, (continued)
- [elpa] externals/calibre 6a7a2344c1 41/76: Initialise tabulated list header, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre 5d49526414 42/76: Add support for search and virtual libraries, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre afe5581b7d 43/76: Only prompt to select library if more than one is defined, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre 22ccc6ff2b 38/76: Fix byte compiler warning, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre abad9116cb 08/76: Correct function name, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre 761f35b771 10/76: Remove dead code, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre edb81a3d01 52/76: Add some utility functions, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre 4b6af65d08 58/76: Support editing book metadata, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre ac4c02aeb9 47/76: Add support for composite filters, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre 187685e08e 70/76: Use cond instead of cl-case, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre 0e7221461b 62/76: Add ability to use CLI interface instead of SQLite,
ELPA Syncer <=
- [elpa] externals/calibre 13141efce4 67/76: Bump package version, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre 3a7abbee56 64/76: Use compat to lower required Emacs version, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre 090b28d6ec 69/76: Use int-to-string instead of format, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre fd949f1813 72/76: Set name of calibre-library-mode, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre 8560bbd48b 75/76: Sort in ascending order by series index, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre dc4b5f79ac 11/76: Add commentary, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre 7d97c360f1 15/76: Update package version to 1.0, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre 38e0beb840 03/76: Get publishers, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre 188a3da504 04/76: Add functions to add and remove books, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre 393ae4a945 12/76: Add force option to library refresh, ELPA Syncer, 2023/05/18