branch: externals/calibre
commit f70ea99968cd2d040bcfae828088c4bf4a631edf
Author: Kjartan Oli Agustsson <[email protected]>
Commit: Kjartan Oli Agustsson <[email protected]>
Add book summary as a metadata field
* calibre-book.el (calibre-book): Add new field summary.
* calibre-cli.el (calibre-cli--make-book): Extract the summary out of
the JSON data.
* calibre-core.el (calibre-library-columns): Add a option to display a
book's summary.
(calibre-library--header-format): Add a case to handle the summary field.
(calibre-book--print-info): Add a case to handle the summary field.
* calibre-db.el (calibre-db--make-book): Extract the new summary field
from ENTRY and pass it to make-calibre-book.
(calibre-db--get-books): Get the books summary from the DB.
* doc/calibre.texi (Viewing your library): Document the new field.
---
calibre-book.el | 5 ++++-
calibre-cli.el | 3 ++-
calibre-core.el | 9 ++++++---
calibre-db.el | 30 +++++++++++++++++++++++++-----
doc/calibre.texi | 4 ++++
5 files changed, 41 insertions(+), 10 deletions(-)
diff --git a/calibre-book.el b/calibre-book.el
index bf4080bd88..f9b96b1857 100644
--- a/calibre-book.el
+++ b/calibre-book.el
@@ -68,7 +68,10 @@
:documentation "The book's position within the library")
(file-name nil
:type string
- :documentation "The book's filename, sans extension."))
+ :documentation "The book's filename, sans extension.")
+ (summary nil
+ :type (or string null)
+ :documentation "The book's summary."))
(defcustom calibre-format-preferences '(pdf epub)
"The preference order of file formats."
diff --git a/calibre-cli.el b/calibre-cli.el
index c074519acc..da19c5c58e 100644
--- a/calibre-cli.el
+++ b/calibre-cli.el
@@ -70,7 +70,8 @@ specified the default is \\='all\\='."
:tags (sort .tags)
:formats (calibre-cli--parse-formats .formats)
:path (calibre-cli--parse-path .formats)
- :file-name (calibre-cli--parse-file-name .formats))))
+ :file-name (calibre-cli--parse-file-name .formats)
+ :summary .comments)))
(defun calibre-cli--parse-authors (authors)
"Parse AUTHORS a string, into a list of authors.
diff --git a/calibre-core.el b/calibre-core.el
index b9b7cb8518..14be43a68b 100644
--- a/calibre-core.el
+++ b/calibre-core.el
@@ -136,7 +136,8 @@ column should have."
(const :tag "Series Index" series-index)
(const :tag "Tags" tags)
(const :tag "Formats" formats)
- (const :tag "Publication date" pubdate))
+ (const :tag "Publication date" pubdate)
+ (const :tag "Summary" summary))
(integer :tag "Width")))
:set (lambda (symbol value)
(set-default symbol value)
@@ -173,7 +174,8 @@ with values determined by `calibre-library-columns'."
(formats `("Formats" ,width))
(pubdate `("Publication Date" ,width (lambda (a b)
(time-less-p
(calibre-book-pubdate (car a))
-
(calibre-book-pubdate (car b)))))))))
+
(calibre-book-pubdate (car b))))))
+ (summary `("Summary" ,width)))))
calibre-library-columns)))
(defun calibre-book--print-info (book)
@@ -194,7 +196,8 @@ BOOK is a `calibre-book'."
(formats (string-join (mapcar (lambda (f)
(upcase (symbol-name f))) (calibre-book-formats book)) ", "))
(pubdate (if (calibre-book-pubdate book)
(format-time-string
calibre-library-time-format (calibre-book-pubdate book))
- "Invalid")))))
+ "Invalid"))
+ (summary (or (calibre-book-summary book) "")))))
calibre-library-columns))))
(defun calibre-book--file (book format)
diff --git a/calibre-db.el b/calibre-db.el
index 740cea71b0..696f5f601d 100644
--- a/calibre-db.el
+++ b/calibre-db.el
@@ -39,8 +39,18 @@ TIMESTAMP is a string of the form YYYY-MM-DD
HH:MM:SS.xxxxxx+00:00."
(defun calibre-db--make-book (entry)
"Create a `calibre-book' from ENTRY.
ENTRY is a list of the form:
-\(ID TITLE SERIES SERIES-INDEX TIMESTAMP PUBDATE LAST-MODIFIED)."
- (seq-let [id title series series-index timestamp pubdate last-modified path]
entry
+\(ID TITLE SERIES SERIES-INDEX TIMESTAMP PUBDATE LAST-MODIFIED PATH SUMMARY)."
+ (seq-let
+ [id
+ title
+ series
+ series-index
+ timestamp
+ pubdate
+ last-modified
+ path
+ summary]
+ entry
(make-calibre-book :id id
:title title
:authors (calibre-db--get-book-authors id)
@@ -53,7 +63,8 @@ ENTRY is a list of the form:
:tags (sort (calibre-db--get-book-tags id))
:formats (calibre-db--get-book-formats id)
:path path
- :file-name (calibre-db--get-book-file-name id))))
+ :file-name (calibre-db--get-book-file-name id)
+ :summary summary)))
(defun calibre-db--get-book-authors (id)
"Return a list of authors for the book identified by ID."
@@ -146,10 +157,19 @@ WHERE books.id = ?"
nil
(mapcar #'calibre-db--make-book
(sqlite-select (calibre--db)
- "SELECT books.id, title, series.name, series_index,
timestamp, pubdate, last_modified, path
+ "SELECT
+ books.id, title,
+ series.name,
+ series_index,
+ timestamp,
+ pubdate,
+ last_modified,
+ path,
+ comments.text
FROM books
LEFT JOIN books_series_link sl ON books.id = sl.book
-LEFT JOIN series ON sl.series = series.id;"))))
+LEFT JOIN series ON sl.series = series.id
+LEFT JOIN comments ON books.id = comments.book;"))))
(defmacro calibre-db--query (query arg fuzzy)
"Run QUERY on the Calibre database.
diff --git a/doc/calibre.texi b/doc/calibre.texi
index 8a1ed4ba44..56794d3806 100644
--- a/doc/calibre.texi
+++ b/doc/calibre.texi
@@ -98,6 +98,10 @@ The formats the book is available in within the library.
@item pubdate
The book's date of publication.@footnote{To change how this is displayed
customize @code{calibre-library-time-format.}}
+@item summary
+The book's summary.@footnote{This field is likely to contain large
+amounts of text which are not well suited to display in the
+@file{*Library*} buffer.}
@end table
@var{WIDTH} is an integer specifying the number of characters the
corresponding column should take in the @file{*Library*} buffer.