Beta. Books & Shelves is not released yet. These pages describe the build in progress.
Read books from your plugin
Find Books & Shelves from another plugin and read its book list, shelves and book files.
Other plugins read books through a small API, reached the way plugins reach Model Hub. Clusters uses it for collections of books.
Before you start
- The API's types aren't published as a package yet. Until they are, copy
books-and-shelves-api.d.tsinto your plugin: it is every public declaration in one file.getBooksandonBooksReadyare a few lines each; copy them fromapi/index.ts. - The full reference is generated from the code: the API reference.
Steps
-
Find the plugin.
getBookschecks that Books & Shelves is installed and new enough. If not, it gives a plain message to show the user.const found = getBooks(this.app, '0.1.0'); if (!found.books) return new Notice(found.message); const books = found.books; -
Read a shelf and its books.
const ids = await books.shelfMembers('field-guides'); // a shelf's Calibre ids const list = await books.listBooks(ids); // id, title, authors, formats, notePath -
Read a book's file or text.
const epub = await books.bookFile(list[0].id, 'EPUB'); // bytes, through the Content Server const text = await books.pdfText(list[0].id); // a PDF's text -
Offer a conversion. A book that has only AZW3 or MOBI has no EPUB to read. With
convert: truethe user is asked; on yes, Calibre adds an EPUB. It resolvesnullif they decline.const epub = await books.bookFile(id, 'EPUB', { convert: true }); -
Handle failures. A failure rejects with an error whose
codesays why:server-off,book-missing,format-missingand others.
If the plugin is reloaded
Books & Shelves fires books-and-shelves:ready with the API each time it loads. onBooksReady runs your callback now and on every reload.