How I manage documents if all of them in one flat folder using calibredb.el

You may not know: there is one type of metadata in Calibre, called folder metadata. It is also be used in elink device if you use calibre to transfer files to elink device. A hidden file named .metadata.calibre.

Unlike the original database metadata.db, metadata needs ebooks be resided inside a non-flat folder, while the .metadata.calibre is a json file, and it has all the metadata for all documents/ebooks under one flat folder.

Therefore, by parsing .metadata.calibre, we can manage all documents inside one flat folder using calibredb.el - The documents management software inside Emacs. What amazing thing is that, after generating the folder meatadata, calibredb.el can smartly filter metadata with live filter feature without using calibre or other calibre command lines, making it also be able to manage ebooks inside Android Emacs where it is unable to install calibre on Termux at this moment.

Install or update calibredb.el to the latest version.

Generate the folder metadata: .metadata.calibre

Launch calibre, Connect/Share, Connect to folder, then .metadata.calibre was generated in that folder, finally you can close calibre.

Config calibredb.el

There is only three things to configure, that is setup calibredb-root-dir to point to the document folder, calibredb-db-dir points to the .metadata.calibre. and calibredb-library-alist holds all libraries.

Here are the examples showing that I have added many different libraries (for example, I sometimes download files from Telegram and switch to emacs to read them, so it worths as a single library). You can add as many as you want! Don’t limit to only one library!

(setq calibredb-root-dir "/home/damonchan/Data/Books/")
(setq calibredb-db-dir (expand-file-name ".metadata.calibre" calibredb-root-dir))
(setq calibredb-library-alist `((,calibredb-root-dir)
                                  ;; Ebooks
                                  (,(pcase system-type
                                      ('gnu/linux
                                       (expand-file-name "~/Data/Ebooks/Calibre"))
                                      ('darwin
                                       (expand-file-name "~/Ebooks/Calibre"))))
                                  (,(expand-file-name "web_doc" org-directory))
                                  ;; telegram folder
                                  (,(pcase system-type
                                      ('gnu/linux
                                       (expand-file-name "~/Downloads/Telegram Desktop"))
                                      ('darwin
                                       (expand-file-name "~/Downloads/Telegram Desktop"))
                                      ('android
                                       (expand-file-name "/storage/emulated/0/Download/Telegram/"))))
                                  ;; opds
                                  ("http://arxiv.maplepop.com/catalog/")
                                  ("https://m.gutenberg.org/ebooks.opds/")
                                  ("http://aozora.textlive.net/catalog.opds")
                                  ("https://opds.wol.moe/zh_CN")
                                  ("http://opds.chaoxing.com/")))

Run calibredb.el

1
M-x cabliredb

Do live search with /, enter to open the file, press . to open dired, N or P switch between libraries.

Demo

PS:

  1. When you view the metadata detail (either calibredb-view or calibredb-toggle-view-at-point), the cover page will be extracted from the file and save as {filename}.jpg in the same folder. If you run calibredb-toggle-view, cover pages are extracted from all files in the library. It takes time if library is big, but it only execute once.
  2. Please notice that not all features designed for calibredb metadata database are usable. It is still under development. If you need to add or delete file, you need to generate the .metadata.calibre using calibre again to refresh the metadata. Because calibredb.el is not able to generate .metadata.calibre at this moment.

Bonus Tip

I love flat folder, so that I can use paw.el to manage ebooks annotations across devices (android and desktop).

Enjoy

updatedupdated2025-02-152025-02-15